123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- "use strict";
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = exports.parseComment = void 0;
- var _lodash = _interopRequireDefault(require("lodash"));
- var _commentParser = _interopRequireDefault(require("comment-parser"));
- var _jsdocUtils = _interopRequireDefault(require("./jsdocUtils"));
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- var parseComment = function parseComment(commentNode, indent) {
- // Preserve JSDoc block start/end indentation.
- return (0, _commentParser.default)(indent + '/*' + commentNode.value + indent + '*/', {
- // @see https://github.com/yavorskiy/comment-parser/issues/21
- parsers: [_commentParser.default.PARSERS.parse_tag, _commentParser.default.PARSERS.parse_type, function (str, data) {
- if (_lodash.default.includes(['return', 'returns', 'throws', 'exception'], data.tag)) {
- return null;
- }
- return _commentParser.default.PARSERS.parse_name(str, data);
- }, _commentParser.default.PARSERS.parse_description]
- })[0] || {};
- };
- exports.parseComment = parseComment;
- var curryUtils = function curryUtils(functionNode, jsdoc, tagNamePreference, exampleCodeRegex, rejectExampleCodeRegex, additionalTagNames, baseConfig, configFile, captionRequired, matchingFileName, eslintrcForExamples, allowInlineConfig, allowEmptyNamepaths, reportUnusedDisableDirectives, noDefaultExampleRules, allowOverrideWithoutParam, allowImplementsWithoutParam, allowAugmentsExtendsWithoutParam, checkSeesForNamepaths, ancestors, sourceCode) {
- var utils = {};
- utils.getFunctionParameterNames = function () {
- return _jsdocUtils.default.getFunctionParameterNames(functionNode);
- };
- utils.getFunctionSourceCode = function () {
- return sourceCode.getText(functionNode);
- };
- utils.isConstructor = function () {
- return functionNode.parent && functionNode.parent.kind === 'constructor';
- };
- utils.getJsdocParameterNamesDeep = function () {
- return _jsdocUtils.default.getJsdocParameterNamesDeep(jsdoc, utils.getPreferredTagName('param'));
- };
- utils.getJsdocParameterNames = function () {
- return _jsdocUtils.default.getJsdocParameterNames(jsdoc, utils.getPreferredTagName('param'));
- };
- utils.getPreferredTagName = function (name) {
- return _jsdocUtils.default.getPreferredTagName(name, tagNamePreference);
- };
- utils.getExampleCodeRegex = function () {
- return exampleCodeRegex;
- };
- utils.getRejectExampleCodeRegex = function () {
- return rejectExampleCodeRegex;
- };
- utils.getMatchingFileName = function () {
- return matchingFileName;
- };
- utils.isValidTag = function (name) {
- return _jsdocUtils.default.isValidTag(name, additionalTagNames);
- };
- utils.hasATag = function (name) {
- return _jsdocUtils.default.hasATag(jsdoc, name);
- };
- utils.hasTag = function (name) {
- return _jsdocUtils.default.hasTag(jsdoc, name);
- };
- utils.useEslintrcForExamples = function () {
- return eslintrcForExamples;
- };
- utils.allowInlineConfig = function () {
- return allowInlineConfig;
- };
- utils.reportUnusedDisableDirectives = function () {
- return reportUnusedDisableDirectives;
- };
- utils.hasNoDefaultExampleRules = function () {
- return noDefaultExampleRules;
- };
- utils.getBaseConfig = function () {
- return baseConfig;
- };
- utils.getConfigFile = function () {
- return configFile;
- };
- utils.isCaptionRequired = function () {
- return captionRequired;
- };
- utils.isOverrideAllowedWithoutParam = function () {
- return allowOverrideWithoutParam;
- };
- utils.isImplementsAllowedWithoutParam = function () {
- return allowImplementsWithoutParam;
- };
- utils.isAugmentsExtendsAllowedWithoutParam = function () {
- return allowAugmentsExtendsWithoutParam;
- };
- utils.isNamepathType = function (tagName) {
- return _jsdocUtils.default.isNamepathType(tagName, checkSeesForNamepaths);
- };
- utils.passesEmptyNamepathCheck = function (tag) {
- return !tag.name && allowEmptyNamepaths && _lodash.default.includes([// These may serve some minor purpose when empty
- 'callback', 'event', 'listens', 'fires', 'emits'], tag.tag);
- };
- utils.getClassJsdocNode = function () {
- var greatGrandParent = ancestors.slice(-3)[0];
- var greatGrandParentValue = greatGrandParent && sourceCode.getFirstToken(greatGrandParent).value;
- if (greatGrandParentValue === 'class') {
- var classJsdocNode = sourceCode.getJSDocComment(greatGrandParent);
- return classJsdocNode;
- }
- return false;
- };
- utils.classHasTag = function (tagName) {
- var classJsdocNode = utils.getClassJsdocNode();
- if (classJsdocNode) {
- var indent = _lodash.default.repeat(' ', classJsdocNode.loc.start.column);
- var classJsdoc = parseComment(classJsdocNode, indent);
- if (_jsdocUtils.default.hasTag(classJsdoc, tagName)) {
- return true;
- }
- }
- return false;
- };
- return utils;
- };
- var _default = function _default(iterator) {
- return function (context) {
- var sourceCode = context.getSourceCode();
- var tagNamePreference = _lodash.default.get(context, 'settings.jsdoc.tagNamePreference') || {};
- var exampleCodeRegex = _lodash.default.get(context, 'settings.jsdoc.exampleCodeRegex') || null;
- var rejectExampleCodeRegex = _lodash.default.get(context, 'settings.jsdoc.rejectExampleCodeRegex') || null;
- var matchingFileName = _lodash.default.get(context, 'settings.jsdoc.matchingFileName') || null;
- var additionalTagNames = _lodash.default.get(context, 'settings.jsdoc.additionalTagNames') || {};
- var baseConfig = _lodash.default.get(context, 'settings.jsdoc.baseConfig') || {};
- var configFile = _lodash.default.get(context, 'settings.jsdoc.configFile');
- var eslintrcForExamples = _lodash.default.get(context, 'settings.jsdoc.eslintrcForExamples') !== false;
- var allowInlineConfig = _lodash.default.get(context, 'settings.jsdoc.allowInlineConfig') !== false;
- var allowEmptyNamepaths = _lodash.default.get(context, 'settings.jsdoc.allowEmptyNamepaths') !== false;
- var reportUnusedDisableDirectives = _lodash.default.get(context, 'settings.jsdoc.reportUnusedDisableDirectives') !== false;
- var captionRequired = Boolean(_lodash.default.get(context, 'settings.jsdoc.captionRequired'));
- var noDefaultExampleRules = Boolean(_lodash.default.get(context, 'settings.jsdoc.noDefaultExampleRules'));
- var allowOverrideWithoutParam = Boolean(_lodash.default.get(context, 'settings.jsdoc.allowOverrideWithoutParam'));
- var allowImplementsWithoutParam = Boolean(_lodash.default.get(context, 'settings.jsdoc.allowImplementsWithoutParam'));
- var allowAugmentsExtendsWithoutParam = Boolean(_lodash.default.get(context, 'settings.jsdoc.allowAugmentsExtendsWithoutParam'));
- var checkSeesForNamepaths = Boolean(_lodash.default.get(context, 'settings.jsdoc.checkSeesForNamepaths'));
- var checkJsdoc = function checkJsdoc(functionNode) {
- var jsdocNode = sourceCode.getJSDocComment(functionNode);
- if (!jsdocNode) {
- return;
- }
- var ancestors = context.getAncestors();
- var indent = _lodash.default.repeat(' ', jsdocNode.loc.start.column);
- var jsdoc = parseComment(jsdocNode, indent);
- var report = function report(message) {
- var fixer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
- var jsdocLoc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
- var loc;
- if (jsdocLoc) {
- var lineNumber = jsdocNode.loc.start.line + jsdocLoc.line;
- loc = {
- end: {
- line: lineNumber
- },
- start: {
- line: lineNumber
- }
- };
- if (jsdocLoc.column) {
- var colNumber = jsdocNode.loc.start.column + jsdocLoc.column;
- loc.end.column = colNumber;
- loc.start.column = colNumber;
- }
- }
- if (fixer === null) {
- context.report({
- loc,
- message,
- node: jsdocNode
- });
- } else {
- context.report({
- fix: fixer,
- loc,
- message,
- node: jsdocNode
- });
- }
- };
- var utils = curryUtils(functionNode, jsdoc, tagNamePreference, exampleCodeRegex, rejectExampleCodeRegex, additionalTagNames, baseConfig, configFile, captionRequired, matchingFileName, eslintrcForExamples, allowInlineConfig, allowEmptyNamepaths, reportUnusedDisableDirectives, noDefaultExampleRules, allowOverrideWithoutParam, allowImplementsWithoutParam, allowAugmentsExtendsWithoutParam, checkSeesForNamepaths, ancestors, sourceCode);
- iterator({
- context,
- functionNode,
- indent,
- jsdoc,
- jsdocNode,
- report,
- sourceCode,
- utils
- });
- };
- return {
- ArrowFunctionExpression: checkJsdoc,
- FunctionDeclaration: checkJsdoc,
- FunctionExpression: checkJsdoc
- };
- };
- };
- exports.default = _default;
- //# sourceMappingURL=iterateJsdoc.js.map
|