eslint-plugin-jsdoc 46.2.4 → 46.2.5
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.
|
@@ -7,6 +7,7 @@ exports.default = void 0;
|
|
|
7
7
|
var _iterateJsdoc = _interopRequireDefault(require("../iterateJsdoc"));
|
|
8
8
|
var _jsdoccomment = require("@es-joy/jsdoccomment");
|
|
9
9
|
var _fs = require("fs");
|
|
10
|
+
var _isBuiltinModule = _interopRequireDefault(require("is-builtin-module"));
|
|
10
11
|
var _path = require("path");
|
|
11
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
13
|
/**
|
|
@@ -55,7 +56,11 @@ var _default = (0, _iterateJsdoc.default)(({
|
|
|
55
56
|
if (/^[./]/u.test(mod)) {
|
|
56
57
|
return;
|
|
57
58
|
}
|
|
58
|
-
if (
|
|
59
|
+
if ((0, _isBuiltinModule.default)(mod)) {
|
|
60
|
+
// mod = '@types/node';
|
|
61
|
+
// moduleCheck.set(mod, !deps.has(mod));
|
|
62
|
+
return;
|
|
63
|
+
} else if (!moduleCheck.has(mod)) {
|
|
59
64
|
let pkg;
|
|
60
65
|
try {
|
|
61
66
|
pkg = JSON.parse(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"importsAsDependencies.js","names":["_iterateJsdoc","_interopRequireDefault","require","_jsdoccomment","_fs","_path","obj","__esModule","default","deps","pkg","JSON","parse","readFileSync","join","process","cwd","Set","dependencies","Object","keys","devDependencies","error","console","log","moduleCheck","Map","_default","iterateJsdoc","jsdoc","settings","utils","mode","tag","tags","typeAst","tryParse","type","traverse","nde","mod","element","value","replace","test","has","types","typings","set","get","reportJSDoc","iterateAllJsdocs","meta","docs","description","url","exports","module"],"sources":["../../src/rules/importsAsDependencies.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc';\nimport {\n parse,\n traverse,\n tryParse,\n} from '@es-joy/jsdoccomment';\nimport {\n readFileSync,\n} from 'fs';\nimport {\n join,\n} from 'path';\n\n/**\n * @type {Set<string>}\n */\nlet deps;\ntry {\n const pkg = JSON.parse(\n // @ts-expect-error It's ok\n readFileSync(join(process.cwd(), './package.json')),\n );\n deps = new Set([\n ...(pkg.dependencies ?\n Object.keys(pkg.dependencies) :\n // istanbul ignore next\n []),\n ...(pkg.devDependencies ?\n Object.keys(pkg.devDependencies) :\n // istanbul ignore next\n []),\n ]);\n} catch (error) {\n /* eslint-disable no-console -- Inform user */\n // istanbul ignore next\n console.log(error);\n /* eslint-enable no-console -- Inform user */\n}\n\nconst moduleCheck = new Map();\n\nexport default iterateJsdoc(({\n jsdoc,\n settings,\n utils,\n}) => {\n // istanbul ignore if\n if (!deps) {\n return;\n }\n\n const {\n mode,\n } = settings;\n\n for (const tag of jsdoc.tags) {\n let typeAst;\n try {\n typeAst = mode === 'permissive' ? tryParse(tag.type) : parse(tag.type, mode);\n } catch {\n continue;\n }\n\n traverse(typeAst, (nde) => {\n if (nde.type === 'JsdocTypeImport') {\n let mod = nde.element.value.replace(\n /^(@[^/]+\\/[^/]+|[^/]+).*$/u, '$1',\n );\n\n if ((/^[./]/u).test(mod)) {\n return;\n }\n\n if (!moduleCheck.has(mod)) {\n let pkg;\n try {\n pkg = JSON.parse(\n // @ts-expect-error It's ok\n readFileSync(join(process.cwd(), 'node_modules', mod, './package.json')),\n );\n } catch {\n // Ignore\n }\n\n if (!pkg || (!pkg.types && !pkg.typings)) {\n mod = `@types/${mod}`;\n }\n\n moduleCheck.set(mod, !deps.has(mod));\n }\n\n if (moduleCheck.get(mod)) {\n utils.reportJSDoc(\n 'import points to package which is not found in dependencies',\n tag,\n );\n }\n }\n });\n }\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Reports if JSDoc `import()` statements point to a package which is not listed in `dependencies` or `devDependencies`',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/imports-as-dependencies.md#repos-sticky-header',\n },\n type: 'suggestion',\n },\n});\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AAKA,IAAAE,GAAA,GAAAF,OAAA;AAGA,IAAAG,KAAA,
|
|
1
|
+
{"version":3,"file":"importsAsDependencies.js","names":["_iterateJsdoc","_interopRequireDefault","require","_jsdoccomment","_fs","_isBuiltinModule","_path","obj","__esModule","default","deps","pkg","JSON","parse","readFileSync","join","process","cwd","Set","dependencies","Object","keys","devDependencies","error","console","log","moduleCheck","Map","_default","iterateJsdoc","jsdoc","settings","utils","mode","tag","tags","typeAst","tryParse","type","traverse","nde","mod","element","value","replace","test","isBuiltinModule","has","types","typings","set","get","reportJSDoc","iterateAllJsdocs","meta","docs","description","url","exports","module"],"sources":["../../src/rules/importsAsDependencies.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc';\nimport {\n parse,\n traverse,\n tryParse,\n} from '@es-joy/jsdoccomment';\nimport {\n readFileSync,\n} from 'fs';\nimport isBuiltinModule from 'is-builtin-module';\nimport {\n join,\n} from 'path';\n\n/**\n * @type {Set<string>}\n */\nlet deps;\ntry {\n const pkg = JSON.parse(\n // @ts-expect-error It's ok\n readFileSync(join(process.cwd(), './package.json')),\n );\n deps = new Set([\n ...(pkg.dependencies ?\n Object.keys(pkg.dependencies) :\n // istanbul ignore next\n []),\n ...(pkg.devDependencies ?\n Object.keys(pkg.devDependencies) :\n // istanbul ignore next\n []),\n ]);\n} catch (error) {\n /* eslint-disable no-console -- Inform user */\n // istanbul ignore next\n console.log(error);\n /* eslint-enable no-console -- Inform user */\n}\n\nconst moduleCheck = new Map();\n\nexport default iterateJsdoc(({\n jsdoc,\n settings,\n utils,\n}) => {\n // istanbul ignore if\n if (!deps) {\n return;\n }\n\n const {\n mode,\n } = settings;\n\n for (const tag of jsdoc.tags) {\n let typeAst;\n try {\n typeAst = mode === 'permissive' ? tryParse(tag.type) : parse(tag.type, mode);\n } catch {\n continue;\n }\n\n traverse(typeAst, (nde) => {\n if (nde.type === 'JsdocTypeImport') {\n let mod = nde.element.value.replace(\n /^(@[^/]+\\/[^/]+|[^/]+).*$/u, '$1',\n );\n\n if ((/^[./]/u).test(mod)) {\n return;\n }\n\n if (isBuiltinModule(mod)) {\n // mod = '@types/node';\n // moduleCheck.set(mod, !deps.has(mod));\n return;\n } else if (!moduleCheck.has(mod)) {\n let pkg;\n try {\n pkg = JSON.parse(\n // @ts-expect-error It's ok\n readFileSync(join(process.cwd(), 'node_modules', mod, './package.json')),\n );\n } catch {\n // Ignore\n }\n\n if (!pkg || (!pkg.types && !pkg.typings)) {\n mod = `@types/${mod}`;\n }\n\n moduleCheck.set(mod, !deps.has(mod));\n }\n\n if (moduleCheck.get(mod)) {\n utils.reportJSDoc(\n 'import points to package which is not found in dependencies',\n tag,\n );\n }\n }\n });\n }\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Reports if JSDoc `import()` statements point to a package which is not listed in `dependencies` or `devDependencies`',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/imports-as-dependencies.md#repos-sticky-header',\n },\n type: 'suggestion',\n },\n});\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AAKA,IAAAE,GAAA,GAAAF,OAAA;AAGA,IAAAG,gBAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AAEc,SAAAD,uBAAAM,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAEd;AACA;AACA;AACA,IAAIG,IAAI;AACR,IAAI;EACF,MAAMC,GAAG,GAAGC,IAAI,CAACC,KAAK;EACpB;EACA,IAAAC,gBAAY,EAAC,IAAAC,UAAI,EAACC,OAAO,CAACC,GAAG,CAAC,CAAC,EAAE,gBAAgB,CAA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UACxB;UACA;UACA;QACF,CAAC,MAAM,IAAI,CAACf,WAAW,CAACqB,GAAG,CAACN,GAAG,CAAC,EAAE;UAChC,IAAI9B,GAAG;UACP,IAAI;YACFA,GAAG,GAAGC,IAAI,CAACC,KAAK;YACd;YACA,IAAAC,gBAAY,EAAC,IAAAC,UAAI,EAACC,OAAO,CAACC,GAAG,CAAC,CAAC,EAAE,cAAc,EAAEwB,GAAG,EAAE,gBAAgB,CAAC,CACzE,CAAC;UACH,CAAC,CAAC,MAAM;YACN;UAAA;UAGF,IAAI,CAAC9B,GAAG,IAAK,CAACA,GAAG,CAACqC,KAAK,IAAI,CAACrC,GAAG,CAACsC,OAAQ,EAAE;YACxCR,GAAG,GAAI,UAASA,GAAI,EAAC;UACvB;UAEAf,WAAW,CAACwB,GAAG,CAACT,GAAG,EAAE,CAAC/B,IAAI,CAACqC,GAAG,CAACN,GAAG,CAAC,CAAC;QACtC;QAEA,IAAIf,WAAW,CAACyB,GAAG,CAACV,GAAG,CAAC,EAAE;UACxBT,KAAK,CAACoB,WAAW,CACf,6DAA6D,EAC7DlB,GACF,CAAC;QACH;MACF;IACF,CAAC,CAAC;EACJ;AACF,CAAC,EAAE;EACDmB,gBAAgB,EAAE,IAAI;EACtBC,IAAI,EAAE;IACJC,IAAI,EAAE;MACJC,WAAW,EAAE,sHAAsH;MACnIC,GAAG,EAAE;IACP,CAAC;IACDnB,IAAI,EAAE;EACR;AACF,CAAC,CAAC;AAAAoB,OAAA,CAAAjD,OAAA,GAAAmB,QAAA;AAAA+B,MAAA,CAAAD,OAAA,GAAAA,OAAA,CAAAjD,OAAA"}
|
|
@@ -83,5 +83,17 @@ The following patterns are not considered problems:
|
|
|
83
83
|
/**
|
|
84
84
|
* @type {null|import('./relativePath.js').Program}
|
|
85
85
|
*/
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @type {null|import('fs').PathLike}
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @type {null|import('fs/promises').FileHandle}
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @type {null|import('node:fs').PathLike}
|
|
97
|
+
*/
|
|
86
98
|
````
|
|
87
99
|
|
package/package.json
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"debug": "^4.3.4",
|
|
12
12
|
"escape-string-regexp": "^4.0.0",
|
|
13
13
|
"esquery": "^1.5.0",
|
|
14
|
+
"is-builtin-module": "^3.2.1",
|
|
14
15
|
"semver": "^7.5.1",
|
|
15
16
|
"spdx-expression-parse": "^3.0.1"
|
|
16
17
|
},
|
|
@@ -37,7 +38,7 @@
|
|
|
37
38
|
"@types/estree": "^1.0.1",
|
|
38
39
|
"@types/lodash.defaultsdeep": "^4.6.7",
|
|
39
40
|
"@types/mocha": "^10.0.1",
|
|
40
|
-
"@types/node": "^20.2.
|
|
41
|
+
"@types/node": "^20.2.5",
|
|
41
42
|
"@types/semver": "^7.5.0",
|
|
42
43
|
"@types/spdx-expression-parse": "^3.0.2",
|
|
43
44
|
"@typescript-eslint/parser": "^5.59.6",
|
|
@@ -135,5 +136,5 @@
|
|
|
135
136
|
"test-cov": "cross-env TIMING=1 nyc --reporter text npm run test-no-cov",
|
|
136
137
|
"test-index": "npm run test-no-cov -- test/rules/index.js"
|
|
137
138
|
},
|
|
138
|
-
"version": "46.2.
|
|
139
|
+
"version": "46.2.5"
|
|
139
140
|
}
|