From 8009e2c3be301b0c107660cddb19ac18e228d8c7 Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Fri, 9 Jun 2023 03:40:02 +0000 Subject: [PATCH] tools: update eslint-plugin-jsdoc Run a subset of `tools/dep_updaters/update-eslint.sh` to update `eslint-plugin-jsdoc` to get rid of a spurious ENOENT error when running the linter. PR-URL: https://github.com/nodejs/node/pull/48393 Fixes: https://github.com/nodejs/node/issues/48374 Reviewed-By: Debadree Chatterjee Reviewed-By: Luigi Pinca Reviewed-By: Mohammed Keyvanzadeh Reviewed-By: Antoine du Hamel Reviewed-By: Moshe Atlow --- .../builtin-modules/builtin-modules.json | 43 +++++++++++++ .../node_modules/builtin-modules/index.js | 11 ++++ .../node_modules/builtin-modules/license | 9 +++ .../node_modules/builtin-modules/package.json | 44 +++++++++++++ .../node_modules/builtin-modules/readme.md | 44 +++++++++++++ .../node_modules/builtin-modules/static.js | 2 + .../eslint-plugin-jsdoc/dist/generateRule.js | 8 ++- .../dist/rules/importsAsDependencies.js | 61 +++++++++++++------ .../eslint-plugin-jsdoc/package.json | 5 +- .../node_modules/is-builtin-module/index.js | 22 +++++++ .../node_modules/is-builtin-module/license | 9 +++ .../is-builtin-module/package.json | 47 ++++++++++++++ .../node_modules/is-builtin-module/readme.md | 47 ++++++++++++++ 13 files changed, 330 insertions(+), 22 deletions(-) create mode 100644 tools/node_modules/eslint/node_modules/builtin-modules/builtin-modules.json create mode 100644 tools/node_modules/eslint/node_modules/builtin-modules/index.js create mode 100644 tools/node_modules/eslint/node_modules/builtin-modules/license create mode 100644 tools/node_modules/eslint/node_modules/builtin-modules/package.json create mode 100644 tools/node_modules/eslint/node_modules/builtin-modules/readme.md create mode 100644 tools/node_modules/eslint/node_modules/builtin-modules/static.js create mode 100644 tools/node_modules/eslint/node_modules/is-builtin-module/index.js create mode 100644 tools/node_modules/eslint/node_modules/is-builtin-module/license create mode 100644 tools/node_modules/eslint/node_modules/is-builtin-module/package.json create mode 100644 tools/node_modules/eslint/node_modules/is-builtin-module/readme.md diff --git a/tools/node_modules/eslint/node_modules/builtin-modules/builtin-modules.json b/tools/node_modules/eslint/node_modules/builtin-modules/builtin-modules.json new file mode 100644 index 00000000000000..f2f4dbd50db0e5 --- /dev/null +++ b/tools/node_modules/eslint/node_modules/builtin-modules/builtin-modules.json @@ -0,0 +1,43 @@ +[ + "assert", + "async_hooks", + "buffer", + "child_process", + "cluster", + "console", + "constants", + "crypto", + "dgram", + "diagnostics_channel", + "dns", + "domain", + "events", + "fs", + "http", + "http2", + "https", + "inspector", + "module", + "net", + "os", + "path", + "perf_hooks", + "process", + "punycode", + "querystring", + "readline", + "repl", + "stream", + "string_decoder", + "timers", + "tls", + "trace_events", + "tty", + "url", + "util", + "v8", + "vm", + "wasi", + "worker_threads", + "zlib" +] diff --git a/tools/node_modules/eslint/node_modules/builtin-modules/index.js b/tools/node_modules/eslint/node_modules/builtin-modules/index.js new file mode 100644 index 00000000000000..8596b8da0dae2a --- /dev/null +++ b/tools/node_modules/eslint/node_modules/builtin-modules/index.js @@ -0,0 +1,11 @@ +'use strict'; +const {builtinModules} = require('module'); + +const ignoreList = [ + 'sys' +]; + +// eslint-disable-next-line node/no-deprecated-api +module.exports = (builtinModules || (process.binding ? Object.keys(process.binding('natives')) : []) || []) + .filter(x => !/^_|^(internal|v8|node-inspect)\/|\//.test(x) && !ignoreList.includes(x)) + .sort(); diff --git a/tools/node_modules/eslint/node_modules/builtin-modules/license b/tools/node_modules/eslint/node_modules/builtin-modules/license new file mode 100644 index 00000000000000..fa7ceba3eb4a96 --- /dev/null +++ b/tools/node_modules/eslint/node_modules/builtin-modules/license @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) Sindre Sorhus (https://sindresorhus.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/tools/node_modules/eslint/node_modules/builtin-modules/package.json b/tools/node_modules/eslint/node_modules/builtin-modules/package.json new file mode 100644 index 00000000000000..39ddc446b0f5dc --- /dev/null +++ b/tools/node_modules/eslint/node_modules/builtin-modules/package.json @@ -0,0 +1,44 @@ +{ + "name": "builtin-modules", + "version": "3.3.0", + "description": "List of the Node.js builtin modules", + "license": "MIT", + "repository": "sindresorhus/builtin-modules", + "funding": "https://github.com/sponsors/sindresorhus", + "author": { + "name": "Sindre Sorhus", + "email": "sindresorhus@gmail.com", + "url": "https://sindresorhus.com" + }, + "engines": { + "node": ">=6" + }, + "scripts": { + "test": "xo && ava && tsd", + "make": "node make.js" + }, + "files": [ + "index.js", + "index.d.ts", + "static.js", + "static.d.ts", + "builtin-modules.json" + ], + "keywords": [ + "builtin", + "built-in", + "builtins", + "node", + "modules", + "core", + "bundled", + "list", + "array", + "names" + ], + "devDependencies": { + "ava": "^1.4.1", + "tsd": "^0.7.2", + "xo": "^0.24.0" + } +} diff --git a/tools/node_modules/eslint/node_modules/builtin-modules/readme.md b/tools/node_modules/eslint/node_modules/builtin-modules/readme.md new file mode 100644 index 00000000000000..9126b64dc1c89f --- /dev/null +++ b/tools/node_modules/eslint/node_modules/builtin-modules/readme.md @@ -0,0 +1,44 @@ +# builtin-modules + +> List of the Node.js builtin modules + +The list is just a [JSON file](builtin-modules.json) and can be used anywhere. + +## Install + +``` +$ npm install builtin-modules +``` + +## Usage + +```js +const builtinModules = require('builtin-modules'); + +console.log(builtinModules); +//=> ['assert', 'buffer', ...] +``` + +## API + +Returns an array of builtin modules fetched from the running Node.js version. + +### Static list + +This module also comes bundled with a static array of builtin modules generated from the latest Node.js version. You can get it with `require('builtin-modules/static');` + +## Related + +- [is-builtin-module](https://github.com/sindresorhus/is-builtin-module) - Check if a string matches the name of a Node.js builtin module + +--- + +
+ + Get professional support for this package with a Tidelift subscription + +
+ + Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies. +
+
diff --git a/tools/node_modules/eslint/node_modules/builtin-modules/static.js b/tools/node_modules/eslint/node_modules/builtin-modules/static.js new file mode 100644 index 00000000000000..396628033d23f4 --- /dev/null +++ b/tools/node_modules/eslint/node_modules/builtin-modules/static.js @@ -0,0 +1,2 @@ +'use strict'; +module.exports = require('./builtin-modules'); diff --git a/tools/node_modules/eslint/node_modules/eslint-plugin-jsdoc/dist/generateRule.js b/tools/node_modules/eslint/node_modules/eslint-plugin-jsdoc/dist/generateRule.js index 5ee2d5f734160d..81de2b1f9cf2e3 100644 --- a/tools/node_modules/eslint/node_modules/eslint-plugin-jsdoc/dist/generateRule.js +++ b/tools/node_modules/eslint/node_modules/eslint-plugin-jsdoc/dist/generateRule.js @@ -103,7 +103,13 @@ export default iterateJsdoc(({ |Settings|| |Options|| - +## Failing examples + + + +## Passing examples + + `; const ruleReadmePath = `./.README/rules/${ruleName}.md`; if (!(0, _fs.existsSync)(ruleReadmePath)) { diff --git a/tools/node_modules/eslint/node_modules/eslint-plugin-jsdoc/dist/rules/importsAsDependencies.js b/tools/node_modules/eslint/node_modules/eslint-plugin-jsdoc/dist/rules/importsAsDependencies.js index a833e6979e6bb5..a06666f395df68 100644 --- a/tools/node_modules/eslint/node_modules/eslint-plugin-jsdoc/dist/rules/importsAsDependencies.js +++ b/tools/node_modules/eslint/node_modules/eslint-plugin-jsdoc/dist/rules/importsAsDependencies.js @@ -7,27 +7,32 @@ exports.default = void 0; var _iterateJsdoc = _interopRequireDefault(require("../iterateJsdoc")); var _jsdoccomment = require("@es-joy/jsdoccomment"); var _fs = require("fs"); +var _isBuiltinModule = _interopRequireDefault(require("is-builtin-module")); var _path = require("path"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** - * @type {Set} + * @type {Set|null} */ let deps; -try { - const pkg = JSON.parse( - // @ts-expect-error It's ok - (0, _fs.readFileSync)((0, _path.join)(process.cwd(), './package.json'))); - deps = new Set([...(pkg.dependencies ? Object.keys(pkg.dependencies) : - // istanbul ignore next - []), ...(pkg.devDependencies ? Object.keys(pkg.devDependencies) : - // istanbul ignore next - [])]); -} catch (error) { - /* eslint-disable no-console -- Inform user */ - // istanbul ignore next - console.log(error); - /* eslint-enable no-console -- Inform user */ -} +const setDeps = function () { + try { + const pkg = JSON.parse( + // @ts-expect-error It's ok + (0, _fs.readFileSync)((0, _path.join)(process.cwd(), './package.json'))); + deps = new Set([...(pkg.dependencies ? Object.keys(pkg.dependencies) : + // istanbul ignore next + []), ...(pkg.devDependencies ? Object.keys(pkg.devDependencies) : + // istanbul ignore next + [])]); + } catch (error) { + // istanbul ignore next -- our package.json exists + deps = null; + /* eslint-disable no-console -- Inform user */ + // istanbul ignore next -- our package.json exists + console.log(error); + /* eslint-enable no-console -- Inform user */ + } +}; const moduleCheck = new Map(); var _default = (0, _iterateJsdoc.default)(({ @@ -36,7 +41,12 @@ var _default = (0, _iterateJsdoc.default)(({ utils }) => { // istanbul ignore if - if (!deps) { + if (deps === undefined) { + setDeps(); + } + + // istanbul ignore if -- our package.json exists + if (deps === null) { return; } const { @@ -49,10 +59,23 @@ var _default = (0, _iterateJsdoc.default)(({ } catch { continue; } + + // eslint-disable-next-line no-loop-func -- Safe (0, _jsdoccomment.traverse)(typeAst, nde => { + // istanbul ignore if -- TS guard + if (deps === null) { + return; + } if (nde.type === 'JsdocTypeImport') { let mod = nde.element.value.replace(/^(@[^/]+\/[^/]+|[^/]+).*$/u, '$1'); - if (!moduleCheck.has(mod)) { + if (/^[./]/u.test(mod)) { + return; + } + if ((0, _isBuiltinModule.default)(mod)) { + // mod = '@types/node'; + // moduleCheck.set(mod, !deps.has(mod)); + return; + } else if (!moduleCheck.has(mod)) { let pkg; try { pkg = JSON.parse( @@ -61,7 +84,7 @@ var _default = (0, _iterateJsdoc.default)(({ } catch { // Ignore } - if (!pkg || !pkg.types) { + if (!pkg || !pkg.types && !pkg.typings) { mod = `@types/${mod}`; } moduleCheck.set(mod, !deps.has(mod)); diff --git a/tools/node_modules/eslint/node_modules/eslint-plugin-jsdoc/package.json b/tools/node_modules/eslint/node_modules/eslint-plugin-jsdoc/package.json index ab9374db4a3636..b0fff02d7e513c 100644 --- a/tools/node_modules/eslint/node_modules/eslint-plugin-jsdoc/package.json +++ b/tools/node_modules/eslint/node_modules/eslint-plugin-jsdoc/package.json @@ -11,6 +11,7 @@ "debug": "^4.3.4", "escape-string-regexp": "^4.0.0", "esquery": "^1.5.0", + "is-builtin-module": "^3.2.1", "semver": "^7.5.1", "spdx-expression-parse": "^3.0.1" }, @@ -37,7 +38,7 @@ "@types/estree": "^1.0.1", "@types/lodash.defaultsdeep": "^4.6.7", "@types/mocha": "^10.0.1", - "@types/node": "^20.2.3", + "@types/node": "^20.2.5", "@types/semver": "^7.5.0", "@types/spdx-expression-parse": "^3.0.2", "@typescript-eslint/parser": "^5.59.6", @@ -135,5 +136,5 @@ "test-cov": "cross-env TIMING=1 nyc --reporter text npm run test-no-cov", "test-index": "npm run test-no-cov -- test/rules/index.js" }, - "version": "46.2.1" + "version": "46.2.6" } diff --git a/tools/node_modules/eslint/node_modules/is-builtin-module/index.js b/tools/node_modules/eslint/node_modules/is-builtin-module/index.js new file mode 100644 index 00000000000000..e79a925c3d3d26 --- /dev/null +++ b/tools/node_modules/eslint/node_modules/is-builtin-module/index.js @@ -0,0 +1,22 @@ +'use strict'; +const builtinModules = require('builtin-modules'); + +const moduleSet = new Set(builtinModules); +const NODE_PROTOCOL = 'node:'; + +module.exports = moduleName => { + if (typeof moduleName !== 'string') { + throw new TypeError('Expected a string'); + } + + if (moduleName.startsWith(NODE_PROTOCOL)) { + moduleName = moduleName.slice(NODE_PROTOCOL.length); + } + + const slashIndex = moduleName.indexOf('/'); + if (slashIndex !== -1 && slashIndex !== moduleName.length - 1) { + moduleName = moduleName.slice(0, slashIndex); + } + + return moduleSet.has(moduleName); +}; diff --git a/tools/node_modules/eslint/node_modules/is-builtin-module/license b/tools/node_modules/eslint/node_modules/is-builtin-module/license new file mode 100644 index 00000000000000..e7af2f77107d73 --- /dev/null +++ b/tools/node_modules/eslint/node_modules/is-builtin-module/license @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) Sindre Sorhus (sindresorhus.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/tools/node_modules/eslint/node_modules/is-builtin-module/package.json b/tools/node_modules/eslint/node_modules/is-builtin-module/package.json new file mode 100644 index 00000000000000..866e5baffdf205 --- /dev/null +++ b/tools/node_modules/eslint/node_modules/is-builtin-module/package.json @@ -0,0 +1,47 @@ +{ + "name": "is-builtin-module", + "version": "3.2.1", + "description": "Check if a string matches the name of a Node.js builtin module", + "license": "MIT", + "repository": "sindresorhus/is-builtin-module", + "funding": "https://github.com/sponsors/sindresorhus", + "author": { + "name": "Sindre Sorhus", + "email": "sindresorhus@gmail.com", + "url": "https://sindresorhus.com" + }, + "engines": { + "node": ">=6" + }, + "scripts": { + "test": "xo && ava && tsd" + }, + "files": [ + "index.js", + "index.d.ts" + ], + "keywords": [ + "builtin", + "built-in", + "builtins", + "node", + "modules", + "core", + "bundled", + "list", + "array", + "names", + "is", + "detect", + "check", + "match" + ], + "dependencies": { + "builtin-modules": "^3.3.0" + }, + "devDependencies": { + "ava": "^0.25.0", + "tsd": "^0.7.2", + "xo": "^0.23.0" + } +} diff --git a/tools/node_modules/eslint/node_modules/is-builtin-module/readme.md b/tools/node_modules/eslint/node_modules/is-builtin-module/readme.md new file mode 100644 index 00000000000000..8304ebdf022d6f --- /dev/null +++ b/tools/node_modules/eslint/node_modules/is-builtin-module/readme.md @@ -0,0 +1,47 @@ +# is-builtin-module + +> Check if a string matches the name of a Node.js builtin module + + +## Install + +``` +$ npm install is-builtin-module +``` + + +## Usage + +```js +const isBuiltinModule = require('is-builtin-module'); + +isBuiltinModule('fs'); +//=> true + +isBuiltinModule('fs/promises'); +//=> true + +isBuiltinModule('node:fs/promises'); +//=> true + +isBuiltinModule('unicorn'); +//=> false +``` + + +## Related + +- [builtin-modules](https://github.com/sindresorhus/builtin-modules) - List of the Node.js builtin modules + + +--- + +
+ + Get professional support for this package with a Tidelift subscription + +
+ + Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies. +
+