eslint-plugin-jsdoc 51.0.6 → 51.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/rules/checkTemplateNames.cjs +27 -16
- package/dist/rules/checkTemplateNames.cjs.map +1 -1
- package/dist/rules/linesBeforeBlock.cjs +7 -0
- package/dist/rules/linesBeforeBlock.cjs.map +1 -1
- package/package.json +1 -1
- package/src/rules/checkTemplateNames.js +33 -15
- package/src/rules/linesBeforeBlock.js +8 -0
|
@@ -4,13 +4,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var _iterateJsdoc =
|
|
7
|
+
var _iterateJsdoc = _interopRequireWildcard(require("../iterateJsdoc.cjs"));
|
|
8
|
+
var _jsdocUtils = require("../jsdocUtils.cjs");
|
|
8
9
|
var _jsdoccomment = require("@es-joy/jsdoccomment");
|
|
9
|
-
function
|
|
10
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
10
11
|
var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
12
|
+
jsdoc,
|
|
11
13
|
node,
|
|
12
14
|
report,
|
|
13
15
|
settings,
|
|
16
|
+
sourceCode,
|
|
14
17
|
utils
|
|
15
18
|
}) => {
|
|
16
19
|
const {
|
|
@@ -38,18 +41,18 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
|
38
41
|
}
|
|
39
42
|
});
|
|
40
43
|
};
|
|
41
|
-
const checkParamsAndReturnsTags = () => {
|
|
44
|
+
const checkParamsAndReturnsTags = (jsdc = jsdoc) => {
|
|
42
45
|
const paramName = /** @type {string} */utils.getPreferredTagName({
|
|
43
46
|
tagName: 'param'
|
|
44
47
|
});
|
|
45
|
-
const paramTags =
|
|
48
|
+
const paramTags = (0, _jsdocUtils.getTags)(jsdc, paramName);
|
|
46
49
|
for (const paramTag of paramTags) {
|
|
47
50
|
checkForUsedTypes(paramTag.type);
|
|
48
51
|
}
|
|
49
52
|
const returnsName = /** @type {string} */utils.getPreferredTagName({
|
|
50
53
|
tagName: 'returns'
|
|
51
54
|
});
|
|
52
|
-
const returnsTags =
|
|
55
|
+
const returnsTags = (0, _jsdocUtils.getTags)(jsdc, returnsName);
|
|
53
56
|
for (const returnsTag of returnsTags) {
|
|
54
57
|
checkForUsedTypes(returnsTag.type);
|
|
55
58
|
}
|
|
@@ -91,6 +94,24 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
|
91
94
|
}
|
|
92
95
|
if (checkParamsAndReturns) {
|
|
93
96
|
checkParamsAndReturnsTags();
|
|
97
|
+
} else if (aliasDeclaration.type === 'ClassDeclaration') {
|
|
98
|
+
/* c8 ignore next -- TS */
|
|
99
|
+
for (const nde of aliasDeclaration?.body?.body ?? []) {
|
|
100
|
+
// @ts-expect-error Should be ok
|
|
101
|
+
const commentNode = (0, _jsdoccomment.getJSDocComment)(sourceCode, nde, settings);
|
|
102
|
+
if (!commentNode) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
const innerJsdoc = (0, _iterateJsdoc.parseComment)(commentNode, '');
|
|
106
|
+
checkParamsAndReturnsTags(innerJsdoc);
|
|
107
|
+
const typeName = /** @type {string} */utils.getPreferredTagName({
|
|
108
|
+
tagName: 'type'
|
|
109
|
+
});
|
|
110
|
+
const typeTags = (0, _jsdocUtils.getTags)(innerJsdoc, typeName);
|
|
111
|
+
for (const typeTag of typeTags) {
|
|
112
|
+
checkForUsedTypes(typeTag.type);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
94
115
|
}
|
|
95
116
|
checkTemplateTags();
|
|
96
117
|
};
|
|
@@ -145,17 +166,7 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
|
145
166
|
for (const propertyTag of propertyTags) {
|
|
146
167
|
checkForUsedTypes(propertyTag.type);
|
|
147
168
|
}
|
|
148
|
-
|
|
149
|
-
const {
|
|
150
|
-
name
|
|
151
|
-
} = tag;
|
|
152
|
-
const names = name.split(/,\s*/u);
|
|
153
|
-
for (const nme of names) {
|
|
154
|
-
if (!usedNames.has(nme)) {
|
|
155
|
-
report(`@template ${nme} not in use`, null, tag);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
169
|
+
checkTemplateTags();
|
|
159
170
|
}, {
|
|
160
171
|
iterateAllJsdocs: true,
|
|
161
172
|
meta: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkTemplateNames.cjs","names":["_iterateJsdoc","_interopRequireDefault","require","_jsdoccomment","e","__esModule","default","_default","exports","iterateJsdoc","node","report","settings","utils","mode","templateTags","getTags","usedNames","Set","checkForUsedTypes","potentialType","parsedType","tryParseType","parseType","traverse","nde","type","value","add","checkParamsAndReturnsTags","paramName","getPreferredTagName","tagName","paramTags","paramTag","returnsName","returnsTags","returnsTag","checkTemplateTags","tag","name","names","split","nme","has","checkParameters","aliasDeclaration","checkParamsAndReturns","params","typeParameters","handleTypeAliases","declaration","callbackTags","functionTags","length","typedefTags","potentialTypedefType","propertyName","propertyTags","propertyTag","iterateAllJsdocs","meta","docs","description","url","schema","module"],"sources":["../../src/rules/checkTemplateNames.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc.js';\nimport {\n parse as parseType,\n traverse,\n tryParse as tryParseType,\n} from '@es-joy/jsdoccomment';\n\nexport default iterateJsdoc(({\n node,\n report,\n settings,\n utils,\n}) => {\n const {\n mode,\n } = settings;\n\n const templateTags = utils.getTags('template');\n\n const usedNames = new Set();\n /**\n * @param {string} potentialType\n */\n const checkForUsedTypes = (potentialType) => {\n let parsedType;\n try {\n parsedType = mode === 'permissive' ?\n tryParseType(/** @type {string} */ (potentialType)) :\n parseType(/** @type {string} */ (potentialType), mode);\n } catch {\n return;\n }\n\n traverse(parsedType, (nde) => {\n const {\n type,\n value,\n } = /** @type {import('jsdoc-type-pratt-parser').NameResult} */ (nde);\n if (type === 'JsdocTypeName') {\n usedNames.add(value);\n }\n });\n };\n\n const checkParamsAndReturnsTags = () => {\n const paramName = /** @type {string} */ (utils.getPreferredTagName({\n tagName: 'param',\n }));\n const paramTags = utils.getTags(paramName);\n for (const paramTag of paramTags) {\n checkForUsedTypes(paramTag.type);\n }\n\n const returnsName = /** @type {string} */ (utils.getPreferredTagName({\n tagName: 'returns',\n }));\n const returnsTags = utils.getTags(returnsName);\n for (const returnsTag of returnsTags) {\n checkForUsedTypes(returnsTag.type);\n }\n };\n\n const checkTemplateTags = () => {\n for (const tag of templateTags) {\n const {\n name,\n } = tag;\n const names = name.split(/,\\s*/u);\n for (const nme of names) {\n if (!usedNames.has(nme)) {\n report(`@template ${nme} not in use`, null, tag);\n }\n }\n }\n };\n\n /**\n * @param {import('@typescript-eslint/types').TSESTree.FunctionDeclaration|\n * import('@typescript-eslint/types').TSESTree.ClassDeclaration|\n * import('@typescript-eslint/types').TSESTree.TSInterfaceDeclaration|\n * import('@typescript-eslint/types').TSESTree.TSTypeAliasDeclaration} aliasDeclaration\n * @param {boolean} [checkParamsAndReturns]\n */\n const checkParameters = (aliasDeclaration, checkParamsAndReturns) => {\n /* c8 ignore next -- Guard */\n const {\n params,\n } = aliasDeclaration.typeParameters ?? {\n params: [],\n };\n for (const {\n name: {\n name,\n },\n } of params) {\n usedNames.add(name);\n }\n\n if (checkParamsAndReturns) {\n checkParamsAndReturnsTags();\n }\n\n checkTemplateTags();\n };\n\n const handleTypeAliases = () => {\n const nde = /** @type {import('@typescript-eslint/types').TSESTree.Node} */ (\n node\n );\n if (!nde) {\n return;\n }\n\n switch (nde.type) {\n case 'ClassDeclaration':\n case 'TSInterfaceDeclaration':\n case 'TSTypeAliasDeclaration':\n checkParameters(nde);\n break;\n case 'ExportDefaultDeclaration':\n case 'ExportNamedDeclaration':\n switch (nde.declaration?.type) {\n case 'ClassDeclaration':\n case 'TSInterfaceDeclaration':\n case 'TSTypeAliasDeclaration':\n checkParameters(nde.declaration);\n break;\n case 'FunctionDeclaration':\n checkParameters(nde.declaration, true);\n break;\n }\n\n break;\n case 'FunctionDeclaration':\n checkParameters(nde, true);\n break;\n }\n };\n\n const callbackTags = utils.getTags('callback');\n const functionTags = utils.getTags('function');\n if (callbackTags.length || functionTags.length) {\n checkParamsAndReturnsTags();\n checkTemplateTags();\n return;\n }\n\n const typedefTags = utils.getTags('typedef');\n if (!typedefTags.length || typedefTags.length >= 2) {\n handleTypeAliases();\n return;\n }\n\n const potentialTypedefType = typedefTags[0].type;\n checkForUsedTypes(potentialTypedefType);\n\n const propertyName = /** @type {string} */ (utils.getPreferredTagName({\n tagName: 'property',\n }));\n const propertyTags = utils.getTags(propertyName);\n for (const propertyTag of propertyTags) {\n checkForUsedTypes(propertyTag.type);\n }\n\n for (const tag of templateTags) {\n const {\n name,\n } = tag;\n const names = name.split(/,\\s*/u);\n for (const nme of names) {\n if (!usedNames.has(nme)) {\n report(`@template ${nme} not in use`, null, tag);\n }\n }\n }\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Checks that any `@template` names are actually used in the connected `@typedef` or type alias.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/check-template-names.md#repos-sticky-header',\n },\n schema: [],\n type: 'suggestion',\n },\n});\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AAI8B,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA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ACjC,IAAI,CAAC;EACrC;EAEA,KAAK,MAAMa,GAAG,IAAIxB,YAAY,EAAE;IAC9B,MAAM;MACJyB;IACF,CAAC,GAAGD,GAAG;IACP,MAAME,KAAK,GAAGD,IAAI,CAACE,KAAK,CAAC,OAAO,CAAC;IACjC,KAAK,MAAMC,GAAG,IAAIF,KAAK,EAAE;MACvB,IAAI,CAACxB,SAAS,CAAC2B,GAAG,CAACD,GAAG,CAAC,EAAE;QACvBhC,MAAM,CAAC,aAAagC,GAAG,aAAa,EAAE,IAAI,EAAEJ,GAAG,CAAC;MAClD;IACF;EACF;AACF,CAAC,EAAE;EACDqB,gBAAgB,EAAE,IAAI;EACtBC,IAAI,EAAE;IACJC,IAAI,EAAE;MACJC,WAAW,EAAE,gGAAgG;MAC7GC,GAAG,EAAE;IACP,CAAC;IACDC,MAAM,EAAE,EAAE;IACVvC,IAAI,EAAE;EACR;AACF,CAAC,CAAC;AAAAwC,MAAA,CAAA1D,OAAA,GAAAA,OAAA,CAAAF,OAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"checkTemplateNames.cjs","names":["_iterateJsdoc","_interopRequireWildcard","require","_jsdocUtils","_jsdoccomment","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_default","exports","iterateJsdoc","jsdoc","node","report","settings","sourceCode","utils","mode","templateTags","getTags","usedNames","Set","checkForUsedTypes","potentialType","parsedType","tryParseType","parseType","traverse","nde","type","value","add","checkParamsAndReturnsTags","jsdc","paramName","getPreferredTagName","tagName","paramTags","paramTag","returnsName","returnsTags","returnsTag","checkTemplateTags","tag","name","names","split","nme","checkParameters","aliasDeclaration","checkParamsAndReturns","params","typeParameters","body","commentNode","getJSDocComment","innerJsdoc","parseComment","typeName","typeTags","typeTag","handleTypeAliases","declaration","callbackTags","functionTags","length","typedefTags","potentialTypedefType","propertyName","propertyTags","propertyTag","iterateAllJsdocs","meta","docs","description","url","schema","module"],"sources":["../../src/rules/checkTemplateNames.js"],"sourcesContent":["import iterateJsdoc, {\n parseComment,\n} from '../iterateJsdoc.js';\nimport {\n getTags,\n} from '../jsdocUtils.js';\nimport {\n getJSDocComment,\n parse as parseType,\n traverse,\n tryParse as tryParseType,\n} from '@es-joy/jsdoccomment';\n\nexport default iterateJsdoc(({\n jsdoc,\n node,\n report,\n settings,\n sourceCode,\n utils,\n}) => {\n const {\n mode,\n } = settings;\n\n const templateTags = utils.getTags('template');\n\n const usedNames = new Set();\n /**\n * @param {string} potentialType\n */\n const checkForUsedTypes = (potentialType) => {\n let parsedType;\n try {\n parsedType = mode === 'permissive' ?\n tryParseType(/** @type {string} */ (potentialType)) :\n parseType(/** @type {string} */ (potentialType), mode);\n } catch {\n return;\n }\n\n traverse(parsedType, (nde) => {\n const {\n type,\n value,\n } = /** @type {import('jsdoc-type-pratt-parser').NameResult} */ (nde);\n if (type === 'JsdocTypeName') {\n usedNames.add(value);\n }\n });\n };\n\n const checkParamsAndReturnsTags = (jsdc = jsdoc) => {\n const paramName = /** @type {string} */ (utils.getPreferredTagName({\n tagName: 'param',\n }));\n const paramTags = getTags(jsdc, paramName);\n for (const paramTag of paramTags) {\n checkForUsedTypes(paramTag.type);\n }\n\n const returnsName = /** @type {string} */ (utils.getPreferredTagName({\n tagName: 'returns',\n }));\n const returnsTags = getTags(jsdc, returnsName);\n for (const returnsTag of returnsTags) {\n checkForUsedTypes(returnsTag.type);\n }\n };\n\n const checkTemplateTags = () => {\n for (const tag of templateTags) {\n const {\n name,\n } = tag;\n const names = name.split(/,\\s*/u);\n for (const nme of names) {\n if (!usedNames.has(nme)) {\n report(`@template ${nme} not in use`, null, tag);\n }\n }\n }\n };\n\n /**\n * @param {import('@typescript-eslint/types').TSESTree.FunctionDeclaration|\n * import('@typescript-eslint/types').TSESTree.ClassDeclaration|\n * import('@typescript-eslint/types').TSESTree.TSInterfaceDeclaration|\n * import('@typescript-eslint/types').TSESTree.TSTypeAliasDeclaration} aliasDeclaration\n * @param {boolean} [checkParamsAndReturns]\n */\n const checkParameters = (aliasDeclaration, checkParamsAndReturns) => {\n /* c8 ignore next -- Guard */\n const {\n params,\n } = aliasDeclaration.typeParameters ?? {\n params: [],\n };\n for (const {\n name: {\n name,\n },\n } of params) {\n usedNames.add(name);\n }\n\n if (checkParamsAndReturns) {\n checkParamsAndReturnsTags();\n } else if (aliasDeclaration.type === 'ClassDeclaration') {\n /* c8 ignore next -- TS */\n for (const nde of aliasDeclaration?.body?.body ?? []) {\n // @ts-expect-error Should be ok\n const commentNode = getJSDocComment(sourceCode, nde, settings);\n if (!commentNode) {\n continue;\n }\n\n const innerJsdoc = parseComment(commentNode, '');\n checkParamsAndReturnsTags(innerJsdoc);\n\n const typeName = /** @type {string} */ (utils.getPreferredTagName({\n tagName: 'type',\n }));\n const typeTags = getTags(innerJsdoc, typeName);\n for (const typeTag of typeTags) {\n checkForUsedTypes(typeTag.type);\n }\n }\n }\n\n checkTemplateTags();\n };\n\n const handleTypeAliases = () => {\n const nde = /** @type {import('@typescript-eslint/types').TSESTree.Node} */ (\n node\n );\n if (!nde) {\n return;\n }\n\n switch (nde.type) {\n case 'ClassDeclaration':\n case 'TSInterfaceDeclaration':\n case 'TSTypeAliasDeclaration':\n checkParameters(nde);\n break;\n case 'ExportDefaultDeclaration':\n case 'ExportNamedDeclaration':\n switch (nde.declaration?.type) {\n case 'ClassDeclaration':\n case 'TSInterfaceDeclaration':\n case 'TSTypeAliasDeclaration':\n checkParameters(nde.declaration);\n break;\n case 'FunctionDeclaration':\n checkParameters(nde.declaration, true);\n break;\n }\n\n break;\n case 'FunctionDeclaration':\n checkParameters(nde, true);\n break;\n }\n };\n\n const callbackTags = utils.getTags('callback');\n const functionTags = utils.getTags('function');\n if (callbackTags.length || functionTags.length) {\n checkParamsAndReturnsTags();\n checkTemplateTags();\n return;\n }\n\n const typedefTags = utils.getTags('typedef');\n if (!typedefTags.length || typedefTags.length >= 2) {\n handleTypeAliases();\n return;\n }\n\n const potentialTypedefType = typedefTags[0].type;\n checkForUsedTypes(potentialTypedefType);\n\n const propertyName = /** @type {string} */ (utils.getPreferredTagName({\n tagName: 'property',\n }));\n const propertyTags = utils.getTags(propertyName);\n for (const propertyTag of propertyTags) {\n checkForUsedTypes(propertyTag.type);\n }\n\n checkTemplateTags();\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Checks that any `@template` names are actually used in the connected `@typedef` or type alias.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/check-template-names.md#repos-sticky-header',\n },\n schema: [],\n type: 'suggestion',\n },\n});\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,uBAAA,CAAAC,OAAA;AAGA,IAAAC,WAAA,GAAAD,OAAA;AAGA,IAAAE,aAAA,GAAAF,OAAA;AAK8B,SAAAD,wBAAAI,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAN,uBAAA,YAAAA,CAAAI,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBA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":[]}
|
|
@@ -23,6 +23,7 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
|
23
23
|
checkBlockStarts,
|
|
24
24
|
excludedTags = ['type'],
|
|
25
25
|
ignoreSameLine = true,
|
|
26
|
+
ignoreSingleLines = true,
|
|
26
27
|
lines = 1
|
|
27
28
|
} = context.options[0] || {};
|
|
28
29
|
if (utils.hasATag(excludedTags)) {
|
|
@@ -42,6 +43,9 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
|
42
43
|
if (sameLine && ignoreSameLine) {
|
|
43
44
|
return;
|
|
44
45
|
}
|
|
46
|
+
if (ignoreSingleLines && jsdocNode.loc?.start.line === jsdocNode.loc?.end.line) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
45
49
|
|
|
46
50
|
/** @type {import('eslint').Rule.ReportFixer} */
|
|
47
51
|
const fix = fixer => {
|
|
@@ -90,6 +94,9 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
|
90
94
|
ignoreSameLine: {
|
|
91
95
|
type: 'boolean'
|
|
92
96
|
},
|
|
97
|
+
ignoreSingleLines: {
|
|
98
|
+
type: 'boolean'
|
|
99
|
+
},
|
|
93
100
|
lines: {
|
|
94
101
|
type: 'integer'
|
|
95
102
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linesBeforeBlock.cjs","names":["_iterateJsdoc","_interopRequireDefault","require","e","__esModule","default","startPunctuators","Set","_default","exports","iterateJsdoc","context","jsdocNode","report","sourceCode","utils","checkBlockStarts","excludedTags","ignoreSameLine","lines","options","hasATag","tokensBefore","getTokensBefore","includeComments","tokenBefore","at","type","has","value","loc","end","line","start","startLine","sameLine","fix","fixer","indent","spaceDiff","column","match","slice","tokenPrior","startColumn","pop","repeat","insertTextAfter","iterateAllJsdocs","meta","docs","description","url","fixable","schema","additionalProperties","properties","items","module"],"sources":["../../src/rules/linesBeforeBlock.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc.js';\n\n/**\n * Punctuators that begin a logical group should not require a line before it skipped. Specifically\n * `[` starts an array, `{` starts an object or block, `(` starts a grouping, and `=` starts a\n * declaration (like a variable or a type alias).\n */\nconst startPunctuators = new Set([\n '(', '=', '[', '{',\n]);\n\nexport default iterateJsdoc(({\n context,\n jsdocNode,\n report,\n sourceCode,\n utils,\n}) => {\n const {\n checkBlockStarts,\n excludedTags = [\n 'type',\n ],\n ignoreSameLine = true,\n lines = 1,\n } = context.options[0] || {};\n\n if (utils.hasATag(excludedTags)) {\n return;\n }\n\n const tokensBefore = sourceCode.getTokensBefore(jsdocNode, {\n includeComments: true,\n });\n const tokenBefore = tokensBefore.at(-1);\n if (\n !tokenBefore || (\n tokenBefore.type === 'Punctuator' &&\n !checkBlockStarts &&\n startPunctuators.has(tokenBefore.value)\n )\n ) {\n return;\n }\n\n if (tokenBefore.loc?.end?.line + lines >=\n /** @type {number} */\n (jsdocNode.loc?.start?.line)\n ) {\n const startLine = jsdocNode.loc?.start?.line;\n const sameLine = tokenBefore.loc?.end?.line === startLine;\n\n if (sameLine && ignoreSameLine) {\n return;\n }\n\n /** @type {import('eslint').Rule.ReportFixer} */\n const fix = (fixer) => {\n let indent = '';\n if (sameLine) {\n const spaceDiff = /** @type {number} */ (jsdocNode.loc?.start?.column) -\n /** @type {number} */ (tokenBefore.loc?.end?.column);\n // @ts-expect-error Should be a comment\n indent = /** @type {import('estree').Comment} */ (\n jsdocNode\n ).value.match(/^\\*\\n([\\t ]*) \\*/u)?.[1]?.slice(spaceDiff);\n if (!indent) {\n /** @type {import('eslint').AST.Token|import('estree').Comment|undefined} */\n let tokenPrior = tokenBefore;\n let startColumn;\n while (tokenPrior && tokenPrior?.loc?.start?.line === startLine) {\n startColumn = tokenPrior.loc?.start?.column;\n tokenPrior = tokensBefore.pop();\n }\n\n indent = ' '.repeat(\n /* c8 ignore next */\n /** @type {number} */ (startColumn ? startColumn - 1 : 0),\n );\n }\n }\n\n return fixer.insertTextAfter(\n /** @type {import('eslint').AST.Token} */\n (tokenBefore),\n '\\n'.repeat(lines) +\n (sameLine ? '\\n' + indent : ''),\n );\n };\n\n report(`Required ${lines} line(s) before JSDoc block`, fix);\n }\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Enforces minimum number of newlines before JSDoc comment blocks',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/lines-before-block.md#repos-sticky-header',\n },\n fixable: 'code',\n schema: [\n {\n additionalProperties: false,\n properties: {\n checkBlockStarts: {\n type: 'boolean',\n },\n excludedTags: {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n ignoreSameLine: {\n type: 'boolean',\n },\n lines: {\n type: 'integer',\n },\n },\n type: 'object',\n },\n ],\n type: 'suggestion',\n },\n});\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA8C,SAAAD,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAE9C;AACA;AACA;AACA;AACA;AACA,MAAMG,gBAAgB,GAAG,IAAIC,GAAG,CAAC,CAC/B,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CACnB,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAJ,OAAA,GAEY,IAAAK,qBAAY,EAAC,CAAC;EAC3BC,OAAO;EACPC,SAAS;EACTC,MAAM;EACNC,UAAU;EACVC;AACF,CAAC,KAAK;EACJ,MAAM;IACJC,gBAAgB;IAChBC,YAAY,GAAG,CACb,MAAM,CACP;IACDC,cAAc,GAAG,IAAI;IACrBC,KAAK,GAAG;EACV,CAAC,
|
|
1
|
+
{"version":3,"file":"linesBeforeBlock.cjs","names":["_iterateJsdoc","_interopRequireDefault","require","e","__esModule","default","startPunctuators","Set","_default","exports","iterateJsdoc","context","jsdocNode","report","sourceCode","utils","checkBlockStarts","excludedTags","ignoreSameLine","ignoreSingleLines","lines","options","hasATag","tokensBefore","getTokensBefore","includeComments","tokenBefore","at","type","has","value","loc","end","line","start","startLine","sameLine","fix","fixer","indent","spaceDiff","column","match","slice","tokenPrior","startColumn","pop","repeat","insertTextAfter","iterateAllJsdocs","meta","docs","description","url","fixable","schema","additionalProperties","properties","items","module"],"sources":["../../src/rules/linesBeforeBlock.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc.js';\n\n/**\n * Punctuators that begin a logical group should not require a line before it skipped. Specifically\n * `[` starts an array, `{` starts an object or block, `(` starts a grouping, and `=` starts a\n * declaration (like a variable or a type alias).\n */\nconst startPunctuators = new Set([\n '(', '=', '[', '{',\n]);\n\nexport default iterateJsdoc(({\n context,\n jsdocNode,\n report,\n sourceCode,\n utils,\n}) => {\n const {\n checkBlockStarts,\n excludedTags = [\n 'type',\n ],\n ignoreSameLine = true,\n ignoreSingleLines = true,\n lines = 1,\n } = context.options[0] || {};\n\n if (utils.hasATag(excludedTags)) {\n return;\n }\n\n const tokensBefore = sourceCode.getTokensBefore(jsdocNode, {\n includeComments: true,\n });\n const tokenBefore = tokensBefore.at(-1);\n if (\n !tokenBefore || (\n tokenBefore.type === 'Punctuator' &&\n !checkBlockStarts &&\n startPunctuators.has(tokenBefore.value)\n )\n ) {\n return;\n }\n\n if (tokenBefore.loc?.end?.line + lines >=\n /** @type {number} */\n (jsdocNode.loc?.start?.line)\n ) {\n const startLine = jsdocNode.loc?.start?.line;\n const sameLine = tokenBefore.loc?.end?.line === startLine;\n\n if (sameLine && ignoreSameLine) {\n return;\n }\n\n if (ignoreSingleLines && jsdocNode.loc?.start.line === jsdocNode.loc?.end.line) {\n return;\n }\n\n /** @type {import('eslint').Rule.ReportFixer} */\n const fix = (fixer) => {\n let indent = '';\n if (sameLine) {\n const spaceDiff = /** @type {number} */ (jsdocNode.loc?.start?.column) -\n /** @type {number} */ (tokenBefore.loc?.end?.column);\n // @ts-expect-error Should be a comment\n indent = /** @type {import('estree').Comment} */ (\n jsdocNode\n ).value.match(/^\\*\\n([\\t ]*) \\*/u)?.[1]?.slice(spaceDiff);\n if (!indent) {\n /** @type {import('eslint').AST.Token|import('estree').Comment|undefined} */\n let tokenPrior = tokenBefore;\n let startColumn;\n while (tokenPrior && tokenPrior?.loc?.start?.line === startLine) {\n startColumn = tokenPrior.loc?.start?.column;\n tokenPrior = tokensBefore.pop();\n }\n\n indent = ' '.repeat(\n /* c8 ignore next */\n /** @type {number} */ (startColumn ? startColumn - 1 : 0),\n );\n }\n }\n\n return fixer.insertTextAfter(\n /** @type {import('eslint').AST.Token} */\n (tokenBefore),\n '\\n'.repeat(lines) +\n (sameLine ? '\\n' + indent : ''),\n );\n };\n\n report(`Required ${lines} line(s) before JSDoc block`, fix);\n }\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Enforces minimum number of newlines before JSDoc comment blocks',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/lines-before-block.md#repos-sticky-header',\n },\n fixable: 'code',\n schema: [\n {\n additionalProperties: false,\n properties: {\n checkBlockStarts: {\n type: 'boolean',\n },\n excludedTags: {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n ignoreSameLine: {\n type: 'boolean',\n },\n ignoreSingleLines: {\n type: 'boolean',\n },\n lines: {\n type: 'integer',\n },\n },\n type: 'object',\n },\n ],\n type: 'suggestion',\n },\n});\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA8C,SAAAD,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAE9C;AACA;AACA;AACA;AACA;AACA,MAAMG,gBAAgB,GAAG,IAAIC,GAAG,CAAC,CAC/B,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CACnB,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAJ,OAAA,GAEY,IAAAK,qBAAY,EAAC,CAAC;EAC3BC,O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AI,EAAE;QACR,CAAC;QACDX,YAAY,EAAE;UACZyC,KAAK,EAAE;YACL9B,IAAI,EAAE;UACR,CAAC;UACDA,IAAI,EAAE;QACR,CAAC;QACDV,cAAc,EAAE;UACdU,IAAI,EAAE;QACR,CAAC;QACDT,iBAAiB,EAAE;UACjBS,IAAI,EAAE;QACR,CAAC;QACDR,KAAK,EAAE;UACLQ,IAAI,EAAE;QACR;MACF,CAAC;MACDA,IAAI,EAAE;IACR,CAAC,CACF;IACDA,IAAI,EAAE;EACR;AACF,CAAC,CAAC;AAAA+B,MAAA,CAAAlD,OAAA,GAAAA,OAAA,CAAAJ,OAAA","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
|
-
import iterateJsdoc
|
|
1
|
+
import iterateJsdoc, {
|
|
2
|
+
parseComment,
|
|
3
|
+
} from '../iterateJsdoc.js';
|
|
2
4
|
import {
|
|
5
|
+
getTags,
|
|
6
|
+
} from '../jsdocUtils.js';
|
|
7
|
+
import {
|
|
8
|
+
getJSDocComment,
|
|
3
9
|
parse as parseType,
|
|
4
10
|
traverse,
|
|
5
11
|
tryParse as tryParseType,
|
|
6
12
|
} from '@es-joy/jsdoccomment';
|
|
7
13
|
|
|
8
14
|
export default iterateJsdoc(({
|
|
15
|
+
jsdoc,
|
|
9
16
|
node,
|
|
10
17
|
report,
|
|
11
18
|
settings,
|
|
19
|
+
sourceCode,
|
|
12
20
|
utils,
|
|
13
21
|
}) => {
|
|
14
22
|
const {
|
|
@@ -42,11 +50,11 @@ export default iterateJsdoc(({
|
|
|
42
50
|
});
|
|
43
51
|
};
|
|
44
52
|
|
|
45
|
-
const checkParamsAndReturnsTags = () => {
|
|
53
|
+
const checkParamsAndReturnsTags = (jsdc = jsdoc) => {
|
|
46
54
|
const paramName = /** @type {string} */ (utils.getPreferredTagName({
|
|
47
55
|
tagName: 'param',
|
|
48
56
|
}));
|
|
49
|
-
const paramTags =
|
|
57
|
+
const paramTags = getTags(jsdc, paramName);
|
|
50
58
|
for (const paramTag of paramTags) {
|
|
51
59
|
checkForUsedTypes(paramTag.type);
|
|
52
60
|
}
|
|
@@ -54,7 +62,7 @@ export default iterateJsdoc(({
|
|
|
54
62
|
const returnsName = /** @type {string} */ (utils.getPreferredTagName({
|
|
55
63
|
tagName: 'returns',
|
|
56
64
|
}));
|
|
57
|
-
const returnsTags =
|
|
65
|
+
const returnsTags = getTags(jsdc, returnsName);
|
|
58
66
|
for (const returnsTag of returnsTags) {
|
|
59
67
|
checkForUsedTypes(returnsTag.type);
|
|
60
68
|
}
|
|
@@ -98,6 +106,26 @@ export default iterateJsdoc(({
|
|
|
98
106
|
|
|
99
107
|
if (checkParamsAndReturns) {
|
|
100
108
|
checkParamsAndReturnsTags();
|
|
109
|
+
} else if (aliasDeclaration.type === 'ClassDeclaration') {
|
|
110
|
+
/* c8 ignore next -- TS */
|
|
111
|
+
for (const nde of aliasDeclaration?.body?.body ?? []) {
|
|
112
|
+
// @ts-expect-error Should be ok
|
|
113
|
+
const commentNode = getJSDocComment(sourceCode, nde, settings);
|
|
114
|
+
if (!commentNode) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const innerJsdoc = parseComment(commentNode, '');
|
|
119
|
+
checkParamsAndReturnsTags(innerJsdoc);
|
|
120
|
+
|
|
121
|
+
const typeName = /** @type {string} */ (utils.getPreferredTagName({
|
|
122
|
+
tagName: 'type',
|
|
123
|
+
}));
|
|
124
|
+
const typeTags = getTags(innerJsdoc, typeName);
|
|
125
|
+
for (const typeTag of typeTags) {
|
|
126
|
+
checkForUsedTypes(typeTag.type);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
101
129
|
}
|
|
102
130
|
|
|
103
131
|
checkTemplateTags();
|
|
@@ -162,17 +190,7 @@ export default iterateJsdoc(({
|
|
|
162
190
|
checkForUsedTypes(propertyTag.type);
|
|
163
191
|
}
|
|
164
192
|
|
|
165
|
-
|
|
166
|
-
const {
|
|
167
|
-
name,
|
|
168
|
-
} = tag;
|
|
169
|
-
const names = name.split(/,\s*/u);
|
|
170
|
-
for (const nme of names) {
|
|
171
|
-
if (!usedNames.has(nme)) {
|
|
172
|
-
report(`@template ${nme} not in use`, null, tag);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
193
|
+
checkTemplateTags();
|
|
176
194
|
}, {
|
|
177
195
|
iterateAllJsdocs: true,
|
|
178
196
|
meta: {
|
|
@@ -22,6 +22,7 @@ export default iterateJsdoc(({
|
|
|
22
22
|
'type',
|
|
23
23
|
],
|
|
24
24
|
ignoreSameLine = true,
|
|
25
|
+
ignoreSingleLines = true,
|
|
25
26
|
lines = 1,
|
|
26
27
|
} = context.options[0] || {};
|
|
27
28
|
|
|
@@ -54,6 +55,10 @@ export default iterateJsdoc(({
|
|
|
54
55
|
return;
|
|
55
56
|
}
|
|
56
57
|
|
|
58
|
+
if (ignoreSingleLines && jsdocNode.loc?.start.line === jsdocNode.loc?.end.line) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
57
62
|
/** @type {import('eslint').Rule.ReportFixer} */
|
|
58
63
|
const fix = (fixer) => {
|
|
59
64
|
let indent = '';
|
|
@@ -114,6 +119,9 @@ export default iterateJsdoc(({
|
|
|
114
119
|
ignoreSameLine: {
|
|
115
120
|
type: 'boolean',
|
|
116
121
|
},
|
|
122
|
+
ignoreSingleLines: {
|
|
123
|
+
type: 'boolean',
|
|
124
|
+
},
|
|
117
125
|
lines: {
|
|
118
126
|
type: 'integer',
|
|
119
127
|
},
|