noDefaults.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _iterateJsdoc = _interopRequireDefault(require("../iterateJsdoc.js"));
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  8. var _default = exports.default = (0, _iterateJsdoc.default)(({
  9. context,
  10. utils
  11. }) => {
  12. const {
  13. noOptionalParamNames
  14. } = context.options[0] || {};
  15. const paramTags = utils.getPresentTags(['param', 'arg', 'argument']);
  16. for (const tag of paramTags) {
  17. if (noOptionalParamNames && tag.optional) {
  18. utils.reportJSDoc(`Optional param names are not permitted on @${tag.tag}.`, tag, () => {
  19. utils.changeTag(tag, {
  20. name: tag.name.replace(/([^=]*)(=.+)?/u, '$1')
  21. });
  22. });
  23. } else if (tag.default) {
  24. utils.reportJSDoc(`Defaults are not permitted on @${tag.tag}.`, tag, () => {
  25. utils.changeTag(tag, {
  26. name: tag.name.replace(/([^=]*)(=.+)?/u, '[$1]')
  27. });
  28. });
  29. }
  30. }
  31. const defaultTags = utils.getPresentTags(['default', 'defaultvalue']);
  32. for (const tag of defaultTags) {
  33. if (tag.description.trim()) {
  34. utils.reportJSDoc(`Default values are not permitted on @${tag.tag}.`, tag, () => {
  35. utils.changeTag(tag, {
  36. description: '',
  37. postTag: ''
  38. });
  39. });
  40. }
  41. }
  42. }, {
  43. contextDefaults: true,
  44. meta: {
  45. docs: {
  46. description: 'This rule reports defaults being used on the relevant portion of `@param` or `@default`.',
  47. url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/no-defaults.md#repos-sticky-header'
  48. },
  49. fixable: 'code',
  50. schema: [{
  51. additionalProperties: false,
  52. properties: {
  53. contexts: {
  54. items: {
  55. anyOf: [{
  56. type: 'string'
  57. }, {
  58. additionalProperties: false,
  59. properties: {
  60. comment: {
  61. type: 'string'
  62. },
  63. context: {
  64. type: 'string'
  65. }
  66. },
  67. type: 'object'
  68. }]
  69. },
  70. type: 'array'
  71. },
  72. noOptionalParamNames: {
  73. type: 'boolean'
  74. }
  75. },
  76. type: 'object'
  77. }],
  78. type: 'suggestion'
  79. }
  80. });
  81. module.exports = exports.default;
  82. //# sourceMappingURL=noDefaults.js.map