Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions docs/rules/prefer-import-tag.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,32 @@ The following patterns are considered problems:
*/
// "jsdoc/prefer-import-tag": ["error"|"warn", {"exemptTypedefs":true}]
// Message: Inline `import()` found; prefer `@import`

/**
* @type {import('eslint').anchors[keyof DataMap.anchors]}
*/
// Message: Inline `import()` found; prefer `@import`

/** @typedef {import('eslint').Rule[keyof import('eslint').Rule]} Rule */
/**
* @type {import('eslint').Abc.Rule}
*/
// "jsdoc/prefer-import-tag": ["error"|"warn", {"exemptTypedefs":true}]
// Message: Inline `import()` found; prefer `@import`

/** @typedef {import('eslint').Rule[keyof import('eslint').Rule]} Rule */
/**
* @type {import('eslint').Rule[keyof import('eslint').Rule]}
*/
// "jsdoc/prefer-import-tag": ["error"|"warn", {"exemptTypedefs":true}]
// Message: Inline `import()` found; using `@typedef`

/** @typedef {import('eslint').Rule} Rule */
/**
* @type {import('eslint').Rule[keyof import('eslint').Rule]}
*/
// "jsdoc/prefer-import-tag": ["error"|"warn", {"exemptTypedefs":true}]
// Message: Inline `import()` found; using `@typedef`
````


Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"url": "http://gajus.com"
},
"dependencies": {
"@es-joy/jsdoccomment": "~0.60.0",
"@es-joy/jsdoccomment": "~0.61.0",
"are-docs-informative": "^0.0.2",
"comment-parser": "1.4.1",
"debug": "^4.4.3",
Expand Down Expand Up @@ -58,10 +58,10 @@
"glob": "^11.0.3",
"globals": "^16.4.0",
"husky": "^9.1.7",
"jsdoc-type-pratt-parser": "^5.4.0",
"jsdoc-type-pratt-parser": "^5.8.0",
"json-schema": "^0.4.0",
"json-schema-to-typescript": "^15.0.4",
"lint-staged": "^16.2.0",
"lint-staged": "^16.2.1",
"mocha": "^11.7.2",
"open-editor": "^5.1.0",
"replace": "^1.2.2",
Expand Down
32 changes: 16 additions & 16 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 24 additions & 4 deletions src/index-cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,23 @@ import textEscaping from './rules/textEscaping.js';
import typeFormatting from './rules/typeFormatting.js';
import validTypes from './rules/validTypes.js';

/* eslint-disable jsdoc/valid-types -- Bug */
/**
* @typedef {"recommended" | "stylistic" | "contents" | "logical" | "requirements"} ConfigGroups
* @typedef {"" | "-typescript" | "-typescript-flavor"} ConfigVariants
* @typedef {"" | "-error"} ErrorLevelVariants
* @type {import('eslint').ESLint.Plugin & {
* configs: Record<`flat/${ConfigGroups}${ConfigVariants}${ErrorLevelVariants}`,
* import('eslint').Linter.Config> & Record<"examples"|"default-expressions"|"examples-and-default-expressions", import('eslint').Linter.Config[]>
* configs: Record<
* `flat/${ConfigGroups}${ConfigVariants}${ErrorLevelVariants}`,
* import('eslint').Linter.Config
* > &
* Record<
* "examples"|"default-expressions"|"examples-and-default-expressions",
* import('eslint').Linter.Config[]
* > &
* Record<"flat/recommended-mixed", import('eslint').Linter.Config[]>
* }}
*/
const index = {};
/* eslint-enable jsdoc/valid-types -- Bug */
index.configs = {};
index.rules = {
'check-access': checkAccess,
Expand Down Expand Up @@ -666,4 +671,19 @@ index.configs['examples-and-default-expressions'] = /** @type {import('eslint').
}),
]);

index.configs['flat/recommended-mixed'] = [
{
...index.configs['flat/recommended-typescript-flavor'],
files: [
'**/*.{js,jsx,cjs,mjs}',
],
},
{
...index.configs['flat/recommended-typescript'],
files: [
'**/*.{ts,tsx,cts,mts}',
],
},
];

export default index;
28 changes: 24 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,23 @@ import textEscaping from './rules/textEscaping.js';
import typeFormatting from './rules/typeFormatting.js';
import validTypes from './rules/validTypes.js';

