123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378 |
- "use strict";
-
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
-
- var _jsdoccomment = require("@es-joy/jsdoccomment");
-
- var _lodash = _interopRequireDefault(require("lodash"));
-
- var _exportParser = _interopRequireDefault(require("../exportParser"));
-
- var _iterateJsdoc = require("../iterateJsdoc");
-
- var _jsdocUtils = _interopRequireDefault(require("../jsdocUtils"));
-
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
-
- const OPTIONS_SCHEMA = {
- additionalProperties: false,
- properties: {
- checkConstructors: {
- default: true,
- type: 'boolean'
- },
- checkGetters: {
- anyOf: [{
- type: 'boolean'
- }, {
- enum: ['no-setter'],
- type: 'string'
- }],
- default: true
- },
- checkSetters: {
- anyOf: [{
- type: 'boolean'
- }, {
- enum: ['no-getter'],
- type: 'string'
- }],
- default: true
- },
- contexts: {
- items: {
- anyOf: [{
- type: 'string'
- }, {
- additionalProperties: false,
- properties: {
- context: {
- type: 'string'
- },
- inlineCommentBlock: {
- type: 'boolean'
- }
- },
- type: 'object'
- }]
- },
- type: 'array'
- },
- enableFixer: {
- default: true,
- type: 'boolean'
- },
- exemptEmptyConstructors: {
- default: false,
- type: 'boolean'
- },
- exemptEmptyFunctions: {
- default: false,
- type: 'boolean'
- },
- fixerMessage: {
- default: '',
- type: 'string'
- },
- publicOnly: {
- oneOf: [{
- default: false,
- type: 'boolean'
- }, {
- additionalProperties: false,
- default: {},
- properties: {
- ancestorsOnly: {
- type: 'boolean'
- },
- cjs: {
- type: 'boolean'
- },
- esm: {
- type: 'boolean'
- },
- window: {
- type: 'boolean'
- }
- },
- type: 'object'
- }]
- },
- require: {
- additionalProperties: false,
- default: {},
- properties: {
- ArrowFunctionExpression: {
- default: false,
- type: 'boolean'
- },
- ClassDeclaration: {
- default: false,
- type: 'boolean'
- },
- ClassExpression: {
- default: false,
- type: 'boolean'
- },
- FunctionDeclaration: {
- default: true,
- type: 'boolean'
- },
- FunctionExpression: {
- default: false,
- type: 'boolean'
- },
- MethodDefinition: {
- default: false,
- type: 'boolean'
- }
- },
- type: 'object'
- }
- },
- type: 'object'
- };
-
- const getOption = (context, baseObject, option, key) => {
- if (!_lodash.default.has(context, `options[0][${option}][${key}]`)) {
- return baseObject.properties[key].default;
- }
-
- return context.options[0][option][key];
- };
-
- const getOptions = context => {
- const {
- publicOnly,
- contexts = [],
- exemptEmptyConstructors = true,
- exemptEmptyFunctions = false,
- enableFixer = true,
- fixerMessage = ''
- } = context.options[0] || {};
- return {
- contexts,
- enableFixer,
- exemptEmptyConstructors,
- exemptEmptyFunctions,
- fixerMessage,
- publicOnly: (baseObj => {
- if (!publicOnly) {
- return false;
- }
-
- const properties = {};
- Object.keys(baseObj.properties).forEach(prop => {
- const opt = getOption(context, baseObj, 'publicOnly', prop);
- properties[prop] = opt;
- });
- return properties;
- })(OPTIONS_SCHEMA.properties.publicOnly.oneOf[1]),
- require: (baseObj => {
- const properties = {};
- Object.keys(baseObj.properties).forEach(prop => {
- const opt = getOption(context, baseObj, 'require', prop);
- properties[prop] = opt;
- });
- return properties;
- })(OPTIONS_SCHEMA.properties.require)
- };
- };
-
- var _default = {
- create(context) {
- const sourceCode = context.getSourceCode();
- const settings = (0, _iterateJsdoc.getSettings)(context);
-
- if (!settings) {
- return {};
- }
-
- const {
- require: requireOption,
- contexts,
- publicOnly,
- exemptEmptyFunctions,
- exemptEmptyConstructors,
- enableFixer,
- fixerMessage
- } = getOptions(context);
-
- const checkJsDoc = (info, handler, node) => {
- const jsDocNode = (0, _jsdoccomment.getJSDocComment)(sourceCode, node, settings);
-
- if (jsDocNode) {
- return;
- } // For those who have options configured against ANY constructors (or
- // setters or getters) being reported
-
-
- if (_jsdocUtils.default.exemptSpeciaMethods({
- tags: []
- }, node, context, [OPTIONS_SCHEMA])) {
- return;
- }
-
- if ( // Avoid reporting param-less, return-less functions (when
- // `exemptEmptyFunctions` option is set)
- exemptEmptyFunctions && info.isFunctionContext || // Avoid reporting param-less, return-less constructor methods (when
- // `exemptEmptyConstructors` option is set)
- exemptEmptyConstructors && _jsdocUtils.default.isConstructor(node)) {
- const functionParameterNames = _jsdocUtils.default.getFunctionParameterNames(node);
-
- if (!functionParameterNames.length && !_jsdocUtils.default.hasReturnValue(node)) {
- return;
- }
- }
-
- const fix = fixer => {
- // Default to one line break if the `minLines`/`maxLines` settings allow
- const lines = settings.minLines === 0 && settings.maxLines >= 1 ? 1 : settings.minLines;
- let baseNode = (0, _jsdoccomment.getReducedASTNode)(node, sourceCode);
- const decorator = (0, _jsdoccomment.getDecorator)(baseNode);
-
- if (decorator) {
- baseNode = decorator;
- }
-
- const indent = _jsdocUtils.default.getIndent({
- text: sourceCode.getText(baseNode, baseNode.loc.start.column)
- });
-
- const {
- inlineCommentBlock
- } = contexts.find(({
- context: ctxt
- }) => {
- return ctxt === node.type;
- }) || {};
- const insertion = (inlineCommentBlock ? `/** ${fixerMessage}` : `/**\n${indent}*${fixerMessage}\n${indent}`) + `*/${'\n'.repeat(lines)}${indent.slice(0, -1)}`;
- return fixer.insertTextBefore(baseNode, insertion);
- };
-
- const report = () => {
- const loc = {
- end: node.loc.start + 1,
- start: node.loc.start
- };
- context.report({
- fix: enableFixer ? fix : null,
- loc,
- messageId: 'missingJsDoc',
- node
- });
- };
-
- if (publicOnly) {
- var _publicOnly$ancestors, _publicOnly$esm, _publicOnly$cjs, _publicOnly$window;
-
- const opt = {
- ancestorsOnly: Boolean((_publicOnly$ancestors = publicOnly === null || publicOnly === void 0 ? void 0 : publicOnly.ancestorsOnly) !== null && _publicOnly$ancestors !== void 0 ? _publicOnly$ancestors : false),
- esm: Boolean((_publicOnly$esm = publicOnly === null || publicOnly === void 0 ? void 0 : publicOnly.esm) !== null && _publicOnly$esm !== void 0 ? _publicOnly$esm : true),
- initModuleExports: Boolean((_publicOnly$cjs = publicOnly === null || publicOnly === void 0 ? void 0 : publicOnly.cjs) !== null && _publicOnly$cjs !== void 0 ? _publicOnly$cjs : true),
- initWindow: Boolean((_publicOnly$window = publicOnly === null || publicOnly === void 0 ? void 0 : publicOnly.window) !== null && _publicOnly$window !== void 0 ? _publicOnly$window : false)
- };
-
- const exported = _exportParser.default.isUncommentedExport(node, sourceCode, opt, settings);
-
- if (exported) {
- report();
- }
- } else {
- report();
- }
- };
-
- const hasOption = prop => {
- return requireOption[prop] || contexts.some(ctxt => {
- return typeof ctxt === 'object' ? ctxt.context === prop : ctxt === prop;
- });
- };
-
- return { ..._jsdocUtils.default.getContextObject(_jsdocUtils.default.enforcedContexts(context, []), checkJsDoc),
-
- ArrowFunctionExpression(node) {
- if (!hasOption('ArrowFunctionExpression')) {
- return;
- }
-
- if (['VariableDeclarator', 'AssignmentExpression', 'ExportDefaultDeclaration'].includes(node.parent.type) || ['Property', 'ObjectProperty', 'ClassProperty'].includes(node.parent.type) && node === node.parent.value) {
- checkJsDoc({
- isFunctionContext: true
- }, null, node);
- }
- },
-
- ClassDeclaration(node) {
- if (!hasOption('ClassDeclaration')) {
- return;
- }
-
- checkJsDoc({
- isFunctionContext: false
- }, null, node);
- },
-
- ClassExpression(node) {
- if (!hasOption('ClassExpression')) {
- return;
- }
-
- checkJsDoc({
- isFunctionContext: false
- }, null, node);
- },
-
- FunctionDeclaration(node) {
- if (!hasOption('FunctionDeclaration')) {
- return;
- }
-
- checkJsDoc({
- isFunctionContext: true
- }, null, node);
- },
-
- FunctionExpression(node) {
- if (hasOption('MethodDefinition') && node.parent.type === 'MethodDefinition') {
- checkJsDoc({
- isFunctionContext: true
- }, null, node);
- return;
- }
-
- if (!hasOption('FunctionExpression')) {
- return;
- }
-
- if (['VariableDeclarator', 'AssignmentExpression', 'ExportDefaultDeclaration'].includes(node.parent.type) || ['Property', 'ObjectProperty', 'ClassProperty'].includes(node.parent.type) && node === node.parent.value) {
- checkJsDoc({
- isFunctionContext: true
- }, null, node);
- }
- }
-
- };
- },
-
- meta: {
- docs: {
- category: 'Stylistic Issues',
- description: 'Require JSDoc comments',
- recommended: 'true',
- url: 'https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-require-jsdoc'
- },
- fixable: 'code',
- messages: {
- missingJsDoc: 'Missing JSDoc comment.'
- },
- schema: [OPTIONS_SCHEMA],
- type: 'suggestion'
- }
- };
- exports.default = _default;
- module.exports = exports.default;
- //# sourceMappingURL=requireJsdoc.js.map
|