eslint-plugin-jsdoc 46.2.4 → 46.2.6
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,27 +7,32 @@ 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
|
/**
|
|
13
|
-
* @type {Set<string
|
|
14
|
+
* @type {Set<string>|null}
|
|
14
15
|
*/
|
|
15
16
|
let deps;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
17
|
+
const setDeps = function () {
|
|
18
|
+
try {
|
|
19
|
+
const pkg = JSON.parse(
|
|
20
|
+
// @ts-expect-error It's ok
|
|
21
|
+
(0, _fs.readFileSync)((0, _path.join)(process.cwd(), './package.json')));
|
|
22
|
+
deps = new Set([...(pkg.dependencies ? Object.keys(pkg.dependencies) :
|
|
23
|
+
// istanbul ignore next
|
|
24
|
+
[]), ...(pkg.devDependencies ? Object.keys(pkg.devDependencies) :
|
|
25
|
+
// istanbul ignore next
|
|
26
|
+
[])]);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
// istanbul ignore next -- our package.json exists
|
|
29
|
+
deps = null;
|
|
30
|
+
/* eslint-disable no-console -- Inform user */
|
|
31
|
+
// istanbul ignore next -- our package.json exists
|
|
32
|
+
console.log(error);
|
|
33
|
+
/* eslint-enable no-console -- Inform user */
|
|
34
|
+
}
|
|
35
|
+
};
|
|
31
36
|
|
|
32
37
|
const moduleCheck = new Map();
|
|
33
38
|
var _default = (0, _iterateJsdoc.default)(({
|
|
@@ -36,7 +41,12 @@ var _default = (0, _iterateJsdoc.default)(({
|
|
|
36
41
|
utils
|
|
37
42
|
}) => {
|
|
38
43
|
// istanbul ignore if
|
|
39
|
-
if (
|
|
44
|
+
if (deps === undefined) {
|
|
45
|
+
setDeps();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// istanbul ignore if -- our package.json exists
|
|
49
|
+
if (deps === null) {
|
|
40
50
|
return;
|
|
41
51
|
}
|
|
42
52
|
const {
|
|
@@ -49,13 +59,23 @@ var _default = (0, _iterateJsdoc.default)(({
|
|
|
49
59
|
} catch {
|
|
50
60
|
continue;
|
|
51
61
|
}
|
|
62
|
+
|
|
63
|
+
// eslint-disable-next-line no-loop-func -- Safe
|
|
52
64
|
(0, _jsdoccomment.traverse)(typeAst, nde => {
|
|
65
|
+
// istanbul ignore if -- TS guard
|
|
66
|
+
if (deps === null) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
53
69
|
if (nde.type === 'JsdocTypeImport') {
|
|
54
70
|
let mod = nde.element.value.replace(/^(@[^/]+\/[^/]+|[^/]+).*$/u, '$1');
|
|
55
71
|
if (/^[./]/u.test(mod)) {
|
|
56
72
|
return;
|
|
57
73
|
}
|
|
58
|
-
if (
|
|
74
|
+
if ((0, _isBuiltinModule.default)(mod)) {
|
|
75
|
+
// mod = '@types/node';
|
|
76
|
+
// moduleCheck.set(mod, !deps.has(mod));
|
|
77
|
+
return;
|
|
78
|
+
} else if (!moduleCheck.has(mod)) {
|
|
59
79
|
let pkg;
|
|
60
80
|
try {
|
|
61
81
|
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
|
|
1
|
+
{"version":3,"file":"importsAsDependencies.js","names":["_iterateJsdoc","_interopRequireDefault","require","_jsdoccomment","_fs","_isBuiltinModule","_path","obj","__esModule","default","deps","setDeps","pkg","JSON","parse","readFileSync","join","process","cwd","Set","dependencies","Object","keys","devDependencies","error","console","log","moduleCheck","Map","_default","iterateJsdoc","jsdoc","settings","utils","undefined","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>|null}\n */\nlet deps;\n\nconst setDeps = function () {\n try {\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 // istanbul ignore next -- our package.json exists\n deps = null;\n /* eslint-disable no-console -- Inform user */\n // istanbul ignore next -- our package.json exists\n console.log(error);\n /* eslint-enable no-console -- Inform user */\n }\n};\n\nconst moduleCheck = new Map();\n\nexport default iterateJsdoc(({\n jsdoc,\n settings,\n utils,\n}) => {\n // istanbul ignore if\n if (deps === undefined) {\n setDeps();\n }\n\n // istanbul ignore if -- our package.json exists\n if (deps === null) {\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 // eslint-disable-next-line no-loop-func -- Safe\n traverse(typeAst, (nde) => {\n // istanbul ignore if -- TS guard\n if (deps === null) {\n return;\n }\n\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,IAAA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CAACV,GAAG,CAAC,EAAE;UACxBV,KAAK,CAACqB,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,CAAAnD,OAAA,GAAAoB,QAAA;AAAAgC,MAAA,CAAAD,OAAA,GAAAA,OAAA,CAAAnD,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.6"
|
|
139
140
|
}
|