Skip to content

Commit 5822816

Browse files
committed
fix(check-values, no-undefined-types): avoid need for worker; fixes gajus#1371
1 parent 771eadf commit 5822816

9 files changed

+63
-48
lines changed

docs/rules/no-undefined-types.md

+9
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,9 @@ quux();
822822
/**
823823
* @import LinterDef, { Sth as Something, Another as Another2 } from "eslint"
824824
*/
825+
/**
826+
* @import LinterDef2, * as LinterDef3 from "eslint"
827+
*/
825828
/**
826829
* @import { Linter } from "eslint"
827830
*/
@@ -838,6 +841,12 @@ quux();
838841
/**
839842
* @type {LinterDef}
840843
*/
844+
/**
845+
* @type {LinterDef2}
846+
*/
847+
/**
848+
* @type {LinterDef3}
849+
*/
841850
/**
842851
* @type {Something}
843852
*/

package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212
"escape-string-regexp": "^4.0.0",
1313
"espree": "^10.1.0",
1414
"esquery": "^1.6.0",
15-
"parse-imports": "^2.1.1",
15+
"parse-imports-exports": "^0.2.4",
1616
"semver": "^7.6.3",
17-
"spdx-expression-parse": "^4.0.0",
18-
"synckit": "^0.9.1"
17+
"spdx-expression-parse": "^4.0.0"
1918
},
2019
"description": "JSDoc linting rules for ESLint.",
2120
"devDependencies": {
@@ -146,7 +145,7 @@
146145
"scripts": {
147146
"tsc": "tsc",
148147
"tsc-build": "tsc -p tsconfig-prod.json",
149-
"build": "rimraf ./dist && cross-env NODE_ENV=production babel ./src --out-file-extension .cjs --out-dir ./dist --copy-files --source-maps --ignore ./src/bin/*.js --no-copy-ignored && replace 'require\\(\"\\.(.*?)\\.[^.]*?\"\\)' 'require(\".$1.cjs\")' 'dist' -r --include=\"*.cjs\" && cp src/import-worker.mjs dist/import-worker.mjs && pnpm tsc-build",
148+
"build": "rimraf ./dist && cross-env NODE_ENV=production babel ./src --out-file-extension .cjs --out-dir ./dist --copy-files --source-maps --ignore ./src/bin/*.js --no-copy-ignored && replace 'require\\(\"\\.(.*?)\\.[^.]*?\"\\)' 'require(\".$1.cjs\")' 'dist' -r --include=\"*.cjs\" && pnpm tsc-build",
150149
"check-docs": "babel-node ./src/bin/generateDocs.js --check",
151150
"create-docs": "npm run create-options && babel-node ./src/bin/generateDocs.js",
152151
"create-rule": "babel-node ./src/bin/generateRule.js",

pnpm-lock.yaml

+15-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ignoredBuiltDependencies:
2+
- core-js-pure

src/import-worker.mjs

-11
This file was deleted.

src/rules/checkValues.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { dirname, join } from 'node:path';
22
import { fileURLToPath } from 'node:url';
33

4-
import { createSyncFn } from 'synckit';
54
import semver from 'semver';
65
import spdxExpressionParse from 'spdx-expression-parse';
6+
import {parseImportsExports} from 'parse-imports-exports';
77
import iterateJsdoc from '../iterateJsdoc.js';
88

99
const __dirname = dirname(fileURLToPath(import.meta.url));
10-
const pathName = join(__dirname, '../import-worker.mjs');
1110

1211
const allowedKinds = new Set([
1312
'class',
@@ -175,8 +174,9 @@ export default iterateJsdoc(({
175174
? `${typePart}${name} ${description}`
176175
: `${typePart}${name}`);
177176

178-
const getImports = createSyncFn(pathName);
179-
if (!getImports(imprt)) {
177+
const importsExports = parseImportsExports(imprt);
178+
179+
if (importsExports.errors) {
180180
report(
181181
`Bad @import tag`,
182182
null,

src/rules/noUndefinedTypes.js

+20-21
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { dirname, join } from 'path';
22
import { fileURLToPath } from 'url';
33

4-
import { createSyncFn } from 'synckit';
4+
import {parseImportsExports} from 'parse-imports-exports';
55
import {
66
getJSDocComment,
77
parse as parseType,
@@ -13,7 +13,6 @@ import iterateJsdoc, {
1313
} from '../iterateJsdoc.js';
1414

1515
const __dirname = dirname(fileURLToPath(import.meta.url));
16-
const pathName = join(__dirname, '../import-worker.mjs');
1716

1817
const extraTypes = [
1918
'null', 'undefined', 'void', 'string', 'boolean', 'object',
@@ -152,30 +151,30 @@ export default iterateJsdoc(({
152151
? `${typePart}${name} ${description}`
153152
: `${typePart}${name}`);
154153

155-
const getImports = createSyncFn(pathName);
156-
const imports = /** @type {import('parse-imports').Import[]} */ (getImports(imprt));
157-
if (!imports) {
158-
return null;
159-
}
154+
const importsExports = parseImportsExports(imprt);
160155

161-
return imports.flatMap(({importClause}) => {
162-
/* c8 ignore next */
163-
const {default: dflt, named, namespace} = importClause || {};
164-
const types = [];
165-
if (dflt) {
166-
types.push(dflt);
156+
const types = [];
157+
const namedImports = Object.values(importsExports.namedImports || {})[0]?.[0];
158+
if (namedImports) {
159+
if (namedImports.default) {
160+
types.push(namedImports.default);
167161
}
168-
if (namespace) {
169-
types.push(namespace);
162+
if (namedImports.names) {
163+
types.push(...Object.keys(namedImports.names));
170164
}
171-
if (named) {
172-
for (const {binding} of named) {
173-
types.push(binding);
174-
}
165+
}
166+
167+
const namespaceImports = Object.values(importsExports.namespaceImports || {})[0]?.[0];
168+
if (namespaceImports) {
169+
if (namespaceImports.namespace) {
170+
types.push(namespaceImports.namespace);
175171
}
172+
if (namespaceImports.default) {
173+
types.push(namespaceImports.default);
174+
}
175+
}
176176

177-
return types;
178-
});
177+
return types;
179178
}).filter(Boolean)) : [];
180179

181180
const ancestorNodes = [];

test/rules/assertions/noUndefinedTypes.js

+9
Original file line numberDiff line numberDiff line change
@@ -1502,6 +1502,9 @@ export default /** @type {import('../index.js').TestCases} */ ({
15021502
/**
15031503
* @import LinterDef, { Sth as Something, Another as Another2 } from "eslint"
15041504
*/
1505+
/**
1506+
* @import LinterDef2, * as LinterDef3 from "eslint"
1507+
*/
15051508
/**
15061509
* @import { Linter } from "eslint"
15071510
*/
@@ -1518,6 +1521,12 @@ export default /** @type {import('../index.js').TestCases} */ ({
15181521
/**
15191522
* @type {LinterDef}
15201523
*/
1524+
/**
1525+
* @type {LinterDef2}
1526+
*/
1527+
/**
1528+
* @type {LinterDef3}
1529+
*/
15211530
/**
15221531
* @type {Something}
15231532
*/

tsconfig.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
"src/**/*.js",
1818
"test/**/*.js",
1919
"typings/gitdown.d.ts",
20-
"typings/babel__eslint-parser.d.ts",
21-
"src/import-worker.mjs"
20+
"typings/babel__eslint-parser.d.ts"
2221
],
2322
"exclude": ["node_modules"]
2423
}

0 commit comments

Comments
 (0)