/* eslint-disable jsdoc/valid-types -- Bug */
/**
* @typedef {"recommended" | "stylistic" | "contents" | "logical" | "requirements"} ConfigGroups
* @typedef {"" | "-typescript" | "-typescript-flavor"} ConfigVariants
* @typedef {"" | "-error"} ErrorLevelVariants
* @type {import('eslint').ESLint.Plugin & {
* configs: Record<`flat/${ConfigGroups}${ConfigVariants}${ErrorLevelVariants}`,
* import('eslint').Linter.Config> & Record<"examples"|"default-expressions"|"examples-and-default-expressions", import('eslint').Linter.Config[]>
* configs: Record<
* `flat/${ConfigGroups}${ConfigVariants}${ErrorLevelVariants}`,
* import('eslint').Linter.Config
* > &
* Record<
* "examples"|"default-expressions"|"examples-and-default-expressions",
* import('eslint').Linter.Config[]
* > &
* Record<"flat/recommended-mixed", import('eslint').Linter.Config[]>
* }}
*/
const index = {};
/* eslint-enable jsdoc/valid-types -- Bug */
index.configs = {};
index.rules = {
'check-access': checkAccess,
Expand Down Expand Up @@ -672,6 +677,21 @@ index.configs['examples-and-default-expressions'] = /** @type {import('eslint').
}),
]);

index.configs['flat/recommended-mixed'] = [
{
...index.configs['flat/recommended-typescript-flavor'],
files: [
'**/*.{js,jsx,cjs,mjs}',
],
},
{
...index.configs['flat/recommended-typescript'],
files: [
'**/*.{ts,tsx,cts,mts}',
],
},
];

export default index;

/* eslint-disable jsdoc/valid-types -- Bug */
Expand Down
10 changes: 8 additions & 2 deletions src/iterateJsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@
src.number = firstNumber + /** @type {Integer} */ (lastIndex) + idx;
}

// Todo: Once rewiring of tags may be fixed in comment-parser to reflect

Check warning on line 1135 in src/iterateJsdoc.js

View workflow job for this annotation

GitHub Actions / Lint

Unexpected 'todo' comment: 'Todo: Once rewiring of tags may be fixed...'
// missing tags, this step should be added here (so that, e.g.,
// if accessing `jsdoc.tags`, such as to add a new tag, the
// correct information will be available)
Expand Down Expand Up @@ -2284,7 +2284,10 @@
}

if (contexts) {
handler = commentHandler(settings);
handler = commentHandler({
...settings,
mode: settings.mode === 'permissive' ? 'typescript' : settings.mode,
});
}

const state = {};
Expand Down Expand Up @@ -2537,7 +2540,10 @@
contextObject = jsdocUtils.getContextObject(
contexts,
checkJsdoc,
commentHandler(settings),
commentHandler({
...settings,
mode: settings.mode === 'permissive' ? 'typescript' : settings.mode,
}),
);
} else {
for (const prop of [
Expand Down
19 changes: 16 additions & 3 deletions src/rules/preferImportTag.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,18 @@ export default iterateJsdoc(({
break;
}

pathSegments.unshift(currentNode.right.value);
pathSegments.unshift(
currentNode.right.type === 'JsdocTypeIndexedAccessIndex' ?
stringify(currentNode.right.right) :
currentNode.right.value,
);
nodes.unshift(currentNode);
propertyOrBrackets.unshift(currentNode.pathType);
quotes.unshift(currentNode.right.meta.quote);
quotes.unshift(
currentNode.right.type === 'JsdocTypeIndexedAccessIndex' ?
undefined :
currentNode.right.meta.quote,
);
}

/**
Expand Down Expand Up @@ -218,7 +226,12 @@ export default iterateJsdoc(({
break;
}

if (typedefNode.right.value !== pathSegment) {
if (
(typedefNode.right.type === 'JsdocTypeIndexedAccessIndex' &&
stringify(typedefNode.right.right) !== pathSegment) ||
(typedefNode.right.type !== 'JsdocTypeIndexedAccessIndex' &&
typedefNode.right.value !== pathSegment)
) {
if (namepathMatch === true) {
// It stopped matching, so stop
break;
Expand Down
55 changes: 55 additions & 0 deletions test/rules/assertions/noRestrictedSyntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,35 @@ export default /** @type {import('../index.js').TestCases} */ ({
*/
function quux () {

}
`,
errors: [
{
line: 2,
message: 'Syntax is restricted: FunctionDeclaration',
},
],
ignoreReadme: true,
options: [
{
contexts: [
'FunctionDeclaration',
],
},
],
settings: {
jsdoc: {
mode: 'permissive',
},
},
},
{
code: `
/**
*
*/
function quux () {

}
`,
errors: [
Expand Down Expand Up @@ -780,6 +809,32 @@ export default /** @type {import('../index.js').TestCases} */ ({
},
],
},
{
code: `
/**
* @param ab
* @param cd
*/
function a () {}
`,
ignoreReadme: true,
options: [
{
contexts: [
{
comment: 'JsdocBlock:has(JsdocTag[name=/opt_/])',
context: 'any',
message: 'Only allowing names not matching `/^opt_/i`.',
},
],
},
],
settings: {
jsdoc: {
mode: 'permissive',
},
},
},
{
code: `
/**
Expand Down
Loading
Loading