Skip to content

Commit 065f11a

Browse files
committed
fix: ensure permissive settings are converted for jsdoc-type-pratt-parser
Also: - chore: update jsdoccomment and devDeps.
1 parent 68fad5b commit 065f11a

File tree

9 files changed

+217
-28
lines changed

9 files changed

+217
-28
lines changed

docs/rules/prefer-import-tag.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,32 @@ The following patterns are considered problems:
266266
*/
267267
// "jsdoc/prefer-import-tag": ["error"|"warn", {"exemptTypedefs":true}]
268268
// Message: Inline `import()` found; prefer `@import`
269+
270+
/**
271+
* @type {import('eslint').anchors[keyof DataMap.anchors]}
272+
*/
273+
// Message: Inline `import()` found; prefer `@import`
274+
275+
/** @typedef {import('eslint').Rule[keyof import('eslint').Rule]} Rule */
276+
/**
277+
* @type {import('eslint').Abc.Rule}
278+
*/
279+
// "jsdoc/prefer-import-tag": ["error"|"warn", {"exemptTypedefs":true}]
280+
// Message: Inline `import()` found; prefer `@import`
281+
282+
/** @typedef {import('eslint').Rule[keyof import('eslint').Rule]} Rule */
283+
/**
284+
* @type {import('eslint').Rule[keyof import('eslint').Rule]}
285+
*/
286+
// "jsdoc/prefer-import-tag": ["error"|"warn", {"exemptTypedefs":true}]
287+
// Message: Inline `import()` found; using `@typedef`
288+
289+
/** @typedef {import('eslint').Rule} Rule */
290+
/**
291+
* @type {import('eslint').Rule[keyof import('eslint').Rule]}
292+
*/
293+
// "jsdoc/prefer-import-tag": ["error"|"warn", {"exemptTypedefs":true}]
294+
// Message: Inline `import()` found; using `@typedef`
269295
````
270296

