eslint-plugin-jsdoc 50.6.12 → 50.6.13
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.
|
@@ -6,6 +6,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _iterateJsdoc = _interopRequireDefault(require("../iterateJsdoc.cjs"));
|
|
8
8
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
/**
|
|
10
|
+
* `;` ends a previous statement, `}` ends a previous block, `|` is seen the middle of a union, and
|
|
11
|
+
* `&` is seen in the middle of an intersection. All other punctuators are for things like arrays,
|
|
12
|
+
* functions, type aliases, and so on that shouldn't require a line before it.
|
|
13
|
+
*/
|
|
14
|
+
const lintedPunctuators = new Set([';', '}', '|', '&']);
|
|
9
15
|
var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
10
16
|
context,
|
|
11
17
|
jsdocNode,
|
|
@@ -26,8 +32,8 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
|
26
32
|
const tokensBefore = sourceCode.getTokensBefore(jsdocNode, {
|
|
27
33
|
includeComments: true
|
|
28
34
|
});
|
|
29
|
-
const tokenBefore = tokensBefore.
|
|
30
|
-
if (!tokenBefore || tokenBefore.
|
|
35
|
+
const tokenBefore = tokensBefore.at(-1);
|
|
36
|
+
if (!tokenBefore || tokenBefore.type === 'Punctuator' && !checkBlockStarts && !lintedPunctuators.has(tokenBefore.value)) {
|
|
31
37
|
return;
|
|
32
38
|
}
|
|
33
39
|
if (((_tokenBefore$loc = tokenBefore.loc) === null || _tokenBefore$loc === void 0 || (_tokenBefore$loc = _tokenBefore$loc.end) === null || _tokenBefore$loc === void 0 ? void 0 : _tokenBefore$loc.line) + lines >= ( /** @type {number} */(_jsdocNode$loc = jsdocNode.loc) === null || _jsdocNode$loc === void 0 || (_jsdocNode$loc = _jsdocNode$loc.start) === null || _jsdocNode$loc === void 0 ? void 0 : _jsdocNode$loc.line)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linesBeforeBlock.cjs","names":["_iterateJsdoc","_interopRequireDefault","require","e","__esModule","default","_default","exports","iterateJsdoc","context","jsdocNode","sourceCode","report","utils","_tokenBefore$loc","_jsdocNode$loc","checkBlockStarts","lines","ignoreSameLine","excludedTags","options","hasATag","tokensBefore","getTokensBefore","includeComments","tokenBefore","
|
|
1
|
+
{"version":3,"file":"linesBeforeBlock.cjs","names":["_iterateJsdoc","_interopRequireDefault","require","e","__esModule","default","lintedPunctuators","Set","_default","exports","iterateJsdoc","context","jsdocNode","sourceCode","report","utils","_tokenBefore$loc","_jsdocNode$loc","checkBlockStarts","lines","ignoreSameLine","excludedTags","options","hasATag","tokensBefore","getTokensBefore","includeComments","tokenBefore","at","type","has","value","loc","end","line","start","_jsdocNode$loc2","_tokenBefore$loc2","startLine","sameLine","fix","fixer","indent","_jsdocNode$loc3","_tokenBefore$loc3","_jsdocNode$value$matc","spaceDiff","column","match","slice","tokenPrior","startColumn","_tokenPrior","_tokenPrior$loc","pop","repeat","insertTextAfter","iterateAllJsdocs","meta","fixable","docs","description","url","schema","additionalProperties","properties","items","module"],"sources":["../../src/rules/linesBeforeBlock.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc.js';\n\n/**\n * `;` ends a previous statement, `}` ends a previous block, `|` is seen the middle of a union, and\n * `&` is seen in the middle of an intersection. All other punctuators are for things like arrays,\n * functions, type aliases, and so on that shouldn't require a line before it.\n */\nconst lintedPunctuators = new Set([';', '}', '|', '&']);\n\nexport default iterateJsdoc(({\n context,\n jsdocNode,\n sourceCode,\n report,\n utils,\n}) => {\n const {\n checkBlockStarts,\n lines = 1,\n ignoreSameLine = true,\n excludedTags = ['type']\n } = context.options[0] || {};\n\n if (utils.hasATag(excludedTags)) {\n return;\n }\n\n const tokensBefore = sourceCode.getTokensBefore(jsdocNode, {includeComments: true});\n const tokenBefore = tokensBefore.at(-1);\n if (\n !tokenBefore || (\n tokenBefore.type === 'Punctuator' &&\n !checkBlockStarts &&\n !lintedPunctuators.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]*) \\*/)?.[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 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 report(`Required ${lines} line(s) before JSDoc block`, fix);\n }\n}, {\n iterateAllJsdocs: true,\n meta: {\n fixable: 'code',\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 schema: [\n {\n additionalProperties: false,\n properties: {\n checkBlockStarts: {\n type: 'boolean',\n },\n excludedTags: {\n type: 'array',\n items: {\n type: 'string'\n }\n },\n ignoreSameLine: {\n type: 'boolean',\n },\n lines: {\n type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CACN;MACEC,oBAAoB,EAAE,KAAK;MAC3BC,UAAU,EAAE;QACV/C,gBAAgB,EAAE;UAChBW,IAAI,EAAE;QACR,CAAC;QACDR,YAAY,EAAE;UACZQ,IAAI,EAAE,OAAO;UACbqC,KAAK,EAAE;YACLrC,IAAI,EAAE;UACR;QACF,CAAC;QACDT,cAAc,EAAE;UACdS,IAAI,EAAE;QACR,CAAC;QACDV,KAAK,EAAE;UACLU,IAAI,EAAE;QACR;MACF,CAAC;MACDA,IAAI,EAAE;IACR,CAAC,CACF;IACDA,IAAI,EAAE;EACR;AACF,CAAC,CAAC;AAAAsC,MAAA,CAAA1D,OAAA,GAAAA,OAAA,CAAAJ,OAAA","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import iterateJsdoc from '../iterateJsdoc.js';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* `;` ends a previous statement, `}` ends a previous block, `|` is seen the middle of a union, and
|
|
5
|
+
* `&` is seen in the middle of an intersection. All other punctuators are for things like arrays,
|
|
6
|
+
* functions, type aliases, and so on that shouldn't require a line before it.
|
|
7
|
+
*/
|
|
8
|
+
const lintedPunctuators = new Set([';', '}', '|', '&']);
|
|
9
|
+
|
|
3
10
|
export default iterateJsdoc(({
|
|
4
11
|
context,
|
|
5
12
|
jsdocNode,
|
|
@@ -19,8 +26,14 @@ export default iterateJsdoc(({
|
|
|
19
26
|
}
|
|
20
27
|
|
|
21
28
|
const tokensBefore = sourceCode.getTokensBefore(jsdocNode, {includeComments: true});
|
|
22
|
-
const tokenBefore = tokensBefore.
|
|
23
|
-
if (
|
|
29
|
+
const tokenBefore = tokensBefore.at(-1);
|
|
30
|
+
if (
|
|
31
|
+
!tokenBefore || (
|
|
32
|
+
tokenBefore.type === 'Punctuator' &&
|
|
33
|
+
!checkBlockStarts &&
|
|
34
|
+
!lintedPunctuators.has(tokenBefore.value)
|
|
35
|
+
)
|
|
36
|
+
) {
|
|
24
37
|
return;
|
|
25
38
|
}
|
|
26
39
|
|