eslint-plugin-jsdoc 46.2.5 → 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.
|
@@ -11,24 +11,28 @@ var _isBuiltinModule = _interopRequireDefault(require("is-builtin-module"));
|
|
|
11
11
|
var _path = require("path");
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
13
|
/**
|
|
14
|
-
* @type {Set<string
|
|
14
|
+
* @type {Set<string>|null}
|
|
15
15
|
*/
|
|
16
16
|
let deps;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
+
};
|
|
32
36
|
|
|
33
37
|
const moduleCheck = new Map();
|
|
34
38
|
var _default = (0, _iterateJsdoc.default)(({
|
|
@@ -37,7 +41,12 @@ var _default = (0, _iterateJsdoc.default)(({
|
|
|
37
41
|
utils
|
|
38
42
|
}) => {
|
|
39
43
|
// istanbul ignore if
|
|
40
|
-
if (
|
|
44
|
+
if (deps === undefined) {
|
|
45
|
+
setDeps();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// istanbul ignore if -- our package.json exists
|
|
49
|
+
if (deps === null) {
|
|
41
50
|
return;
|
|
42
51
|
}
|
|
43
52
|
const {
|
|
@@ -50,7 +59,13 @@ var _default = (0, _iterateJsdoc.default)(({
|
|
|
50
59
|
} catch {
|
|
51
60
|
continue;
|
|
52
61
|
}
|
|
62
|
+
|
|
63
|
+
// eslint-disable-next-line no-loop-func -- Safe
|
|
53
64
|
(0, _jsdoccomment.traverse)(typeAst, nde => {
|
|
65
|
+
// istanbul ignore if -- TS guard
|
|
66
|
+
if (deps === null) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
54
69
|
if (nde.type === 'JsdocTypeImport') {
|
|
55
70
|
let mod = nde.element.value.replace(/^(@[^/]+\/[^/]+|[^/]+).*$/u, '$1');
|
|
56
71
|
if (/^[./]/u.test(mod)) {
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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,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;AAER,MAAMC,OAAO,GAAG,SAAAA,CAAA,EAAY;EAC1B,IAAI;IACF,MAAMC,GAAG,GAAGC,IAAI,CAACC,KAAK;IACpB;IACA,IAAAC,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