271297

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"url": "http://gajus.com"
66
},
77
"dependencies": {
8-
"@es-joy/jsdoccomment": "~0.60.0",
8+
"@es-joy/jsdoccomment": "~0.61.0",
99
"are-docs-informative": "^0.0.2",
1010
"comment-parser": "1.4.1",
1111
"debug": "^4.4.3",
@@ -58,10 +58,10 @@
5858
"glob": "^11.0.3",
5959
"globals": "^16.4.0",
6060
"husky": "^9.1.7",
61-
"jsdoc-type-pratt-parser": "^5.4.0",
61+
"jsdoc-type-pratt-parser": "^5.8.0",
6262
"json-schema": "^0.4.0",
6363
"json-schema-to-typescript": "^15.0.4",
64-
"lint-staged": "^16.2.0",
64+
"lint-staged": "^16.2.1",
6565
"mocha": "^11.7.2",
6666
"open-editor": "^5.1.0",
6767
"replace": "^1.2.2",

pnpm-lock.yaml

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index-cjs.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ import textEscaping from './rules/textEscaping.js';
6868
import typeFormatting from './rules/typeFormatting.js';
6969
import validTypes from './rules/validTypes.js';
7070

71-
/* eslint-disable jsdoc/valid-types -- Bug */
7271
/**
7372
* @typedef {"recommended" | "stylistic" | "contents" | "logical" | "requirements"} ConfigGroups
7473
* @typedef {"" | "-typescript" | "-typescript-flavor"} ConfigVariants
@@ -86,7 +85,6 @@ import validTypes from './rules/validTypes.js';
8685
* }}
8786
*/
8887
const index = {};
89-
/* eslint-enable jsdoc/valid-types -- Bug */
9088
index.configs = {};
9189
index.rules = {
9290
'check-access': checkAccess,

src/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ import textEscaping from './rules/textEscaping.js';
7474
import typeFormatting from './rules/typeFormatting.js';
7575
import validTypes from './rules/validTypes.js';
7676

77-
/* eslint-disable jsdoc/valid-types -- Bug */
7877
/**
7978
* @typedef {"recommended" | "stylistic" | "contents" | "logical" | "requirements"} ConfigGroups
8079
* @typedef {"" | "-typescript" | "-typescript-flavor"} ConfigVariants
@@ -92,7 +91,6 @@ import validTypes from './rules/validTypes.js';
9291
* }}
9392
*/
9493
const index = {};
95-
/* eslint-enable jsdoc/valid-types -- Bug */
9694
index.configs = {};
9795
index.rules = {
9896
'check-access': checkAccess,

src/iterateJsdoc.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2284,7 +2284,10 @@ const iterateAllJsdocs = (iterator, ruleConfig, contexts, additiveCommentContext
22842284
}
22852285

22862286
if (contexts) {
2287-
handler = commentHandler(settings);
2287+
handler = commentHandler({
2288+
...settings,
2289+
mode: settings.mode === 'permissive' ? 'typescript' : settings.mode,
2290+
});
22882291
}
22892292

22902293
const state = {};
@@ -2537,7 +2540,10 @@ export default function iterateJsdoc (iterator, ruleConfig) {
25372540
contextObject = jsdocUtils.getContextObject(
25382541
contexts,
25392542
checkJsdoc,
2540-
commentHandler(settings),
2543+
commentHandler({
2544+
...settings,
2545+
mode: settings.mode === 'permissive' ? 'typescript' : settings.mode,
2546+
}),
25412547
);
25422548
} else {
25432549
for (const prop of [

src/rules/preferImportTag.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,18 @@ export default iterateJsdoc(({
117117
break;
118118
}
119119

120-
pathSegments.unshift(currentNode.right.value);
120+
pathSegments.unshift(
121+
currentNode.right.type === 'JsdocTypeIndexedAccessIndex' ?
122+
stringify(currentNode.right.right) :
123+
currentNode.right.value,
124+
);
121125
nodes.unshift(currentNode);
122126
propertyOrBrackets.unshift(currentNode.pathType);
123-
quotes.unshift(currentNode.right.meta.quote);
127+
quotes.unshift(
128+
currentNode.right.type === 'JsdocTypeIndexedAccessIndex' ?
129+
undefined :
130+
currentNode.right.meta.quote,
131+
);
124132
}
125133

126134
/**
@@ -218,7 +226,12 @@ export default iterateJsdoc(({
218226
break;
219227
}
220228

221-
if (typedefNode.right.value !== pathSegment) {
229+
if (
230+
(typedefNode.right.type === 'JsdocTypeIndexedAccessIndex' &&
231+
stringify(typedefNode.right.right) !== pathSegment) ||
232+
(typedefNode.right.type !== 'JsdocTypeIndexedAccessIndex' &&
233+
typedefNode.right.value !== pathSegment)
234+
) {
222235
if (namepathMatch === true) {
223236
// It stopped matching, so stop
224237
break;

test/rules/assertions/noRestrictedSyntax.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,35 @@ export default /** @type {import('../index.js').TestCases} */ ({
3535
*/
3636
function quux () {
3737
38+
}
39+
`,
40+
errors: [
41+
{
42+
line: 2,
43+
message: 'Syntax is restricted: FunctionDeclaration',
44+
},
45+
],
46+
ignoreReadme: true,
47+
options: [
48+
{
49+
contexts: [
50+
'FunctionDeclaration',
51+
],
52+
},
53+
],
54+
settings: {
55+
jsdoc: {
56+
mode: 'permissive',
57+
},
58+
},
59+
},
60+
{
61+
code: `
62+
/**
63+
*
64+
*/
65+
function quux () {
66+
3867
}
3968
`,
4069
errors: [
@@ -780,6 +809,32 @@ export default /** @type {import('../index.js').TestCases} */ ({
780809
},
781810
],
782811
},
812+
{
813+
code: `
814+
/**
815+
* @param ab
816+
* @param cd
817+
*/
818+
function a () {}
819+
`,
820+
ignoreReadme: true,
821+
options: [
822+
{
823+
contexts: [
824+
{
825+
comment: 'JsdocBlock:has(JsdocTag[name=/opt_/])',
826+
context: 'any',
827+
message: 'Only allowing names not matching `/^opt_/i`.',
828+
},
829+
],
830+
},
831+
],
832+
settings: {
833+
jsdoc: {
834+
mode: 'permissive',
835+
},
836+
},
837+
},
783838
{
784839
code: `
785840
/**

0 commit comments

Comments
 (0)