From 8c55bbbe12d19920c47638865b3136724156d6a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Pires?= Date: Fri, 21 Jul 2023 02:46:02 +0100 Subject: [PATCH 01/44] refactor --- docs/description/description.json | 471 +++++++++++++++-- docs/description/n_callback-return.md | 165 ++++++ docs/description/n_exports-style.md | 115 +++++ .../description/n_file-extension-in-import.md | 96 ++++ docs/description/n_global-require.md | 92 ++++ docs/description/n_handle-callback-err.md | 78 +++ docs/description/n_no-callback-literal.md | 35 ++ docs/description/n_no-deprecated-api.md | 371 ++++++++++++++ docs/description/n_no-exports-assign.md | 47 ++ docs/description/n_no-extraneous-import.md | 84 +++ docs/description/n_no-extraneous-require.md | 94 ++++ docs/description/n_no-hide-core-modules.md | 69 +++ docs/description/n_no-missing-import.md | 98 ++++ docs/description/n_no-missing-require.md | 113 +++++ docs/description/n_no-mixed-requires.md | 122 +++++ docs/description/n_no-new-require.md | 49 ++ docs/description/n_no-path-concat.md | 58 +++ docs/description/n_no-process-env.md | 36 ++ docs/description/n_no-process-exit.md | 53 ++ docs/description/n_no-restricted-import.md | 117 +++++ docs/description/n_no-restricted-require.md | 124 +++++ docs/description/n_no-sync.md | 62 +++ docs/description/n_no-unpublished-bin.md | 117 +++++ docs/description/n_no-unpublished-import.md | 160 ++++++ docs/description/n_no-unpublished-require.md | 150 ++++++ docs/description/n_no-unsupported-features.md | 308 +++++++++++ .../n_no-unsupported-features_es-builtins.md | 167 ++++++ .../n_no-unsupported-features_es-syntax.md | 140 +++++ ...n_no-unsupported-features_node-builtins.md | 351 +++++++++++++ docs/description/n_prefer-global_buffer.md | 71 +++ docs/description/n_prefer-global_console.md | 71 +++ docs/description/n_prefer-global_process.md | 71 +++ .../n_prefer-global_text-decoder.md | 71 +++ .../n_prefer-global_text-encoder.md | 71 +++ .../n_prefer-global_url-search-params.md | 71 +++ docs/description/n_prefer-global_url.md | 71 +++ docs/description/n_prefer-promises_dns.md | 61 +++ docs/description/n_prefer-promises_fs.md | 61 +++ docs/description/n_process-exit-as-throw.md | 38 ++ docs/description/n_shebang.md | 148 ++++++ .../all-patterns-typescript/patterns.xml | 65 ++- docs/multiple-tests/all-patterns/patterns.xml | 65 ++- docs/patterns.json | 477 ++++++++++++++++-- package-lock.json | 229 +++++---- package.json | 30 +- src/docGeneratorMain.ts | 62 +-- src/eslintDefaultOptions.ts | 142 ++++-- src/eslintPlugins.ts | 6 +- 48 files changed, 5528 insertions(+), 295 deletions(-) create mode 100644 docs/description/n_callback-return.md create mode 100644 docs/description/n_exports-style.md create mode 100644 docs/description/n_file-extension-in-import.md create mode 100644 docs/description/n_global-require.md create mode 100644 docs/description/n_handle-callback-err.md create mode 100644 docs/description/n_no-callback-literal.md create mode 100644 docs/description/n_no-deprecated-api.md create mode 100644 docs/description/n_no-exports-assign.md create mode 100644 docs/description/n_no-extraneous-import.md create mode 100644 docs/description/n_no-extraneous-require.md create mode 100644 docs/description/n_no-hide-core-modules.md create mode 100644 docs/description/n_no-missing-import.md create mode 100644 docs/description/n_no-missing-require.md create mode 100644 docs/description/n_no-mixed-requires.md create mode 100644 docs/description/n_no-new-require.md create mode 100644 docs/description/n_no-path-concat.md create mode 100644 docs/description/n_no-process-env.md create mode 100644 docs/description/n_no-process-exit.md create mode 100644 docs/description/n_no-restricted-import.md create mode 100644 docs/description/n_no-restricted-require.md create mode 100644 docs/description/n_no-sync.md create mode 100644 docs/description/n_no-unpublished-bin.md create mode 100644 docs/description/n_no-unpublished-import.md create mode 100644 docs/description/n_no-unpublished-require.md create mode 100644 docs/description/n_no-unsupported-features.md create mode 100644 docs/description/n_no-unsupported-features_es-builtins.md create mode 100644 docs/description/n_no-unsupported-features_es-syntax.md create mode 100644 docs/description/n_no-unsupported-features_node-builtins.md create mode 100644 docs/description/n_prefer-global_buffer.md create mode 100644 docs/description/n_prefer-global_console.md create mode 100644 docs/description/n_prefer-global_process.md create mode 100644 docs/description/n_prefer-global_text-decoder.md create mode 100644 docs/description/n_prefer-global_text-encoder.md create mode 100644 docs/description/n_prefer-global_url-search-params.md create mode 100644 docs/description/n_prefer-global_url.md create mode 100644 docs/description/n_prefer-promises_dns.md create mode 100644 docs/description/n_prefer-promises_fs.md create mode 100644 docs/description/n_process-exit-as-throw.md create mode 100644 docs/description/n_shebang.md diff --git a/docs/description/description.json b/docs/description/description.json index ec0f1993e..6d7b5d7fa 100644 --- a/docs/description/description.json +++ b/docs/description/description.json @@ -3094,6 +3094,13 @@ "description": "Ensures component's `changeDetection` is set to `ChangeDetectionStrategy.OnPush`", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "@angular-eslint_prefer-standalone-component", + "title": "@angular eslint: Prefer standalone component", + "description": "Ensures component `standalone` property is set to `true` in the component decorator", + "timeToFix": 5 + }, { "parameters": [], "patternId": "@angular-eslint_prefer-output-readonly", @@ -3877,18 +3884,6 @@ "description": "Disallow duplicate enum member values", "timeToFix": 5 }, - { - "parameters": [ - { - "name": "includeExports", - "description": "includeExports" - } - ], - "patternId": "@typescript-eslint_no-duplicate-imports", - "title": "@typescript eslint: No duplicate imports", - "description": "Disallow duplicate imports", - "timeToFix": 5 - }, { "parameters": [], "patternId": "@typescript-eslint_no-duplicate-type-constituents", @@ -3966,13 +3961,6 @@ "description": "Disallow iterating over an array with a for-in loop", "timeToFix": 5 }, - { - "parameters": [], - "patternId": "@typescript-eslint_no-implicit-any-catch", - "title": "@typescript eslint: No implicit any catch", - "description": "Disallow usage of the implicit `any` type in catch clauses", - "timeToFix": 5 - }, { "parameters": [], "patternId": "@typescript-eslint_no-implied-eval", @@ -4403,7 +4391,7 @@ "parameters": [], "patternId": "@typescript-eslint_prefer-nullish-coalescing", "title": "@typescript eslint: Prefer nullish coalescing", - "description": "Enforce using the nullish coalescing operator instead of logical chaining", + "description": "Enforce using the nullish coalescing operator instead of logical assignments or chaining", "timeToFix": 5 }, { @@ -4525,13 +4513,6 @@ "description": "Enforce constituents of a type union/intersection to be sorted alphabetically", "timeToFix": 5 }, - { - "parameters": [], - "patternId": "@typescript-eslint_sort-type-union-intersection-members", - "title": "@typescript eslint: Sort type union intersection members", - "description": "Enforce members of a type union/intersection to be sorted alphabetically", - "timeToFix": 5 - }, { "parameters": [], "patternId": "@typescript-eslint_space-before-blocks", @@ -5088,6 +5069,132 @@ "description": "Styles are sorted alphabetically.", "timeToFix": 5 }, + { + "parameters": [ + { + "name": "allowAllPropertiesOnSameLine", + "description": "allowAllPropertiesOnSameLine" + } + ], + "patternId": "canonical_destructuring-property-newline", + "title": "Canonical: Destructuring property newline", + "description": "Like `object-property-newline`, but for destructuring.", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "canonical_export-specifier-newline", + "title": "Canonical: Export specifier newline", + "description": "Forces every export specifier to be on a new line.", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "canonical_filename-match-exported", + "title": "Canonical: Filename match exported", + "description": "Match the file name against the default exported value in the module.", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "canonical_filename-match-regex", + "title": "Canonical: Filename match regex", + "description": "Enforce a certain file naming convention using a regular expression.", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "canonical_filename-no-index", + "title": "Canonical: Filename no index", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "canonical_import-specifier-newline", + "title": "Canonical: Import specifier newline", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "canonical_no-barrel-import", + "title": "Canonical: No barrel import", + "description": "Require that imports are made directly from the source", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "canonical_no-reassign-imports", + "title": "Canonical: No reassign imports", + "description": "Restricts re-assigning imports to variables that are exported.", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "canonical_no-restricted-strings", + "title": "Canonical: No restricted strings", + "description": "Disallowed string.", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "canonical_no-unused-exports", + "title": "Canonical: No unused exports", + "description": "Identifies unused exports.", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "canonical_no-use-extend-native", + "title": "Canonical: No use extend native", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "canonical_prefer-import-alias", + "title": "Canonical: Prefer import alias", + "description": "Restrict imports to path aliases or relative imports limited by depth.", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "canonical_prefer-inline-type-import", + "title": "Canonical: Prefer inline type import", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "canonical_prefer-react-lazy", + "title": "Canonical: Prefer react lazy", + "description": "Require that useMount(() => {}) is used instead of useEffect(() => {}, [])", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "canonical_prefer-use-mount", + "title": "Canonical: Prefer use mount", + "description": "Require that useMount(() => {}) is used instead of useEffect(() => {}, [])", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "canonical_require-extension", + "title": "Canonical: Require extension", + "description": "Require file extension in import and export statements", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "canonical_sort-keys", + "title": "Canonical: Sort keys", + "description": "Require object keys to be sorted", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "canonical_virtual-module", + "title": "Canonical: Virtual module", + "timeToFix": 5 + }, { "parameters": [], "patternId": "chai-expect_no-inner-compare", @@ -7442,7 +7549,7 @@ "parameters": [], "patternId": "eslint-plugin_prefer-message-ids", "title": "Eslint plugin: Prefer message ids", - "description": "Require using `messageId` instead of `message` to report rule violations", + "description": "Require using `messageId` instead of `message` or `desc` to report rule violations", "timeToFix": 5 }, { @@ -11277,6 +11384,289 @@ "title": "Monorepo: No relative import", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "n_callback-return", + "title": "N: Callback return", + "description": "Require `return` statements after callbacks", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_exports-style", + "title": "N: Exports style", + "description": "Enforce either `module.exports` or `exports`", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_file-extension-in-import", + "title": "N: File extension in import", + "description": "Enforce the style of file extensions in `import` declarations", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_global-require", + "title": "N: Global require", + "description": "Require `require()` calls to be placed at top-level module scope", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_handle-callback-err", + "title": "N: Handle callback err", + "description": "Require error handling in callbacks", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_no-callback-literal", + "title": "N: No callback literal", + "description": "Enforce Node.js-style error-first callback pattern is followed", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_no-deprecated-api", + "title": "N: No deprecated api", + "description": "Disallow deprecated APIs", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_no-exports-assign", + "title": "N: No exports assign", + "description": "Disallow the assignment to `exports`", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_no-extraneous-import", + "title": "N: No extraneous import", + "description": "Disallow `import` declarations which import extraneous modules", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_no-extraneous-require", + "title": "N: No extraneous require", + "description": "Disallow `require()` expressions which import extraneous modules", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_no-missing-import", + "title": "N: No missing import", + "description": "Disallow `import` declarations which import non-existence modules", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_no-missing-require", + "title": "N: No missing require", + "description": "Disallow `require()` expressions which import non-existence modules", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_no-mixed-requires", + "title": "N: No mixed requires", + "description": "Disallow `require` calls to be mixed with regular variable declarations", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_no-new-require", + "title": "N: No new require", + "description": "Disallow `new` operators with calls to `require`", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_no-path-concat", + "title": "N: No path concat", + "description": "Disallow string concatenation with `__dirname` and `__filename`", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_no-process-env", + "title": "N: No process env", + "description": "Disallow the use of `process.env`", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_no-process-exit", + "title": "N: No process exit", + "description": "Disallow the use of `process.exit()`", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_no-restricted-import", + "title": "N: No restricted import", + "description": "Disallow specified modules when loaded by `import` declarations", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_no-restricted-require", + "title": "N: No restricted require", + "description": "Disallow specified modules when loaded by `require`", + "timeToFix": 5 + }, + { + "parameters": [ + { + "name": "allowAtRootLevel", + "description": "allowAtRootLevel" + } + ], + "patternId": "n_no-sync", + "title": "N: No sync", + "description": "Disallow synchronous methods", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_no-unpublished-bin", + "title": "N: No unpublished bin", + "description": "Disallow `bin` files that npm ignores", + "timeToFix": 5 + }, + { + "parameters": [ + { + "name": "ignoreTypeImport", + "description": "ignoreTypeImport" + } + ], + "patternId": "n_no-unpublished-import", + "title": "N: No unpublished import", + "description": "Disallow `import` declarations which import private modules", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_no-unpublished-require", + "title": "N: No unpublished require", + "description": "Disallow `require()` expressions which import private modules", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_no-unsupported-features_es-builtins", + "title": "N: [No unsupported features] Es builtins", + "description": "Disallow unsupported ECMAScript built-ins on the specified version", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_no-unsupported-features_es-syntax", + "title": "N: [No unsupported features] Es syntax", + "description": "Disallow unsupported ECMAScript syntax on the specified version", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_no-unsupported-features_node-builtins", + "title": "N: [No unsupported features] Node builtins", + "description": "Disallow unsupported Node.js built-in APIs on the specified version", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_prefer-global_buffer", + "title": "N: [Prefer global] Buffer", + "description": "Enforce either `Buffer` or `require(\"buffer\").Buffer`", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_prefer-global_console", + "title": "N: [Prefer global] Console", + "description": "Enforce either `console` or `require(\"console\")`", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_prefer-global_process", + "title": "N: [Prefer global] Process", + "description": "Enforce either `process` or `require(\"process\")`", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_prefer-global_text-decoder", + "title": "N: [Prefer global] Text decoder", + "description": "Enforce either `TextDecoder` or `require(\"util\").TextDecoder`", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_prefer-global_text-encoder", + "title": "N: [Prefer global] Text encoder", + "description": "Enforce either `TextEncoder` or `require(\"util\").TextEncoder`", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_prefer-global_url-search-params", + "title": "N: [Prefer global] Url search params", + "description": "Enforce either `URLSearchParams` or `require(\"url\").URLSearchParams`", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_prefer-global_url", + "title": "N: [Prefer global] Url", + "description": "Enforce either `URL` or `require(\"url\").URL`", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_prefer-promises_dns", + "title": "N: [Prefer promises] Dns", + "description": "Enforce `require(\"dns\").promises`", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_prefer-promises_fs", + "title": "N: [Prefer promises] Fs", + "description": "Enforce `require(\"fs\").promises`", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_process-exit-as-throw", + "title": "N: Process exit as throw", + "description": "Require that `process.exit()` expressions use the same code path as `throw`", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_shebang", + "title": "N: Shebang", + "description": "Require correct usage of shebang", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_no-hide-core-modules", + "title": "N: No hide core modules", + "description": "Disallow third-party modules which are hiding core modules", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "n_no-unsupported-features", + "title": "N: No unsupported features", + "description": "Disallow unsupported ECMAScript features on the specified version", + "timeToFix": 5 + }, { "parameters": [ { @@ -13461,12 +13851,6 @@ "title": "Scanjs rules: Assign_to_src", "timeToFix": 5 }, - { - "parameters": [], - "patternId": "scanjs-rules_call__Function", - "title": "Scanjs rules: Call_Function", - "timeToFix": 5 - }, { "parameters": [], "patternId": "scanjs-rules_call__addEventListener", @@ -13503,6 +13887,12 @@ "title": "Scanjs rules: Call_execScript", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "scanjs-rules_call__Function", + "title": "Scanjs rules: Call_Function", + "timeToFix": 5 + }, { "parameters": [], "patternId": "scanjs-rules_call__hide", @@ -14592,13 +14982,6 @@ "description": "Disallow unreadable IIFEs.", "timeToFix": 5 }, - { - "parameters": [], - "patternId": "unicorn_no-unsafe-regex", - "title": "Unicorn: No unsafe regex", - "description": "Disallow unsafe regular expressions.", - "timeToFix": 5 - }, { "parameters": [], "patternId": "unicorn_no-unused-properties", @@ -14744,6 +15127,12 @@ "description": "Require `new` when throwing an error.", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "unicorn_no-unsafe-regex", + "title": "Unicorn: No unsafe regex", + "timeToFix": 5 + }, { "parameters": [], "patternId": "unused-imports_no-unused-vars", diff --git a/docs/description/n_callback-return.md b/docs/description/n_callback-return.md new file mode 100644 index 000000000..4b91f61ca --- /dev/null +++ b/docs/description/n_callback-return.md @@ -0,0 +1,165 @@ +# Require `return` statements after callbacks (`n/callback-return`) + + + +The callback pattern is at the heart of most I/O and event-driven programming + in JavaScript. + +```js +function doSomething(err, callback) { + if (err) { + return callback(err); + } + callback(); +} +``` + +To prevent calling the callback multiple times it is important to `return` anytime the callback is triggered outside + of the main function body. Neglecting this technique often leads to issues where you do something more than once. + For example, in the case of an HTTP request, you may try to send HTTP headers more than once leading Node.js to `throw` + a `Can't render headers after they are sent to the client.` error. + +## 📖 Rule Details + +This rule is aimed at ensuring that callbacks used outside of the main function block are always part-of or immediately +preceding a `return` statement. This rule decides what is a callback based on the name of the function being called. + +### Options + +The rule takes a single option - an array of possible callback names - which may include object methods. The default callback names are `callback`, `cb`, `next`. + +#### Default callback names + +Examples of **incorrect** code for this rule with the default `["callback", "cb", "next"]` option: + +```js +/*eslint n/callback-return: "error"*/ + +function foo(err, callback) { + if (err) { + callback(err); + } + callback(); +} +``` + +Examples of **correct** code for this rule with the default `["callback", "cb", "next"]` option: + +```js +/*eslint n/callback-return: "error"*/ + +function foo(err, callback) { + if (err) { + return callback(err); + } + callback(); +} +``` + +#### Supplied callback names + +Examples of **incorrect** code for this rule with the option `["done", "send.error", "send.success"]`: + +```js +/*eslint n/callback-return: ["error", ["done", "send.error", "send.success"]]*/ + +function foo(err, done) { + if (err) { + done(err); + } + done(); +} + +function bar(err, send) { + if (err) { + send.error(err); + } + send.success(); +} +``` + +Examples of **correct** code for this rule with the option `["done", "send.error", "send.success"]`: + +```js +/*eslint callback-return: ["error", ["done", "send.error", "send.success"]]*/ + +function foo(err, done) { + if (err) { + return done(err); + } + done(); +} + +function bar(err, send) { + if (err) { + return send.error(err); + } + send.success(); +} +``` + +### Known Limitations + +Because it is difficult to understand the meaning of a program through static analysis, this rule has limitations: + +- *false negatives* when this rule reports correct code, but the program calls the callback more than one time (which is incorrect behavior) +- *false positives* when this rule reports incorrect code, but the program calls the callback only one time (which is correct behavior) + +#### Passing the callback by reference + +The static analysis of this rule does not detect that the program calls the callback if it is an argument of a function (for example, `setTimeout`). + +Example of a *false negative* when this rule reports correct code: + +```js +/*eslint callback-return: "error"*/ + +function foo(err, callback) { + if (err) { + setTimeout(callback, 0); // this is bad, but WILL NOT warn + } + callback(); +} +``` + +#### Triggering the callback within a nested function + +The static analysis of this rule does not detect that the program calls the callback from within a nested function or an immediately-invoked function expression (IIFE). + +Example of a *false negative* when this rule reports correct code: + +```js +/*eslint callback-return: "error"*/ + +function foo(err, callback) { + if (err) { + process.nextTick(function() { + return callback(); // this is bad, but WILL NOT warn + }); + } + callback(); +} +``` + +#### If/else statements + +The static analysis of this rule does not detect that the program calls the callback only one time in each branch of an `if` statement. + +Example of a *false positive* when this rule reports incorrect code: + +```js +/*eslint callback-return: "error"*/ + +function foo(err, callback) { + if (err) { + callback(err); // this is fine, but WILL warn + } else { + callback(); // this is fine, but WILL warn + } +} +``` + +## 🔎 Implementation + +- [Rule source](../../lib/rules/callback-return.js) +- [Test source](../../tests/lib/rules/callback-return.js) diff --git a/docs/description/n_exports-style.md b/docs/description/n_exports-style.md new file mode 100644 index 000000000..2cec56e61 --- /dev/null +++ b/docs/description/n_exports-style.md @@ -0,0 +1,115 @@ +# Enforce either `module.exports` or `exports` (`n/exports-style`) + +🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + +`module.exports` and `exports` are the same instance by default. +But those come to be different if one of them is modified. + +```js +module.exports = { + foo: 1 +} + +exports.bar = 2 +``` + +In this case, `exports.bar` will be lost since only the instance of `module.exports` will be exported. + +## 📖 Rule Details + +This rule enforces the export style. + +If you use `module.exports`, this rule disallows `exports`.\ +If you use `exports`, this rule disallows `module.exports`. + +You can select it by an option. + +### Options + +This rule has a string option. + +```json +{ + "n/exports-style": [ + "error", + "module.exports" or "exports", + { + "allowBatchAssign": false + } + ] +} +``` + +- `"module.exports"` (default) requires `module.exports` and disallows `exports`. +- `"exports"` requires `exports` and disallows `module.exports`. +- `allowBatchAssign` (default is `false`) allows `module.exports = exports = obj` if this is `true`. + +#### module.exports + +Examples of 👎 **incorrect** code for the `"module.exports"` option: + +```js +/*eslint n/exports-style: ["error", "module.exports"]*/ + +exports.foo = 1 +exports.bar = 2 +``` + +Examples of 👍 **correct** code for the `"module.exports"` option: + +```js +/*eslint n/exports-style: ["error", "module.exports"]*/ + +module.exports = { + foo: 1, + bar: 2 +} + +module.exports.baz = 3 +``` + +#### exports + +Examples of 👎 **incorrect** code for the `"exports"` option: + +```js +/*eslint n/exports-style: ["error", "exports"]*/ + +module.exports = { + foo: 1, + bar: 2 +} + +module.exports.baz = 3 +``` + +Examples of 👍 **correct** code for the `"exports"` option: + +```js +/*eslint n/exports-style: ["error", "exports"]*/ + +exports.foo = 1 +exports.bar = 2 +``` + +#### allowBatchAssign + +Examples of 👍 **correct** code for the `"exports"` and `{"allowBatchAssign": true}` option: + +```js +/*eslint n/exports-style: ["error", "exports", {"allowBatchAssign": true}]*/ + +// Allow `module.exports` in the same assignment expression as `exports`. +module.exports = exports = function foo() { + // do something. +} + +exports.bar = 1 +``` + +## 🔎 Implementation + +- [Rule source](../../lib/rules/exports-style.js) +- [Test source](../../tests/lib/rules/exports-style.js) diff --git a/docs/description/n_file-extension-in-import.md b/docs/description/n_file-extension-in-import.md new file mode 100644 index 000000000..031c27775 --- /dev/null +++ b/docs/description/n_file-extension-in-import.md @@ -0,0 +1,96 @@ +# Enforce the style of file extensions in `import` declarations (`n/file-extension-in-import`) + +🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + +We can omit file extensions in `import`/`export` declarations. + +```js +import foo from "./path/to/a/file" // maybe it's resolved to 'file.js' or 'file.json' +export * from "./path/to/a/file" +``` + +However, [--experimental-modules](https://medium.com/@nodejs/announcing-a-new-experimental-modules-1be8d2d6c2ff) has declared to drop the file extension omition. + +Also, we can import a variety kind of files with bundlers such as Webpack. In the situation, probably explicit file extensions help us to understand code. + +## 📖 Rule Details + +This rule enforces the style of file extensions in `import`/`export` declarations. + +### Options + +This rule has a string option and an object option. + +```json +{ + "n/file-extension-in-import": [ + "error", + "always" or "never", + { + ".xxx": "always" or "never", + } + ] +} +``` + +- `"always"` (default) requires file extensions in `import`/`export` declarations. +- `"never"` disallows file extensions in `import`/`export` declarations. +- `.xxx` is the overriding setting for specific file extensions. You can use arbitrary property names which start with `.`. + +#### always + +Examples of 👎 **incorrect** code for the `"always"` option: + +```js +/*eslint n/file-extension-in-import: ["error", "always"]*/ + +import foo from "./path/to/a/file" +``` + +Examples of 👍 **correct** code for the `"always"` option: + +```js +/*eslint n/file-extension-in-import: ["error", "always"]*/ + +import eslint from "eslint" +import foo from "./path/to/a/file.js" +``` + +#### never + +Examples of 👎 **incorrect** code for the `"never"` option: + +```js +/*eslint n/file-extension-in-import: ["error", "never"]*/ + +import foo from "./path/to/a/file.js" +``` + +Examples of 👍 **correct** code for the `"never"` option: + +```js +/*eslint n/file-extension-in-import: ["error", "never"]*/ + +import eslint from "eslint" +import foo from "./path/to/a/file" +``` + +#### .xxx + +Examples of 👍 **correct** code for the `["always", { ".js": "never" }]` option: + +```js +/*eslint n/file-extension-in-import: ["error", "always", { ".js": "never" }]*/ + +import eslint from "eslint" +import script from "./script" +import styles from "./styles.css" +import logo from "./logo.png" +``` + +## 🔎 Implementation + +- [Rule source](../../lib/rules/file-extension-in-import.js) +- [Test source](../../tests/lib/rules/file-extension-in-import.js) diff --git a/docs/description/n_global-require.md b/docs/description/n_global-require.md new file mode 100644 index 000000000..ff9696786 --- /dev/null +++ b/docs/description/n_global-require.md @@ -0,0 +1,92 @@ +# Require `require()` calls to be placed at top-level module scope (`n/global-require`) + + + +In Node.js, module dependencies are included using the `require()` function, such as: + +```js +var fs = require("fs"); +``` + +While `require()` may be called anywhere in code, some style guides prescribe that it should be called only in the top level of a module to make it easier to identify dependencies. For instance, it's arguably harder to identify dependencies when they are deeply nested inside of functions and other statements: + +```js +function foo() { + + if (condition) { + var fs = require("fs"); + } +} +``` + +Since `require()` does a synchronous load, it can cause performance problems when used in other locations. + +Further, ES6 modules mandate that `import` and `export` statements can only occur in the top level of the module's body. + +## 📖 Rule Details + +This rule requires all calls to `require()` to be at the top level of the module, similar to ES6 `import` and `export` statements, which also can occur only at the top level. + +Examples of **incorrect** code for this rule: + +```js +/*eslint n/global-require: "error"*/ +/*eslint-env es6*/ + +// calling require() inside of a function is not allowed +function readFile(filename, callback) { + var fs = require('fs'); + fs.readFile(filename, callback) +} + +// conditional requires like this are also not allowed +if (DEBUG) { require('debug'); } + +// a require() in a switch statement is also flagged +switch(x) { case '1': require('1'); break; } + +// you may not require() inside an arrow function body +var getModule = (name) => require(name); + +// you may not require() inside of a function body as well +function getModule(name) { return require(name); } + +// you may not require() inside of a try/catch block +try { + require(unsafeModule); +} catch(e) { + console.log(e); +} +``` + +Examples of **correct** code for this rule: + +```js +/*eslint n/global-require: "error"*/ + +// all these variations of require() are ok +require('x'); +var y = require('y'); +var z; +z = require('z').initialize(); + +// requiring a module and using it in a function is ok +var fs = require('fs'); +function readFile(filename, callback) { + fs.readFile(filename, callback) +} + +// you can use a ternary to determine which module to require +var logger = DEBUG ? require('dev-logger') : require('logger'); + +// if you want you can require() at the end of your module +function doSomethingA() {} +function doSomethingB() {} +var x = require("x"), + z = require("z"); +``` + +## 🔎 Implementation + +- [Rule source](../../lib/rules/global-require.js) +- [Test source](../../tests/lib/rules/global-require.js) diff --git a/docs/description/n_handle-callback-err.md b/docs/description/n_handle-callback-err.md new file mode 100644 index 000000000..b30b45fc9 --- /dev/null +++ b/docs/description/n_handle-callback-err.md @@ -0,0 +1,78 @@ +# Require error handling in callbacks (`n/handle-callback-err`) + + + +In Node.js, a common pattern for dealing with asynchronous behavior is called the callback pattern. +This pattern expects an `Error` object or `null` as the first argument of the callback. +Forgetting to handle these errors can lead to some really strange behavior in your application. + +```js +function loadData (err, data) { + doSomething(); // forgot to handle error +} +``` + +## 📖 Rule Details + +This rule expects that when you're using the callback pattern in Node.js you'll handle the error. + +### Options + +The rule takes a single string option: the name of the error parameter. The default is `"err"`. + +Examples of **incorrect** code for this rule with the default `"err"` parameter name: + +```js +/*eslint n/handle-callback-err: "error"*/ + +function loadData (err, data) { + doSomething(); +} + +``` + +Examples of **correct** code for this rule with the default `"err"` parameter name: + +```js +/*eslint n/handle-callback-err: "error"*/ + +function loadData (err, data) { + if (err) { + console.log(err.stack); + } + doSomething(); +} + +function generateError (err) { + if (err) {} +} +``` + +Examples of **correct** code for this rule with a sample `"error"` parameter name: + +```js +/*eslint n/handle-callback-err: ["error", "error"]*/ + +function loadData (error, data) { + if (error) { + console.log(error.stack); + } + doSomething(); +} +``` + +#### Regular Expression + +Sometimes (especially in big projects) the name of the error variable is not consistent across the project, +so you need a more flexible configuration to ensure that the rule reports all unhandled errors. + +If the configured name of the error variable begins with a `^` it is considered to be a regexp pattern. + +- If the option is `"^(err|error|anySpecificError)$"`, the rule reports unhandled errors where the parameter name can be `err`, `error` or `anySpecificError`. +- If the option is `"^.+Error$"`, the rule reports unhandled errors where the parameter name ends with `Error` (for example, `connectionError` or `validationError` will match). +- If the option is `"^.*(e|E)rr"`, the rule reports unhandled errors where the parameter name matches any string that contains `err` or `Err` (for example, `err`, `error`, `anyError`, `some_err` will match). + +## 🔎 Implementation + +- [Rule source](../../lib/rules/handle-callback-err.js) +- [Test source](../../tests/lib/rules/handle-callback-err.js) diff --git a/docs/description/n_no-callback-literal.md b/docs/description/n_no-callback-literal.md new file mode 100644 index 000000000..3515ba8fe --- /dev/null +++ b/docs/description/n_no-callback-literal.md @@ -0,0 +1,35 @@ +# Enforce Node.js-style error-first callback pattern is followed (`n/no-callback-literal`) + + + +When invoking a callback function which uses the Node.js error-first callback pattern, all of your errors should either use the `Error` class or a subclass of it. It is also acceptable to use `undefined` or `null` if there is no error. + +## 📖 Rule Details + +When a function is named `cb` or `callback`, then it must be invoked with a first argument that is `undefined`, `null`, an `Error` class, or a subclass or `Error`. + +Examples of 👎 **incorrect** code for this rule: + +```js +/*eslint n/no-callback-literal: "error" */ + +cb('this is an error string'); +cb({ a: 1 }); +callback(0); +``` + +Examples of 👍 **correct** code for this rule: + +```js +/*eslint n/no-callback-literal: "error" */ + +cb(undefined); +cb(null, 5); +callback(new Error('some error')); +callback(someVariable); +``` + +## 🔎 Implementation + +- [Rule source](../../lib/rules/no-callback-literal.js) +- [Test source](../../tests/lib/rules/no-callback-literal.js) diff --git a/docs/description/n_no-deprecated-api.md b/docs/description/n_no-deprecated-api.md new file mode 100644 index 000000000..c67dd7822 --- /dev/null +++ b/docs/description/n_no-deprecated-api.md @@ -0,0 +1,371 @@ +# Disallow deprecated APIs (`n/no-deprecated-api`) + +💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/eslint-community/eslint-plugin-n#-configs). + + + +Node has many deprecated API. +The community is going to remove those API from Node in future, so we should not use those. + +## 📖 Rule Details + +Examples of 👎 **incorrect** code for this rule: + +```js +/*eslint n/no-deprecated-api: "error" */ + +var fs = require("fs"); +fs.exists("./foo.js", function() {}); /*ERROR: 'fs.exists' was deprecated since v4. Use 'fs.stat()' or 'fs.access()' instead.*/ + +// Also, it can report the following patterns. +var exists = require("fs").exists; /*ERROR: 'fs.exists' was deprecated since v4. Use 'fs.stat()' or 'fs.access()' instead.*/ +const {exists} = require("fs"); /*ERROR: 'fs.exists' was deprecated since v4. Use 'fs.stat()' or 'fs.access()' instead.*/ + + +// And other deprecated API below. +``` + +This rule reports the following deprecated API. + +- [_linklist](https://nodejs.org/docs/v8.0.0/api/deprecations.html#deprecations_dep0002_require_linklist) +- [_stream_wrap](https://nodejs.org/docs/v12.0.0/api/deprecations.html#deprecations_dep0125_require_stream_wrap) +- async_hooks + - [currentId](https://nodejs.org/dist/v8.2.0/docs/api/deprecations.html#deprecations_dep0070_async_hooks_currentid) + - [triggerId](https://nodejs.org/dist/v8.2.0/docs/api/deprecations.html#deprecations_dep0071_async_hooks_triggerid) +- buffer + - [Buffer constructors](https://nodejs.org/dist/v6.0.0/docs/api/buffer.html#buffer_class_buffer) (Use [safe-buffer](https://www.npmjs.com/package/safe-buffer) module for `Node@<4.5.0`) + - [SlowBuffer class](https://nodejs.org/dist/v6.0.0/docs/api/buffer.html#buffer_class_slowbuffer) +- constants (undocumented) +- crypto + - [_toBuf](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0114_crypto_tobuf) + - `Credentials` (undocumented) + - [DEFAULT_ENCODING](https://nodejs.org/dist/v10.0.0/docs/api/crypto.html#crypto_crypto_default_encoding) + - [createCredentials](https://nodejs.org/dist/v0.12.0/docs/api/crypto.html#crypto_crypto_createcredentials_details) + - [createCipher](https://nodejs.org/dist/v10.0.0/docs/api/crypto.html#crypto_crypto_createcipher_algorithm_password_options) + - [createDecipher](https://nodejs.org/dist/v10.0.0/docs/api/crypto.html#crypto_crypto_createdecipher_algorithm_password_options) + - [fips](https://nodejs.org/dist/v10.0.0/docs/api/crypto.html#crypto_crypto_fips) + - [prng](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0115_crypto_prng_crypto_pseudorandombytes_crypto_rng) + - [pseudoRandomBytes](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0115_crypto_prng_crypto_pseudorandombytes_crypto_rng) + - [rng](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0115_crypto_prng_crypto_pseudorandombytes_crypto_rng) +- [domain](https://nodejs.org/dist/v4.0.0/docs/api/domain.html#domain_domain) +- events + - [EventEmitter.listenerCount](https://nodejs.org/dist/v4.0.0/docs/api/events.html#events_class_method_eventemitter_listenercount_emitter_event) +- freelist (undocumented) +- fs + - `SyncWriteStream` (undocumented) + - [exists](https://nodejs.org/dist/v4.0.0/docs/api/fs.html#fs_fs_exists_path_callback) + - [lchmod](https://nodejs.org/dist/v8.0.0/docs/api/fs.html#fs_fs_lchmod_path_mode_callback) + - [lchmodSync](https://nodejs.org/dist/v8.0.0/docs/api/fs.html#fs_fs_lchmodsync_path_mode) +- globals + - [require.extensions](https://nodejs.org/dist/v0.12.0/docs/api/globals.html#globals_require_extensions) + - [GLOBAL](https://nodejs.org/api/deprecations.html#deprecations_dep0016_global_root) + - [root](https://nodejs.org/api/deprecations.html#deprecations_dep0016_global_root) + - [Intl.v8BreakIterator](https://nodejs.org/api/deprecations.html#deprecations_dep0017_intl_v8breakiterator) + - [COUNTER_NET_SERVER_CONNECTION](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0120_windows_performance_counter_support) + - [COUNTER_NET_SERVER_CONNECTION_CLOSE](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0120_windows_performance_counter_support) + - [COUNTER_HTTP_SERVER_REQUEST](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0120_windows_performance_counter_support) + - [COUNTER_HTTP_SERVER_RESPONSE](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0120_windows_performance_counter_support) + - [COUNTER_HTTP_CLIENT_REQUEST](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0120_windows_performance_counter_support) + - [COUNTER_HTTP_CLIENT_RESPONSE](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0120_windows_performance_counter_support) +- http + - [createClient](https://nodejs.org/dist/v0.10.0/docs/api/http.html#http_http_createclient_port_host) +- module + - [createRequireFromPath](https://nodejs.org/dist/v12.2.0/docs/api/deprecations.html#deprecations_dep0130_module_createrequirefrompath) + - `requireRepl` (undocumented) + - [_debug](https://nodejs.org/dist/v9.0.0/docs/api/deprecations.html#deprecations_dep0077_module_debug) +- net + - [_setSimultaneousAccepts](https://nodejs.org/docs/v12.0.0/api/deprecations.html#deprecations_dep0121_net_setsimultaneousaccepts) +- os + - `tmpDir` (undocumented) + - `getNetworkInterfaces` (undocumented) +- path + - [_makeLong](https://nodejs.org/dist/v9.0.0/docs/api/deprecations.html#deprecations_dep0080_path_makelong) +- process + - `EventEmitter` (undocumented) + - `assert` (undocumented) + - [binding](https://nodejs.org/dist/v10.9.0/docs/api/deprecations.html#deprecations_dep0111_process_binding) +- [punycode](https://nodejs.org/dist/v7.0.0/docs/api/punycode.html) +- readline + - `codePointAt` (undocumented) + - `getStringWidth` (undocumented) + - `isFullWidthCodePoint` (undocumented) + - `stripVTControlCharacters` (undocumented) +- repl + - [process.env.NODE_REPL_HISTORY_FILE](https://nodejs.org/dist/v4.0.0/docs/api/repl.html#repl_node_repl_history_file) +- [sys](https://nodejs.org/api/deprecations.html#deprecations_dep0025_require_sys) +- timers + - `enroll` (undocumented) + - `unenroll` (undocumented) +- tls + - [CleartextStream](https://nodejs.org/dist/v0.10.0/docs/api/tls.html#tls_class_tls_cleartextstream) + (this class was removed on v0.11.3, but never deprecated in documents) + - [CryptoStream](https://nodejs.org/dist/v0.12.0/docs/api/tls.html#tls_class_cryptostream) + - [SecurePair](https://nodejs.org/dist/v6.0.0/docs/api/tls.html#tls_class_securepair) + - `convertNPNProtocols` (undocumented) + - [createSecurePair](https://nodejs.org/dist/v6.0.0/docs/api/tls.html#tls_tls_createsecurepair_context_isserver_requestcert_rejectunauthorized_options) + - [parseCertString](https://nodejs.org/dist/v8.6.0/docs/api/deprecations.html#deprecations_dep0076_tls_parsecertstring) +- tty + - [setRawMode](https://nodejs.org/dist/v0.10.0/docs/api/tty.html#tty_tty_setrawmode_mode) +- url + - [parse](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0116_legacy_url_api) + - [resolve](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0116_legacy_url_api) +- util + - [debug](https://nodejs.org/dist/v0.12.0/docs/api/util.html#util_util_debug_string) + - [error](https://nodejs.org/dist/v0.12.0/docs/api/util.html#util_util_error) + - [isArray](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isarray_object) + - [isBoolean](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isboolean_object) + - [isBuffer](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isbuffer_object) + - [isDate](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isdate_object) + - [isError](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_iserror_object) + - [isFunction](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isfunction_object) + - [isNull](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isnull_object) + - [isNullOrUndefined](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isnullorundefined_object) + - [isNumber](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isnumber_object) + - [isObject](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isobject_object) + - [isPrimitive](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isprimitive_object) + - [isRegExp](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isregexp_object) + - [isString](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isstring_object) + - [isSymbol](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_issymbol_object) + - [isUndefined](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isundefined_object) + - [log](https://nodejs.org/dist/v6.0.0/docs/api/util.html#util_util_log_string) + - [print](https://nodejs.org/dist/v0.12.0/docs/api/util.html#util_util_print) + - [pump](https://nodejs.org/dist/v0.10.0/docs/api/util.html#util_util_pump_readablestream_writablestream_callback) + - [puts](https://nodejs.org/dist/v0.12.0/docs/api/util.html#util_util_puts) + - [_extend](https://nodejs.org/dist/v6.0.0/docs/api/util.html#util_util_extend_obj) +- vm + - [runInDebugContext](https://nodejs.org/dist/v8.0.0/docs/api/vm.html#vm_vm_runindebugcontext_code) + +> ⚠️ Note that userland modules don't hide core modules. +> For example, `require("punycode")` still imports the deprecated core module even if you executed `npm install punycode`. +> Use `require("punycode/")` to import userland modules rather than core modules. + +### Configured Node.js version range + +[Configured Node.js version range](../../README.md#configured-nodejs-version-range) + +### Options + +This rule has 4 options. + +```json +{ + "rules": { + "n/no-deprecated-api": ["error", { + "version": ">=16.0.0", + "ignoreModuleItems": [], + "ignoreGlobalItems": [] + "ignoreIndirectDependencies": true + }] + } +} +``` + +#### version + +As mentioned above, this rule reads the [engines] field of `package.json`. +But, you can overwrite the version by `version` option. + +The `version` option accepts [the valid version range of `node-semver`](https://github.com/npm/node-semver#range-grammar). + +#### ignoreModuleItems + +This is the array of module names and module's member names. +Default is an empty array. + +This rule ignores APIs that `ignoreModuleItems` includes. +This option can include the following values: + +- `_linklist` +- `_stream_wrap` +- `async_hooks.currentId` +- `async_hooks.triggerId` +- `buffer.Buffer()` +- `new buffer.Buffer()` +- `buffer.SlowBuffer` +- `constants` +- `crypto._toBuf` +- `crypto.Credentials` +- `crypto.DEFAULT_ENCODING` +- `crypto.createCipher` +- `crypto.createCredentials` +- `crypto.createDecipher` +- `crypto.fips` +- `crypto.prng` +- `crypto.pseudoRandomBytes` +- `crypto.rng` +- `domain` +- `events.EventEmitter.listenerCount` +- `events.listenerCount` +- `freelist` +- `fs.SyncWriteStream` +- `fs.exists` +- `fs.lchmod` +- `fs.lchmodSync` +- `http.createClient` +- `module.Module.createRequireFromPath` +- `module.createRequireFromPath` +- `module.Module.requireRepl` +- `module.requireRepl` +- `module.Module._debug` +- `module._debug` +- `net._setSimultaneousAccepts` +- `os.tmpDir` +- `path._makeLong` +- `process.EventEmitter` +- `process.assert` +- `process.binding` +- `process.env.NODE_REPL_HISTORY_FILE` +- `process.report.triggerReport` +- `punycode` +- `readline.codePointAt` +- `readline.getStringWidth` +- `readline.isFullWidthCodePoint` +- `readline.stripVTControlCharacters` +- `sys` +- `timers.enroll` +- `timers.unenroll` +- `tls.CleartextStream` +- `tls.CryptoStream` +- `tls.SecurePair` +- `tls.convertNPNProtocols` +- `tls.createSecurePair` +- `tls.parseCertString` +- `tty.setRawMode` +- `url.parse` +- `url.resolve` +- `util.debug` +- `util.error` +- `util.isArray` +- `util.isBoolean` +- `util.isBuffer` +- `util.isDate` +- `util.isError` +- `util.isFunction` +- `util.isNull` +- `util.isNullOrUndefined` +- `util.isNumber` +- `util.isObject` +- `util.isPrimitive` +- `util.isRegExp` +- `util.isString` +- `util.isSymbol` +- `util.isUndefined` +- `util.log` +- `util.print` +- `util.pump` +- `util.puts` +- `util._extend` +- `vm.runInDebugContext` + +Examples of 👍 **correct** code for the `{"ignoreModuleItems": ["new buffer.Buffer()"]}`: + +```js +/*eslint n/no-deprecated-api: [error, {ignoreModuleItems: ["new buffer.Buffer()"]}] */ + +const buffer = require("buffer") +const data = new buffer.Buffer(10) // OK since it's in ignoreModuleItems. +``` + +#### ignoreGlobalItems + +This is the array of global variable names and global variable's member names. +Default is an empty array. + +This rule ignores APIs that `ignoreGlobalItems` includes. +This option can include the following values: + +- `Buffer()` +- `new Buffer()` +- `COUNTER_NET_SERVER_CONNECTION` +- `COUNTER_NET_SERVER_CONNECTION_CLOSE` +- `COUNTER_HTTP_SERVER_REQUEST` +- `COUNTER_HTTP_SERVER_RESPONSE` +- `COUNTER_HTTP_CLIENT_REQUEST` +- `COUNTER_HTTP_CLIENT_RESPONSE` +- `Intl.v8BreakIterator` +- `require.extensions` +- `process.EventEmitter` +- `process.assert` +- `process.binding` +- `process.env.NODE_REPL_HISTORY_FILE` + +Examples of 👍 **correct** code for the `{"ignoreGlobalItems": ["new Buffer()"]}`: + +```js +/*eslint n/no-deprecated-api: [error, {ignoreGlobalItems: ["new Buffer()"]}] */ + +const data = new Buffer(10) // OK since it's in ignoreGlobalItems. +``` + +## ⚠️ Known Limitations + +This rule cannot report the following cases: + +### non-static properties + +- async_hooks + - [asyncResource.triggerId](https://nodejs.org/dist/v8.2.0/docs/api/deprecations.html#deprecations_dep0072_async_hooks_asyncresource_triggerid) +- buffer + - [buf.parent](https://nodejs.org/dist/v8.0.0/docs/api/buffer.html#buffer_buf_parent) +- cluster + - [worker.suicide](https://nodejs.org/dist/v6.0.0/docs/api/cluster.html#cluster_worker_suicide) +- crypto + - [ecdh.setPublicKey](https://nodejs.org/dist/v6.0.0/docs/api/crypto.html#crypto_ecdh_setpublickey_public_key_encoding) +- http + - [res.writeHeader()](https://nodejs.org/dist/v8.0.0/docs/api/deprecations.html#deprecations_dep0063_serverresponse_prototype_writeheader) +- net + - [server.connections](https://nodejs.org/dist/v0.10.0/docs/api/net.html#net_server_connections) +- repl + - `replServer.convertToContext` (undocumented) + - [replServer.turnOffEditorMode](https://nodejs.org/dist/v9.0.0/docs/api/deprecations.html#deprecations_dep0078_replserver_turnoffeditormode) + - [replServer.memory](https://nodejs.org/dist/v9.0.0/docs/api/deprecations.html#deprecations_dep0082_replserver_prototype_memory) + +### types of arguments + +- fs + - `fs.truncate()` and `fs.truncateSync()` usage with a file descriptor has been deprecated. +- url + - `url.format()` with legacy `urlObject` has been deprecated. + +### dynamic things + +```js +require(foo).aDeprecatedProperty; +require("http")[A_DEPRECATED_PROPERTY](); +``` + +### assignments to properties + +```js +var obj = { + Buffer: require("buffer").Buffer +}; +new obj.Buffer(); /* missing. */ +``` + +```js +var obj = {}; +obj.Buffer = require("buffer").Buffer +new obj.Buffer(); /* missing. */ +``` + +### giving arguments + +```js +(function(Buffer) { + new Buffer(); /* missing. */ +})(require("buffer").Buffer); +``` + +### reassignments + +```js +var Buffer = require("buffer").Buffer; +Buffer = require("another-buffer"); +new Buffer(); /*ERROR: 'buffer.Buffer' constructor was deprecated.*/ +``` + +## 🔎 Implementation + +- [Rule source](../../lib/rules/no-deprecated-api.js) +- [Test source](../../tests/lib/rules/no-deprecated-api.js) diff --git a/docs/description/n_no-exports-assign.md b/docs/description/n_no-exports-assign.md new file mode 100644 index 000000000..891e1ebb3 --- /dev/null +++ b/docs/description/n_no-exports-assign.md @@ -0,0 +1,47 @@ +# Disallow the assignment to `exports` (`n/no-exports-assign`) + +💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/eslint-community/eslint-plugin-n#-configs). + + + +To assign to `exports` variable would not work as expected. + +```js +// This assigned object is not exported. +// You need to use `module.exports = { ... }`. +exports = { + foo: 1 +} +``` + +## 📖 Rule Details + +This rule is aimed at disallowing `exports = {}`, but allows `module.exports = exports = {}` to avoid conflict with [n/exports-style](./exports-style.md) rule's `allowBatchAssign` option. + +👍 Examples of **correct** code for this rule: + +```js +/*eslint n/no-exports-assign: error */ + +module.exports.foo = 1 +exports.bar = 2 + +module.exports = {} + +// allows `exports = {}` if along with `module.exports =` +module.exports = exports = {} +exports = module.exports = {} +``` + +👎 Examples of **incorrect** code for this rule: + +```js +/*eslint n/no-exports-assign: error */ + +exports = {} +``` + +## 🔎 Implementation + +- [Rule source](../../lib/rules/no-exports-assign.js) +- [Test source](../../tests/lib/rules/no-exports-assign.js) diff --git a/docs/description/n_no-extraneous-import.md b/docs/description/n_no-extraneous-import.md new file mode 100644 index 000000000..305b7e869 --- /dev/null +++ b/docs/description/n_no-extraneous-import.md @@ -0,0 +1,84 @@ +# Disallow `import` declarations which import extraneous modules (`n/no-extraneous-import`) + +💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/eslint-community/eslint-plugin-n#-configs). + + + +If an `import` declaration's source is extraneous (it's not written in `package.json`), the program works in local, but will not work after dependencies are re-installed. It will cause troubles to your team/contributors. +This rule disallows `import` declarations of extraneous modules. + +## 📖 Rule Details + +This rule warns `import` declarations of extraneous modules. + +### Options + +```json +{ + "rules": { + "n/no-extraneous-import": ["error", { + "allowModules": [], + "resolvePaths": [] + }] + } +} +``` + +#### allowModules + +Some platforms have additional embedded modules. +For example, Electron has `electron` module. + +We can specify additional embedded modules with this option. +This option is an array of strings as module names. + +```json +{ + "rules": { + "n/no-extraneous-import": ["error", { + "allowModules": ["electron"] + }] + } +} +``` + +#### resolvePaths + +Adds additional paths to try for when resolving imports. +If a path is relative, it will be resolved from CWD. + +Default is `[]` + +#### convertPath + +- `exclude`: TODO +- `include`: TODO +- `replace`: TODO + +### Shared Settings + +The following options can be set by [shared settings](http://eslint.org/docs/user-guide/configuring.html#adding-shared-settings). +Several rules have the same option, but we can set this option at once. + +- `allowModules` +- `resolvePaths` + +```js +// .eslintrc.js +module.exports = { + "settings": { + "node": { + "allowModules": ["electron"], + "resolvePaths": [__dirname], + } + }, + "rules": { + "n/no-extraneous-import": "error" + } +} +``` + +## 🔎 Implementation + +- [Rule source](../../lib/rules/no-extraneous-import.js) +- [Test source](../../tests/lib/rules/no-extraneous-import.js) diff --git a/docs/description/n_no-extraneous-require.md b/docs/description/n_no-extraneous-require.md new file mode 100644 index 000000000..0ca763952 --- /dev/null +++ b/docs/description/n_no-extraneous-require.md @@ -0,0 +1,94 @@ +# Disallow `require()` expressions which import extraneous modules (`n/no-extraneous-require`) + +💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/eslint-community/eslint-plugin-n#-configs). + + + +If a `require()`'s target is extraneous (it's not written in `package.json`), the program works in local, but will not work after dependencies are re-installed. It will cause troubles to your team/contributors. +This rule disallows `require()` of extraneous modules. + +## 📖 Rule Details + +This rule warns `require()` of extraneous modules. + +### Options + +```json +{ + "rules": { + "n/no-extraneous-require": ["error", { + "allowModules": [], + "resolvePaths": [], + "tryExtensions": [] + }] + } +} +``` + +#### allowModules + +Some platforms have additional embedded modules. +For example, Electron has `electron` module. + +We can specify additional embedded modules with this option. +This option is an array of strings as module names. + +```json +{ + "rules": { + "n/no-extraneous-require": ["error", { + "allowModules": ["electron"] + }] + } +} +``` + +#### resolvePaths + +Adds additional paths to try for when resolving imports. +If a path is relative, it will be resolved from CWD. + +Default is `[]` + +#### tryExtensions + +When an import path does not exist, this rule checks whether or not any of `path.js`, `path.json`, and `path.node` exists. +`tryExtensions` option is the extension list this rule uses at the time. + +Default is `[".js", ".json", ".node"]`. + +#### convertPath + +- `exclude`: TODO +- `include`: TODO +- `replace`: TODO + +### Shared Settings + +The following options can be set by [shared settings](http://eslint.org/docs/user-guide/configuring.html#adding-shared-settings). +Several rules have the same option, but we can set this option at once. + +- `allowModules` +- `resolvePaths` +- `tryExtensions` + +```js +// .eslintrc.js +module.exports = { + "settings": { + "node": { + "allowModules": ["electron"], + "resolvePaths": [__dirname], + "tryExtensions": [".js", ".json", ".node"] + } + }, + "rules": { + "n/no-extraneous-require": "error" + } +} +``` + +## 🔎 Implementation + +- [Rule source](../../lib/rules/no-extraneous-require.js) +- [Test source](../../tests/lib/rules/no-extraneous-require.js) diff --git a/docs/description/n_no-hide-core-modules.md b/docs/description/n_no-hide-core-modules.md new file mode 100644 index 000000000..24a43fcf5 --- /dev/null +++ b/docs/description/n_no-hide-core-modules.md @@ -0,0 +1,69 @@ +# Disallow third-party modules which are hiding core modules (`n/no-hide-core-modules`) + +❌ This rule is deprecated. + + + +**⚠️ This is deprecated since v4.2.0.** This rule was based on an invalid assumption. See also [#69](https://github.com/mysticatea/eslint-plugin-node/issues/69). + +If you have dependencies which have the same name as core modules, your module would use the third-party modules instead of core modules. +Especially, if you depends on such modules indirectly and npm flattens dependencies, you can depend on such third-party modules before as you know it. +This might cause unintentional behaviors. + +This rule warns `require()` expressions and `import` declarations if those import a third-party module which has the same name as core modules. + +## 📖 Rule Details + +👎 Examples of **incorrect** code for this rule: + +```js +/*eslint n/no-hide-core-modules: "error"*/ + +const util = require("util") // ERROR if `util` module exists in node_modules directory. +const path = require("path") // ERROR if `path` module exists in node_modules directory. +// ... +``` + +👍 Examples of **correct** code for this rule: + +```js +/*eslint n/no-hide-core-modules: "error"*/ + +const util = require("util") // OK if this is the core module 'util' surely. +const path = require("path") // OK if this is the core module 'path' surely. +``` + +### Options + +```json +{ + "n/no-hide-core-modules": ["error", { + "allow": [], + "ignoreDirectDependencies": false, + "ignoreIndirectDependencies": false, + }] +} +``` + +#### allow + +If you are sure that your module depends on the third-party module which has the same name as a core module, you can allow it by `allow` option. +E.g. `{"allow": ["util", "path"]}`. +Default is en empty array. + +#### ignoreDirectDependencies + +If `ignoreDirectDependencies: true`, if the third-party module which has the same name as a core module exists in your `package.json`, this rule ignores it. + +This option would allow all explicit dependencies which are hiding core modules. + +#### ignoreIndirectDependencies + +If `ignoreIndirectDependencies: true`, if the third-party module which has the same name as a core module does not exist in your `package.json`, this rule ignores it. + +This option would allow all implicit dependencies which are hiding core modules. + +## 🔎 Implementation + +- [Rule source](../../lib/rules/no-hide-core-modules.js) +- [Test source](../../tests/lib/rules/no-hide-core-modules.js) diff --git a/docs/description/n_no-missing-import.md b/docs/description/n_no-missing-import.md new file mode 100644 index 000000000..3e9bd7ace --- /dev/null +++ b/docs/description/n_no-missing-import.md @@ -0,0 +1,98 @@ +# Disallow `import` declarations which import non-existence modules (`n/no-missing-import`) + +💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/eslint-community/eslint-plugin-n#-configs). + + + +This is similar to [no-missing-require](no-missing-require.md), but this rule handles `import` and `export` declarations. + +⚠️ ECMAScript 2015 (ES6) does not define the lookup logic and Node does not support modules yet. So this rule spec might be changed in future. + +## 📖 Rule Details + +This rule checks the file paths of `import` and `export` declarations. +If the file paths don't exist, this reports these. + +Examples of 👎 **incorrect** code for this rule: + +```js +/*eslint n/no-missing-import: "error" */ + +import typoFile from "./typo-file"; /*ERROR: "./typo-file" is not found.*/ +import typoModule from "typo-module"; /*ERROR: "typo-module" is not found.*/ +``` + +Examples of 👍 **correct** code for this rule: + +```js +/*eslint n/no-missing-import: "error" */ + +import existingFile from "./existing-file"; +import existingModule from "existing-module"; +``` + +### Options + +```json +{ + "rules": { + "n/no-missing-import": ["error", { + "allowModules": [], + "resolvePaths": ["/path/to/a/modules/directory"] + }] + } +} +``` + +#### allowModules + +Some platforms have additional embedded modules. +For example, Electron has `electron` module. + +We can specify additional embedded modules with this option. +This option is an array of strings as module names. + +```json +{ + "rules": { + "n/no-missing-import": ["error", { + "allowModules": ["electron"] + }] + } +} +``` + +#### resolvePaths + +Adds additional paths to try for when resolving imports. +If a path is relative, it will be resolved from CWD. + +Default is `[]` + +### Shared Settings + +The following options can be set by [shared settings](http://eslint.org/docs/user-guide/configuring.html#adding-shared-settings). +Several rules have the same option, but we can set this option at once. + +- `allowModules` +- `resolvePaths` + +```js +// .eslintrc.js +module.exports = { + "settings": { + "node": { + "allowModules": ["electron"], + "resolvePaths": [__dirname], + } + }, + "rules": { + "n/no-missing-import": "error" + } +} +``` + +## 🔎 Implementation + +- [Rule source](../../lib/rules/no-missing-import.js) +- [Test source](../../tests/lib/rules/no-missing-import.js) diff --git a/docs/description/n_no-missing-require.md b/docs/description/n_no-missing-require.md new file mode 100644 index 000000000..96822d5fb --- /dev/null +++ b/docs/description/n_no-missing-require.md @@ -0,0 +1,113 @@ +# Disallow `require()` expressions which import non-existence modules (`n/no-missing-require`) + +💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/eslint-community/eslint-plugin-n#-configs). + + + +Maybe we cannot find typo of import paths until run it, so this rule checks import paths. + +```js +// If the file "foo" doesn't exist, this is a runtime error. +const foo = require("./foo"); +``` + +## 📖 Rule Details + +This rule checks the file paths of `require()`s, then reports the path of files which don't exist. + +Examples of 👎 **incorrect** code for this rule: + +```js +/*eslint n/no-missing-require: "error" */ + +var typoFile = require("./typo-file"); /*error "./typo-file" is not found.*/ +var typoModule = require("typo-module"); /*error "typo-module" is not found.*/ +``` + +Examples of 👍 **correct** code for this rule: + +```js +/*eslint n/no-missing-require: "error" */ + +var existingFile = require("./existing-file"); +var existingModule = require("existing-module"); + +// This rule cannot check for dynamic imports. +var foo = require(FOO_NAME); +``` + +### Options + +```json +{ + "rules": { + "n/no-missing-require": ["error", { + "allowModules": [], + "resolvePaths": ["/path/to/a/modules/directory"], + "tryExtensions": [".js", ".json", ".node"] + }] + } +} +``` + +#### allowModules + +Some platforms have additional embedded modules. +For example, Electron has `electron` module. + +We can specify additional embedded modules with this option. +This option is an array of strings as module names. + +```json +{ + "rules": { + "n/no-missing-require": ["error", { + "allowModules": ["electron"] + }] + } +} +``` + +#### resolvePaths + +Adds additional paths to try for when resolving a require. +If a path is relative, it will be resolved from CWD. + +Default is `[]` + +#### tryExtensions + +When an import path does not exist, this rule checks whether or not any of `path.js`, `path.json`, and `path.node` exists. +`tryExtensions` option is the extension list this rule uses at the time. + +Default is `[".js", ".json", ".node"]`. + +### Shared Settings + +The following options can be set by [shared settings](http://eslint.org/docs/user-guide/configuring.html#adding-shared-settings). +Several rules have the same option, but we can set this option at once. + +- `allowModules` +- `resolvePaths` +- `tryExtensions` + +```js +// .eslintrc.js +module.exports = { + "settings": { + "node": { + "allowModules": ["electron"], + "resolvePaths": [__dirname], + "tryExtensions": [".js", ".json", ".node"] + } + }, + "rules": { + "n/no-missing-require": "error" + } +} +``` + +## 🔎 Implementation + +- [Rule source](../../lib/rules/no-missing-require.js) +- [Test source](../../tests/lib/rules/no-missing-require.js) diff --git a/docs/description/n_no-mixed-requires.md b/docs/description/n_no-mixed-requires.md new file mode 100644 index 000000000..db8bf41cc --- /dev/null +++ b/docs/description/n_no-mixed-requires.md @@ -0,0 +1,122 @@ +# Disallow `require` calls to be mixed with regular variable declarations (`n/no-mixed-requires`) + + + +In the Node.js community it is often customary to separate initializations with calls to `require` modules from other variable declarations, sometimes also grouping them by the type of module. This rule helps you enforce this convention. + +## 📖 Rule Details + +When this rule is enabled, each `var` statement must satisfy the following conditions: + +- either none or all variable declarations must be require declarations (default) +- all require declarations must be of the same type (grouping) + +This rule distinguishes between six kinds of variable declaration types: + +- `core`: declaration of a required +- `file`: declaration of a required +- `module`: declaration of a required module from the +- `computed`: declaration of a required module whose type could not be determined (either because it is computed or because require was called without an argument) +- `uninitialized`: a declaration that is not initialized +- `other`: any other kind of declaration + +In this document, the first four types are summed up under the term *require declaration*. + +```js +var fs = require('fs'), // "core" \ + async = require('async'), // "module" |- these are "require declaration"s + foo = require('./foo'), // "file" | + bar = require(getName()), // "computed" / + baz = 42, // "other" + bam; // "uninitialized" +``` + +### Options + +This rule can have an object literal option whose two properties have `false` values by default. + +Configuring this rule with one boolean option `true` is deprecated. + +Examples of **incorrect** code for this rule with the default `{ "grouping": false, "allowCall": false }` options: + +```js +/*eslint n/no-mixed-requires: "error"*/ + +var fs = require('fs'), + i = 0; + +var async = require('async'), + debug = require('diagnostics').someFunction('my-module'), + eslint = require('eslint'); +``` + +Examples of **correct** code for this rule with the default `{ "grouping": false, "allowCall": false }` options: + +```js +/*eslint n/no-mixed-requires: "error"*/ + +// only require declarations (grouping off) +var eventEmitter = require('events').EventEmitter, + myUtils = require('./utils'), + util = require('util'), + bar = require(getBarModuleName()); + +// only non-require declarations +var foo = 42, + bar = 'baz'; + +// always valid regardless of grouping because all declarations are of the same type +var foo = require('foo' + VERSION), + bar = require(getBarModuleName()), + baz = require(); +``` + +#### grouping + +Examples of **incorrect** code for this rule with the `{ "grouping": true }` option: + +```js +/*eslint n/no-mixed-requires: ["error", { "grouping": true }]*/ + +// invalid because of mixed types "core" and "module" +var fs = require('fs'), + async = require('async'); + +// invalid because of mixed types "file" and "unknown" +var foo = require('foo'), + bar = require(getBarModuleName()); +``` + +#### allowCall + +Examples of **incorrect** code for this rule with the `{ "allowCall": true }` option: + +```js +/*eslint n/no-mixed-requires: ["error", { "allowCall": true }]*/ + +var async = require('async'), + debug = require('diagnostics').someFunction('my-module'), /* allowCall doesn't allow calling any function */ + eslint = require('eslint'); +``` + +Examples of **correct** code for this rule with the `{ "allowCall": true }` option: + +```js +/*eslint n/no-mixed-requires: ["error", { "allowCall": true }]*/ + +var async = require('async'), + debug = require('diagnostics')('my-module'), + eslint = require('eslint'); +``` + +### Known Limitations + +- The implementation is not aware of any local functions with the name `require` that may shadow Node.js' global `require`. + +- Internally, the list of core modules is retrieved via `require("repl")._builtinLibs`. If you use different versions of Node.js for ESLint and your application, the list of core modules for each version may be different. + The above mentioned `_builtinLibs` property became available in 0.8, for earlier versions a hardcoded list of module names is used as a fallback. If your version of Node.js is older than 0.6 that list may be inaccurate. + +## 🔎 Implementation + +- [Rule source](../../lib/rules/no-mixed-requires.js) +- [Test source](../../tests/lib/rules/no-mixed-requires.js) diff --git a/docs/description/n_no-new-require.md b/docs/description/n_no-new-require.md new file mode 100644 index 000000000..734c0eda3 --- /dev/null +++ b/docs/description/n_no-new-require.md @@ -0,0 +1,49 @@ +# Disallow `new` operators with calls to `require` (`n/no-new-require`) + + + +The `require` function is used to include modules that exist in separate files, such as: + +```js +var appHeader = require('app-header'); +``` + +Some modules return a constructor which can potentially lead to code such as: + +```js +var appHeader = new require('app-header'); +``` + +Unfortunately, this introduces a high potential for confusion since the code author likely meant to write: + +```js +var appHeader = new (require('app-header')); +``` + +For this reason, it is usually best to disallow this particular expression. + +## 📖 Rule Details + +This rule aims to eliminate use of the `new require` expression. + +Examples of **incorrect** code for this rule: + +```js +/*eslint n/no-new-require: "error"*/ + +var appHeader = new require('app-header'); +``` + +Examples of **correct** code for this rule: + +```js +/*eslint n/no-new-require: "error"*/ + +var AppHeader = require('app-header'); +var appHeader = new AppHeader(); +``` + +## 🔎 Implementation + +- [Rule source](../../lib/rules/no-new-require.js) +- [Test source](../../tests/lib/rules/no-new-require.js) diff --git a/docs/description/n_no-path-concat.md b/docs/description/n_no-path-concat.md new file mode 100644 index 000000000..7baa9a2df --- /dev/null +++ b/docs/description/n_no-path-concat.md @@ -0,0 +1,58 @@ +# Disallow string concatenation with `__dirname` and `__filename` (`n/no-path-concat`) + + + +In Node.js, the `__dirname` and `__filename` global variables contain the directory path and the file path of the currently executing script file, respectively. Sometimes, developers try to use these variables to create paths to other files, such as: + +```js +var fullPath = __dirname + "/foo.js"; +``` + +However, there are a few problems with this. First, you can't be sure what type of system the script is running on. Node.js can be run on any computer, including Windows, which uses a different path separator. It's very easy, therefore, to create an invalid path using string concatenation and assuming Unix-style separators. There's also the possibility of having double separators, or otherwise ending up with an invalid path. + +In order to avoid any confusion as to how to create the correct path, Node.js provides the `path` module. This module uses system-specific information to always return the correct value. So you can rewrite the previous example as: + +```js +var fullPath = path.join(__dirname, "foo.js"); +``` + +This example doesn't need to include separators as `path.join()` will do it in the most appropriate manner. Alternately, you can use `path.resolve()` to retrieve the fully-qualified path: + +```js +var fullPath = path.resolve(__dirname, "foo.js"); +``` + +Both `path.join()` and `path.resolve()` are suitable replacements for string concatenation wherever file or directory paths are being created. + +## 📖 Rule Details + +This rule aims to prevent string concatenation of directory paths in Node.js + +Examples of **incorrect** code for this rule: + +```js +/*eslint n/no-path-concat: "error"*/ + +const fullPath1 = __dirname + "/foo.js"; +const fullPath2 = __filename + "/foo.js"; +const fullPath3 = `${__dirname}/foo.js`; +const fullPath4 = `${__filename}/foo.js`; +``` + +Examples of **correct** code for this rule: + +```js +/*eslint n/no-path-concat: "error"*/ + +const fullPath1 = path.join(__dirname, "foo.js"); +const fullPath2 = path.join(__filename, "foo.js"); +const fullPath3 = __dirname + ".js"; +const fullPath4 = __filename + ".map"; +const fullPath5 = `${__dirname}_foo.js`; +const fullPath6 = `${__filename}.test.js`; +``` + +## 🔎 Implementation + +- [Rule source](../../lib/rules/no-path-concat.js) +- [Test source](../../tests/lib/rules/no-path-concat.js) diff --git a/docs/description/n_no-process-env.md b/docs/description/n_no-process-env.md new file mode 100644 index 000000000..bd3c84dcf --- /dev/null +++ b/docs/description/n_no-process-env.md @@ -0,0 +1,36 @@ +# Disallow the use of `process.env` (`n/no-process-env`) + + + +The `process.env` object in Node.js is used to store deployment/configuration parameters. Littering it through out a project could lead to maintenance issues as it's another kind of global dependency. As such, it could lead to merge conflicts in a multi-user setup and deployment issues in a multi-server setup. Instead, one of the best practices is to define all those parameters in a single configuration/settings file which could be accessed throughout the project. + +## 📖 Rule Details + +This rule is aimed at discouraging use of `process.env` to avoid global dependencies. As such, it will warn whenever `process.env` is used. + +Examples of **incorrect** code for this rule: + +```js +/*eslint n/no-process-env: "error"*/ + +if(process.env.NODE_ENV === "development") { + //... +} +``` + +Examples of **correct** code for this rule: + +```js +/*eslint n/no-process-env: "error"*/ + +var config = require("./config"); + +if(config.env === "development") { + //... +} +``` + +## 🔎 Implementation + +- [Rule source](../../lib/rules/no-process-env.js) +- [Test source](../../tests/lib/rules/no-process-env.js) diff --git a/docs/description/n_no-process-exit.md b/docs/description/n_no-process-exit.md new file mode 100644 index 000000000..c00cfa74e --- /dev/null +++ b/docs/description/n_no-process-exit.md @@ -0,0 +1,53 @@ +# Disallow the use of `process.exit()` (`n/no-process-exit`) + +💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/eslint-community/eslint-plugin-n#-configs). + + + +The `process.exit()` method in Node.js is used to immediately stop the Node.js process and exit. This is a dangerous operation because it can occur in any method at any point in time, potentially stopping a Node.js application completely when an error occurs. For example: + +```js +if (somethingBadHappened) { + console.error("Something bad happened!"); + process.exit(1); +} +``` + +This code could appear in any module and will stop the entire application when `somethingBadHappened` is truthy. This doesn't give the application any chance to respond to the error. It's usually better to throw an error and allow the application to handle it appropriately: + +```js +if (somethingBadHappened) { + throw new Error("Something bad happened!"); +} +``` + +By throwing an error in this way, other parts of the application have an opportunity to handle the error rather than stopping the application altogether. If the error bubbles all the way up to the process without being handled, then the process will exit and a non-zero exit code will returned, so the end result is the same. + +If you are using `process.exit()` only for specifying the exit code, you can set [`process.exitCode`](https://nodejs.org/api/process.html#process_process_exitcode) (introduced in Node.js 0.11.8) instead. + +## 📖 Rule Details + +This rule aims to prevent the use of `process.exit()` in Node.js JavaScript. As such, it warns whenever `process.exit()` is found in code. + +Examples of **incorrect** code for this rule: + +```js +/*eslint n/no-process-exit: "error"*/ + +process.exit(1); +process.exit(0); +``` + +Examples of **correct** code for this rule: + +```js +/*eslint n/no-process-exit: "error"*/ + +Process.exit(); +var exit = process.exit; +``` + +## 🔎 Implementation + +- [Rule source](../../lib/rules/no-process-exit.js) +- [Test source](../../tests/lib/rules/no-process-exit.js) diff --git a/docs/description/n_no-restricted-import.md b/docs/description/n_no-restricted-import.md new file mode 100644 index 000000000..82da6e24f --- /dev/null +++ b/docs/description/n_no-restricted-import.md @@ -0,0 +1,117 @@ +# Disallow specified modules when loaded by `import` declarations (`n/no-restricted-import`) + + + +## 📖 Rule Details + +This rule allows you to specify modules that you don’t want to use in your application. + +### Options + +The rule takes an array as options: the names of restricted modules. + +```json +{ + "n/no-restricted-import": ["error", [ + "foo-module", + "bar-module" + ]] +} +``` + +You may also specify a custom message for each module you want to restrict as follows: + +```json +{ + "n/no-restricted-import": ["error", [ + { + "name": "foo-module", + "message": "Please use foo-module2 instead." + }, + { + "name": "bar-module", + "message": "Please use bar-module2 instead." + } + ]] +} +``` + +And you can use glob patterns in the `name` property. + +```json +{ + "n/no-restricted-import": ["error", [ + { + "name": "lodash/*", + "message": "Please use xyz-module instead." + }, + { + "name": ["foo-module/private/*", "bar-module/*", "!baz-module/good"], + "message": "Please use xyz-module instead." + } + ]] +} +``` + +And you can use absolute paths in the `name` property. + +```js +module.exports = { + overrides: [ + { + files: "client/**", + rules: { + "n/no-restricted-import": ["error", [ + { + name: path.resolve(__dirname, "server/**"), + message: "Don't use server code from client code." + } + ]] + } + }, + { + files: "server/**", + rules: { + "n/no-restricted-import": ["error", [ + { + name: path.resolve(__dirname, "client/**"), + message: "Don't use client code from server code." + } + ]] + } + } + ] +} +``` + +### Examples + +Examples of **incorrect** code for this rule with sample `"fs", "cluster", "lodash"` restricted modules: + +```js +/*eslint n/no-restricted-import: ["error", ["fs", "cluster", "lodash/*"]]*/ + +import fs from 'fs'; +import cluster from 'cluster'; +import pick from 'lodash/pick'; +``` + +Examples of **correct** code for this rule with sample `"fs", "cluster", "lodash"` restricted modules: + +```js +/*eslint n/no-restricted-import: ["error", ["fs", "cluster", "lodash/*"]]*/ + +import crypto from 'crypto'; +import _ from 'lodash'; +``` + +```js +/*eslint n/no-restricted-import: ["error", ["fs", "cluster", { "name": ["lodash/*", "!lodash/pick"] }]]*/ + +import pick from 'lodash/pick'; +``` + +## 🔎 Implementation + +- [Rule source](../../lib/rules/no-restricted-import.js) +- [Test source](../../tests/lib/rules/no-restricted-import.js) diff --git a/docs/description/n_no-restricted-require.md b/docs/description/n_no-restricted-require.md new file mode 100644 index 000000000..9b1723b4f --- /dev/null +++ b/docs/description/n_no-restricted-require.md @@ -0,0 +1,124 @@ +# Disallow specified modules when loaded by `require` (`n/no-restricted-require`) + + + +A module in Node.js is a simple or complex functionality organized in a JavaScript file which can be reused throughout the Node.js +application. The keyword `require` is used in Node.js/CommonJS to import modules into an application. This way you can have dynamic loading where the loaded module name isn't predefined /static, or where you conditionally load a module only if it's "truly required". + +Why would you want to restrict a module? + +Disallowing usage of specific Node.js modules can be useful if you want to limit the available methods a developer can use. For example, you can block usage of the `fs` module if you want to disallow file system access. + +## 📖 Rule Details + +This rule allows you to specify modules that you don’t want to use in your application. + +### Options + +The rule takes an array as options: the names of restricted modules. + +```json +{ + "n/no-restricted-require": ["error", [ + "foo-module", + "bar-module" + ]] +} +``` + +You may also specify a custom message for each module you want to restrict as follows: + +```json +{ + "n/no-restricted-require": ["error", [ + { + "name": "foo-module", + "message": "Please use foo-module2 instead." + }, + { + "name": "bar-module", + "message": "Please use bar-module2 instead." + } + ]] +} +``` + +And you can use glob patterns in the `name` property. + +```json +{ + "n/no-restricted-require": ["error", [ + { + "name": "lodash/*", + "message": "Please use xyz-module instead." + }, + { + "name": ["foo-module/private/*", "bar-module/*", "!baz-module/good"], + "message": "Please use xyz-module instead." + } + ]] +} +``` + +And you can use absolute paths in the `name` property. + +```js +module.exports = { + overrides: [ + { + files: "client/**", + rules: { + "n/no-restricted-require": ["error", [ + { + name: path.resolve(__dirname, "server/**"), + message: "Don't use server code from client code." + } + ]] + } + }, + { + files: "server/**", + rules: { + "n/no-restricted-require": ["error", [ + { + name: path.resolve(__dirname, "client/**"), + message: "Don't use client code from server code." + } + ]] + } + } + ] +} +``` + +### Examples + +Examples of **incorrect** code for this rule with sample `"fs", "cluster", "lodash"` restricted modules: + +```js +/*eslint n/no-restricted-require: ["error", ["fs", "cluster", "lodash/*"]]*/ + +const fs = require('fs'); +const cluster = require('cluster'); +const pick = require('lodash/pick'); +``` + +Examples of **correct** code for this rule with sample `"fs", "cluster", "lodash"` restricted modules: + +```js +/*eslint n/no-restricted-require: ["error", ["fs", "cluster", "lodash/*"]]*/ + +const crypto = require('crypto'); +const _ = require('lodash'); +``` + +```js +/*eslint n/no-restricted-require: ["error", ["fs", "cluster", { "name": ["lodash/*", "!lodash/pick"] }]]*/ + +const pick = require('lodash/pick'); +``` + +## 🔎 Implementation + +- [Rule source](../../lib/rules/no-restricted-require.js) +- [Test source](../../tests/lib/rules/no-restricted-require.js) diff --git a/docs/description/n_no-sync.md b/docs/description/n_no-sync.md new file mode 100644 index 000000000..30789ca7d --- /dev/null +++ b/docs/description/n_no-sync.md @@ -0,0 +1,62 @@ +# Disallow synchronous methods (`n/no-sync`) + + + +In Node.js, most I/O is done through asynchronous methods. However, there are often synchronous versions of the asynchronous methods. For example, `fs.exists()` and `fs.existsSync()`. In some contexts, using synchronous operations is okay (if, as with ESLint, you are writing a command line utility). However, in other contexts the use of synchronous operations is considered a bad practice that should be avoided. For example, if you are running a high-travel web server on Node.js, you should consider carefully if you want to allow any synchronous operations that could lock up the server. + +## 📖 Rule Details + +This rule is aimed at preventing synchronous methods from being called in Node.js. It looks specifically for the method suffix "`Sync`" (as is the convention with Node.js operations). + +### Options + +This rule has an optional object option `{ allowAtRootLevel: }`, which determines whether synchronous methods should be allowed at the top level of a file, outside of any functions. This option defaults to `false`. + +Examples of **incorrect** code for this rule with the default `{ allowAtRootLevel: false }` option: + +```js +/*eslint n/no-sync: "error"*/ + +fs.existsSync(somePath); + +function foo() { + var contents = fs.readFileSync(somePath).toString(); +} +``` + +Examples of **correct** code for this rule with the default `{ allowAtRootLevel: false }` option: + +```js +/*eslint n/no-sync: "error"*/ + +obj.sync(); + +async(function() { + // ... +}); +``` + +Examples of **incorrect** code for this rule with the `{ allowAtRootLevel: true }` option + +```js +/*eslint n/no-sync: ["error", { allowAtRootLevel: true }]*/ + +function foo() { + var contents = fs.readFileSync(somePath).toString(); +} + +var bar = baz => fs.readFileSync(qux); +``` + +Examples of **correct** code for this rule with the `{ allowAtRootLevel: true }` option + +```js +/*eslint n/no-sync: ["error", { allowAtRootLevel: true }]*/ + +fs.readFileSync(somePath).toString(); +``` + +## 🔎 Implementation + +- [Rule source](../../lib/rules/no-sync.js) +- [Test source](../../tests/lib/rules/no-sync.js) diff --git a/docs/description/n_no-unpublished-bin.md b/docs/description/n_no-unpublished-bin.md new file mode 100644 index 000000000..4288b480a --- /dev/null +++ b/docs/description/n_no-unpublished-bin.md @@ -0,0 +1,117 @@ +# Disallow `bin` files that npm ignores (`n/no-unpublished-bin`) + +💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/eslint-community/eslint-plugin-n#-configs). + + + +We can publish CLI commands by `npm`. It uses `bin` field of `package.json`. + +```json +{ + "name": "command-name", + "bin": "bin/index.js" +} +``` + +At this time, if `npm` ignores the file, your package will fail to install. + +## 📖 Rule Details + +If `npm` ignores the files in `bin` field, this rule warns the files. + +- If `files` field does not includes the files in `bin` field. +- If `.npmignore` file includes the files in `bin` field. + +### Options + +```json +{ + "rules": { + "n/no-unpublished-bin": ["error", { + "convertPath": null + }] + } +} +``` + +#### convertPath + +If we use transpilers (e.g. Babel), perhaps the file path to a source code is never published. +`convertPath` option tells to the rule, it needs to convert file paths. + +For example: + +```json +{ + "rules": { + "n/no-unpublished-bin": ["error", { + "convertPath": { + "src/bin/**/*.js": ["^src/(.+)$", "$1"] + } + }] + } +} +``` + +This option has the following shape: `: [, ]` + +`targetFiles` is a glob pattern. +It converts paths which are matched to the pattern with the following way. + +```js +path.replace(new RegExp(fromRegExp), toString); +``` + +So on this example, `src/bin/index.js` is handled as `bin/index.js`. + +The `convertPath` option can be an array as well. + +For example: + +```json +{ + "rules": { + "n/no-unpublished-bin": ["error", { + "convertPath": [ + { + "include": ["src/bin/**/*.js"], + "exclude": ["**/*.spec.js"], + "replace": ["^src/(.+)$", "$1"] + } + ] + }] + } +} +``` + +In this style, this option has the following shape as the same expression as above: `{include: [], replace: [, ]}`. +In addition, we can specify glob patterns to exclude files. + +### Shared Settings + +The following options can be set by [shared settings](http://eslint.org/docs/user-guide/configuring.html#adding-shared-settings). +Several rules have the same option, but we can set this option at once. + +- `convertPath` + +For Example: + +```json +{ + "settings": { + "node": { + "convertPath": { + "src/bin/**/*.js": ["^src/bin/(.+)$", "bin/$1"] + } + } + }, + "rules": { + "n/no-unpublished-bin": "error" + } +} +``` + +## 🔎 Implementation + +- [Rule source](../../lib/rules/no-unpublished-bin.js) +- [Test source](../../tests/lib/rules/no-unpublished-bin.js) diff --git a/docs/description/n_no-unpublished-import.md b/docs/description/n_no-unpublished-import.md new file mode 100644 index 000000000..114a305bf --- /dev/null +++ b/docs/description/n_no-unpublished-import.md @@ -0,0 +1,160 @@ +# Disallow `import` declarations which import private modules (`n/no-unpublished-import`) + +💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/eslint-community/eslint-plugin-n#-configs). + + + +This is similar to [no-unpublished-require](no-unpublished-require.md), but this rule handles `import` declarations. + +⚠️ ECMAScript 2015 (ES6) does not define the lookup logic and Node does not support modules yet. So this rule spec might be changed in future. + +## 📖 Rule Details + +If a source code file satisfies all of the following conditions, the file is \*published\*. + +- `"files"` field of `package.json` includes the file or `"files"` field of `package.json` does not exist. +- `.npmignore` does not include the file. + +Then this rule warns `import` declarations in \*published\* files if the `import` declaration imports \*unpublished\* files or the packages of `devDependencies`. + +> This intends to prevent "Module Not Found" error after `npm publish`.\ +> 💡 If you want to import `devDependencies`, please write `.npmignore` or `"files"` field of `package.json`. + +### Options + +```json +{ + "rules": { + "n/no-unpublished-import": ["error", { + "allowModules": [], + "convertPath": null + }] + } +} +``` + +#### allowModules + +Some platforms have additional embedded modules. +For example, Electron has `electron` module. + +We can specify additional embedded modules with this option. +This option is an array of strings as module names. + +```json +{ + "rules": { + "n/no-unpublished-import": ["error", { + "allowModules": ["electron"] + }] + } +} +``` + +#### convertPath + +If we use transpilers (e.g. Babel), perhaps the file path to a source code is never published. +`convertPath` option tells to the rule, it needs to convert file paths. + +For example: + +```json +{ + "rules": { + "n/no-unpublished-import": ["error", { + "convertPath": { + "src/**/*.jsx": ["^src/(.+?)\\.jsx$", "lib/$1.js"] + } + }] + } +} +``` + +This option has the following shape: `: [, ]` + +`targetFiles` is a glob pattern. +It converts paths which are matched to the pattern with the following way. + +```js +path.replace(new RegExp(fromRegExp), toString); +``` + +So on this example, `src/a/foo.jsx` is handled as `lib/a/foo.js`. + +The `convertPath` option can be an array as well. + +For example: + +```json +{ + "rules": { + "n/no-unpublished-import": ["error", { + "convertPath": [ + { + "include": ["src/**/*.js"], + "exclude": ["**/*.spec.js"], + "replace": ["^src/(.+)$", "lib/$1"] + } + ] + }] + } +} +``` + +In this style, this option has the following shape as the same expression as above: `{include: [], replace: [, ]}`. +In addition, we can specify glob patterns to exclude files. + +#### resolvePaths + +TODO + +### ignoreTypeImport + +If using typescript, you may want to ignore type imports. This option allows you to do that. + +```json +{ + "rules": { + "n/no-unpublished-import": ["error", { + "ignoreTypeImport": true + }] + } +} +``` + +In this way, the following code will not be reported: + +```ts +import type foo from "foo"; +``` + +### Shared Settings + +The following options can be set by [shared settings](http://eslint.org/docs/user-guide/configuring.html#adding-shared-settings). +Several rules have the same option, but we can set this option at once. + +- `allowModules` +- `convertPath` + +For Example: + +```json +{ + "settings": { + "node": { + "allowModules": ["electron"], + "convertPath": { + "src/**/*.jsx": ["^src/(.+?)\\.jsx$", "lib/$1.js"] + } + } + }, + "rules": { + "n/no-unpublished-import": "error" + } +} +``` + +## 🔎 Implementation + +- [Rule source](../../lib/rules/no-unpublished-import.js) +- [Test source](../../tests/lib/rules/no-unpublished-import.js) diff --git a/docs/description/n_no-unpublished-require.md b/docs/description/n_no-unpublished-require.md new file mode 100644 index 000000000..84615ee8b --- /dev/null +++ b/docs/description/n_no-unpublished-require.md @@ -0,0 +1,150 @@ +# Disallow `require()` expressions which import private modules (`n/no-unpublished-require`) + +💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/eslint-community/eslint-plugin-n#-configs). + + + +If a `require()` expression's target is not published, the program works in local, but will not work after published to npm. +This rule disallows `require()` expressions of unpublished files/modules. + +## 📖 Rule Details + +If a source code file satisfies all of the following conditions, the file is \*published\*. + +- `"files"` field of `package.json` includes the file or `"files"` field of `package.json` does not exist. +- `.npmignore` does not include the file. + +Then this rule warns `require()` expressions in \*published\* files if the `require()` expression imports \*unpublished\* files or the packages of `devDependencies`. + +> This intends to prevent "Module Not Found" error after `npm publish`.\ +> 💡 If you want to import `devDependencies`, please write `.npmignore` or `"files"` field of `package.json`. + +### Options + +```json +{ + "rules": { + "n/no-unpublished-require": ["error", { + "allowModules": [], + "convertPath": null, + "tryExtensions": [".js", ".json", ".node"] + }] + } +} +``` + +#### allowModules + +Some platforms have additional embedded modules. +For example, Electron has `electron` module. + +We can specify additional embedded modules with this option. +This option is an array of strings as module names. + +```json +{ + "rules": { + "n/no-unpublished-require": ["error", { + "allowModules": ["electron"] + }] + } +} +``` + +#### convertPath + +If we use transpilers (e.g. Babel), perhaps the file path to a source code is never published. +`convertPath` option tells to the rule, it needs to convert file paths. + +For example: + +```json +{ + "rules": { + "n/no-unpublished-require": ["error", { + "convertPath": { + "src/**/*.jsx": ["^src/(.+?)\\.jsx$", "lib/$1.js"] + }, + "tryExtensions": [".js", ".jsx", ".json"] + }] + } +} +``` + +This option has the following shape: `: [, ]` + +`targetFiles` is a glob pattern. +It converts paths which are matched to the pattern with the following way. + +```js +path.replace(new RegExp(fromRegExp), toString); +``` + +So on this example, `src/a/foo.jsx` is handled as `lib/a/foo.js`. + +The `convertPath` option can be an array as well. + +For example: + +```json +{ + "rules": { + "n/no-unpublished-require": ["error", { + "convertPath": [ + { + "include": ["src/**/*.js"], + "exclude": ["**/*.spec.js"], + "replace": ["^src/(.+)$", "lib/$1"] + } + ] + }] + } +} +``` + +In this style, this option has the following shape as the same expression as above: `{include: [], replace: [, ]}`. +In addition, we can specify glob patterns to exclude files. + +#### tryExtensions + +When an import path does not exist, this rule checks whether or not any of `path.js`, `path.json`, and `path.node` exists. +`tryExtensions` option is the extension list this rule uses at the time. + +Default is `[".js", ".json", ".node"]`. + +#### resolvePaths + +TODO + +### Shared Settings + +The following options can be set by [shared settings](http://eslint.org/docs/user-guide/configuring.html#adding-shared-settings). +Several rules have the same option, but we can set this option at once. + +- `allowModules` +- `convertPath` +- `tryExtensions` + +For Example: + +```json +{ + "settings": { + "node": { + "allowModules": ["electron"], + "convertPath": { + "src/**/*.jsx": ["^src/(.+?)\\.jsx$", "lib/$1.js"] + }, + "tryExtensions": [".js", ".jsx", ".json"] + } + }, + "rules": { + "n/no-unpublished-require": "error" + } +} +``` + +## 🔎 Implementation + +- [Rule source](../../lib/rules/no-unpublished-require.js) +- [Test source](../../tests/lib/rules/no-unpublished-require.js) diff --git a/docs/description/n_no-unsupported-features.md b/docs/description/n_no-unsupported-features.md new file mode 100644 index 000000000..69a62a275 --- /dev/null +++ b/docs/description/n_no-unsupported-features.md @@ -0,0 +1,308 @@ +# Disallow unsupported ECMAScript features on the specified version (`n/no-unsupported-features`) + +❌ This rule is deprecated. It was replaced by [`n/no-unsupported-features/es-syntax`](no-unsupported-features/es-syntax.md),[`n/no-unsupported-features/es-builtins`](no-unsupported-features/es-builtins.md). + + + +Node.js doesn't support all ECMAScript standard features. +This rule reports when you used unsupported ECMAScript 2015-2018 features on the specified Node.js version. + +> ※ About ECMAScript 2018, this rule reports only features which have arrived at stage 4 until 2018-02-01. +> It needs a major version bump in order to cover newer features. + +## 📖 Rule Details + +⚠️ This rule expects to be used with the following configuration: + +```json +{ + "env": {"es6": true}, + "parserOptions": {"ecmaVersion": 2018} +} +``` + +⚠️ This rule reads the [engines] field of `package.json` to detect Node.js version. + +I recommend a use of the [engines] field since it's the official way to indicate what Node.js versions your module is supporting. +For example of `package.json`: + +```json +{ + "name": "your-module", + "version": "1.0.0", + "engines": { + "node": ">=6.0.0" + } +} +``` + +If the [engines] field is omitted, this rule chooses `4` since it's the minimum version the community is maintaining. + +Examples of 👎 **incorrect** code for this rule: + +```js +/*eslint n/no-unsupported-features: ["error", {version: 4}]*/ +/*eslint-env es6*/ + +function foo(a = 1) { /*error Default Parameters are not supported yet on Node v4.*/ + //... +} + +function foo(...a) { /*error Rest Parameters are not supported yet on Node v4.*/ + //... +} + +var a = [...b]; /*error Spread Operators are not supported yet on Node v4.*/ +var a = /foo/y; /*error RegExp 'y' Flags are not supported yet on Node v4.*/ +var a = /foo/u; /*error RegExp 'u' Flags are not supported yet on Node v4.*/ +var {a, b} = c; /*error Destructuring are not supported yet on Node v4.*/ +var {a, b} = c; /*error Destructuring are not supported yet on Node v4.*/ + +let a = 1; /*error 'let' Declarations in non-strict mode are not supported yet on Node v4.*/ +const a = 1; /*error 'const' Declarations in non-strict mode are not supported yet on Node v4.*/ +class A {} /*error Classes in non-strict mode are not supported yet on Node v4.*/ + +if (a) { + function foo() { /*error Block-Scoped Functions in non-strict mode are not supported yet on Node v4.*/ + //... + } +} + +var p = new Proxy(o, { /*error Proxy is not supported yet on Node v4.*/ + //... +}); +``` + +Examples of 👍 **correct** code for this rule: + +```js +/*eslint n/no-unsupported-features: ["error", {version: 4}]*/ +/*eslint-env es6*/ + +for (var a of list) { + //... +} + +var a = `hello, ${world}!`; + +function foo() { + "use strict"; + + let a = 1; + const b = 2; + + class A { + //... + } + + if (c) { + function bar() { + //... + } + } +} + +var p = new Promise((resolve, reject) => { + //... +}); +``` + +### Options + +```json +{ + "n/no-unsupported-features": ["error", { + "version": 4, + "ignores": [] + }] +} +``` + +#### version + +As mentioned above, this rule reads the [engines] field of `package.json` to detect Node.js version. +Also, you can overwrite the version by `version` option. +The `version` option accepts the following version number: + +- `0.10` +- `0.12` +- `4` +- `5` +- `6` +- `6.5` ... `Symbol.hasInstance` and `Symbol.species`. +- `7` ... Exponential operators, `Object.values`, `Object.entries`, and `Object.getOwnPropertyDescriptors`. +- `7.6` ... Async functions. +- `8` ... Trailing commas in functions. +- `8.3` ... Rest/Spread proeprties. +- `9.0` ... Illegal escape sequences in taggled templates, RegExp 's' flags, RegExp lookbehind assertions, `SharedArrayBuffer`, and `Atomics`. +- `10.0` ... RegExp named capture groups, RegExp Unicode property escapes, Async generators, and `for-await-of` loops. + +#### ignores + +If you are using transpilers, maybe you want to ignore the warnings about some features. +You can use this `ignores` option to ignore the given features. +The `"ignores"` option accepts an array of the following strings. + +- `"syntax"` (group) + - `"defaultParameters"` + - `"restParameters"` + - `"spreadOperators"` + - `"objectLiteralExtensions"` + - `"forOf"` + - `"binaryNumberLiterals"` + - `"octalNumberLiterals"` + - `"templateStrings"` + - `"regexpY"` + - `"regexpU"` + - `"destructuring"` + - `"unicodeCodePointEscapes"` + - `"new.target"` + - `"const"` + - `"let"` + - `"blockScopedFunctions"` + - `"arrowFunctions"` + - `"generatorFunctions"` + - `"classes"` + - `"modules"` + - `"exponentialOperators"` + - `"asyncAwait"` + - `"trailingCommasInFunctions"` + - `"templateLiteralRevision"` + - `"regexpS"` + - `"regexpNamedCaptureGroups"` + - `"regexpLookbehind"` + - `"regexpUnicodeProperties"` + - `"restProperties"` + - `"spreadProperties"` + - `"asyncGenerators"` + - `"forAwaitOf"` +- `"runtime"` (group) + - `"globalObjects"` (group) + - `"typedArrays"` (group) + - `"Int8Array"` + - `"Uint8Array"` + - `"Uint8ClampedArray"` + - `"Int16Array"` + - `"Uint16Array"` + - `"Int32Array"` + - `"Uint32Array"` + - `"Float32Array"` + - `"Float64Array"` + - `"DataView"` + - `"Map"` + - `"Set"` + - `"WeakMap"` + - `"WeakSet"` + - `"Proxy"` + - `"Reflect"` + - `"Promise"` + - `"Symbol"` + - `"SharedArrayBuffer"` + - `"Atomics"` + - `"staticMethods"` (group) + - `"Object.*"` (group) + - `"Object.assign"` + - `"Object.is"` + - `"Object.getOwnPropertySymbols"` + - `"Object.setPrototypeOf"` + - `"Object.values"` + - `"Object.entries"` + - `"Object.getOwnPropertyDescriptors"` + - `"String.*"` (group) + - `"String.raw"` + - `"String.fromCodePoint"` + - `"Array.*"` (group) + - `"Array.from"` + - `"Array.of"` + - `"Number.*"` (group) + - `"Number.isFinite"` + - `"Number.isInteger"` + - `"Number.isSafeInteger"` + - `"Number.isNaN"` + - `"Number.EPSILON"` + - `"Number.MIN_SAFE_INTEGER"` + - `"Number.MAX_SAFE_INTEGER"` + - `"Math.*"` (group) + - `"Math.clz32"` + - `"Math.imul"` + - `"Math.sign"` + - `"Math.log10"` + - `"Math.log2"` + - `"Math.log1p"` + - `"Math.expm1"` + - `"Math.cosh"` + - `"Math.sinh"` + - `"Math.tanh"` + - `"Math.acosh"` + - `"Math.asinh"` + - `"Math.atanh"` + - `"Math.trunc"` + - `"Math.fround"` + - `"Math.cbrt"` + - `"Math.hypot"` + - `"Symbol.*"` (group) + - `"Symbol.hasInstance"` + - `"Symbol.isConcatSpreadablec"` + - `"Symbol.iterator"` + - `"Symbol.species"` + - `"Symbol.replace"` + - `"Symbol.search"` + - `"Symbol.split"` + - `"Symbol.match"` + - `"Symbol.toPrimitive"` + - `"Symbol.toStringTag"` + - `"Symbol.unscopables"` + - `"Atomics.*"` (group) + - `"Atomics.add"` + - `"Atomics.and"` + - `"Atomics.compareExchange"` + - `"Atomics.exchange"` + - `"Atomics.wait"` + - `"Atomics.wake"` + - `"Atomics.isLockFree"` + - `"Atomics.load"` + - `"Atomics.or"` + - `"Atomics.store"` + - `"Atomics.sub"` + - `"Atomics.xor"` + - `"extends"` (group) + - `"extendsArray"` + - `"extendsRegExp"` + - `"extendsFunction"` + - `"extendsPromise"` + - `"extendsBoolean"` + - `"extendsNumber"` + - `"extendsString"` + - `"extendsMap"` + - `"extendsSet"` + - `"extendsNull"` + +If a group value is given, all sub items of the value are ignored. +e.g. if `"String.*"` is given then `"String.raw"` and `"String.fromCodePoint"` are ignored. + +Examples of 👍 **correct** code for the `"ignores"` option: + +```js +/*eslint n/no-unsupported-features: ["error", {version: 4, ignores: ["defaultParameters"]}]*/ +/*eslint-env es6*/ + +function foo(a = 1) { + //... +} +``` + +## ⚠️ Known Limitations + +This rule cannot report non-static things. +E.g., a use of instance methods. + +## 📚 Further Reading + +- + +[engines]: https://docs.npmjs.com/files/package.json#engines + +## 🔎 Implementation + +- [Rule source](../../lib/rules/no-unsupported-features.js) +- [Test source](../../tests/lib/rules/no-unsupported-features.js) diff --git a/docs/description/n_no-unsupported-features_es-builtins.md b/docs/description/n_no-unsupported-features_es-builtins.md new file mode 100644 index 000000000..4c6e438f1 --- /dev/null +++ b/docs/description/n_no-unsupported-features_es-builtins.md @@ -0,0 +1,167 @@ +# Disallow unsupported ECMAScript built-ins on the specified version (`n/no-unsupported-features/es-builtins`) + +💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/eslint-community/eslint-plugin-n#-configs). + + + +ECMAScript standard is updating every two months. +You can check [node.green](https://node.green/) to know which Node.js version supports each ECMAScript feature. + +This rule reports unsupported ECMAScript built-in variables on the configured Node.js version as lint errors. +Editor integrations of ESLint would be useful to know it in real-time. + +## 📖 Rule Details + +### Supported ECMAScript features + +This rule supports ECMAScript 2019 and proposals that have been approved as Stage 4 by August 2019. +See also [TC39 finished proposals](https://github.com/tc39/proposals/blob/master/finished-proposals.md). + +### Configured Node.js version range + +[Configured Node.js version range](../../../README.md#configured-nodejs-version-range) + +### Options + +```json +{ + "n/no-unsupported-features/es-builtins": ["error", { + "version": ">=16.0.0", + "ignores": [] + }] +} +``` + +#### version + +As mentioned above, this rule reads the [`engines`] field of `package.json`. +But, you can overwrite the version by `version` option. + +The `version` option accepts [the valid version range of `node-semver`](https://github.com/npm/node-semver#range-grammar). + +#### ignores + +If you are using transpilers, maybe you want to ignore the warnings about some features. +You can use this `ignores` option to ignore the given features. + +The `"ignores"` option accepts an array of the following strings. + +
+ +**ES2020:** + +- `"BigInt"` +- `"BigInt64Array"` +- `"BigUint64Array"` +- `"Promise.allSettled"` +- `"globalThis"` + +**ES2019:** + +- `"Object.fromEntries"` + +**ES2017:** + +- `"Atomics"` +- `"Object.values"` +- `"Object.entries"` +- `"Object.getOwnPropertyDescriptors"` +- `"SharedArrayBuffer"` + +**ES2015:** + +- `"Array.from"` +- `"Array.of"` +- `"Map"` +- `"Math.acosh"` +- `"Math.asinh"` +- `"Math.atanh"` +- `"Math.cbrt"` +- `"Math.clz32"` +- `"Math.cosh"` +- `"Math.expm1"` +- `"Math.fround"` +- `"Math.hypot"` +- `"Math.imul"` +- `"Math.log10"` +- `"Math.log1p"` +- `"Math.log2"` +- `"Math.sign"` +- `"Math.sinh"` +- `"Math.tanh"` +- `"Math.trunc"` +- `"Number.EPSILON"` +- `"Number.isFinite"` +- `"Number.isInteger"` +- `"Number.isNaN"` +- `"Number.isSafeInteger"` +- `"Number.MAX_SAFE_INTEGER"` +- `"Number.MIN_SAFE_INTEGER"` +- `"Number.parseFloat"` +- `"Number.parseInt"` +- `"Object.assign"` +- `"Object.getOwnPropertySymbols"` +- `"Object.is"` +- `"Object.setPrototypeOf"` +- `"Promise"` +- `"Proxy"` +- `"Reflect"` +- `"Set"` +- `"String.fromCodePoint"` +- `"String.raw"` +- `"Symbol"` +- `"Int8Array"` +- `"Uint8Array"` +- `"Uint8ClampedArray"` +- `"Int16Array"` +- `"Uint16Array"` +- `"Int32Array"` +- `"Uint32Array"` +- `"Float32Array"` +- `"Float64Array"` +- `"DataView"` +- `"WeakMap"` +- `"WeakSet"` + +
+ +### Shared Settings + +The following options can be set by [shared settings](http://eslint.org/docs/user-guide/configuring.html#adding-shared-settings). +Several rules have the same option, but we can set this option at once. + +- `version` + +For Example: + +```json +{ + "settings": { + "node": { + "version": ">=16.0.0", + } + }, + "rules": { + "n/no-unsupported-features/es-builtins": ["error", { + "ignores": [] + }] + } +} +``` + +### Known limitations + +This rule cannot find non-static things. +For example: + +- New properties and methods of instances. +- New parameters of functions. +- New `options` properties of function parameters. +- New events. + +[`engines`]: https://docs.npmjs.com/files/package.json#engines + +## 🔎 Implementation + +- [Rule source](../../../lib/rules/no-unsupported-features/es-builtins.js) +- [Test source](../../../tests/lib/rules/no-unsupported-features/es-builtins.js) diff --git a/docs/description/n_no-unsupported-features_es-syntax.md b/docs/description/n_no-unsupported-features_es-syntax.md new file mode 100644 index 000000000..e4f51daae --- /dev/null +++ b/docs/description/n_no-unsupported-features_es-syntax.md @@ -0,0 +1,140 @@ +# Disallow unsupported ECMAScript syntax on the specified version (`n/no-unsupported-features/es-syntax`) + +💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/eslint-community/eslint-plugin-n#-configs). + + + +ECMAScript standard is updating every two months. +You can check [node.green](https://node.green/) to know which Node.js version supports each ECMAScript feature. + +This rule reports unsupported ECMAScript syntax on the configured Node.js version as lint errors. +Editor integrations of ESLint would be useful to know it in real-time. + +## 📖 Rule Details + +### Supported ECMAScript features + +This rule supports ECMAScript 2019 and proposals that have been approved as Stage 4 by August 2019. +See also [TC39 finished proposals](https://github.com/tc39/proposals/blob/master/finished-proposals.md). + +Please configure your `.eslintrc` file to succeed to succeed in parsing the syntax. +For example, set `2020` to `parserOptions.ecmaVersion`. + +### Configured Node.js version range + +[Configured Node.js version range](../../../README.md#configured-nodejs-version-range) + +### Options + +```json +{ + "n/no-unsupported-features/es-syntax": ["error", { + "version": ">=16.0.0", + "ignores": [] + }] +} +``` + +#### version + +As mentioned above, this rule reads the [`engines`] field of `package.json`. +But, you can overwrite the version by `version` option. + +The `version` option accepts [the valid version range of `node-semver`](https://github.com/npm/node-semver#range-grammar). + +#### ignores + +If you are using transpilers, maybe you want to ignore the warnings about some features. +You can use this `ignores` option to ignore the given features. + +The `"ignores"` option accepts an array of the following strings. + +
+ +**ES2020:** + +- `"bigint"` +- `"dynamicImport"` +- `"optionalChaining"` +- `"nullishCoalescingOperators"` + +**ES2019:** + +- `"jsonSuperset"` +- `"optionalCatchBinding"` + +**ES2018:** + +- `"asyncIteration"` +- `"malformedTemplateLiterals"` +- `"regexpLookbehind"` +- `"regexpNamedCaptureGroups"` +- `"regexpS"` +- `"regexpUnicodeProperties"` +- `"restSpreadProperties"` + +**ES2017:** + +- `"asyncFunctions"` +- `"trailingCommasInFunctions"` + +**ES2016:** + +- `"exponentialOperators"` + +**ES2015:** + +- `"arrowFunctions"` +- `"binaryNumericLiterals"` +- `"blockScopedFunctions"` +- `"blockScopedVariables"` +- `"classes"` +- `"computedProperties"` +- `"defaultParameters"` +- `"destructuring"` +- `"forOfLoops"` +- `"generators"` +- `"modules"` +- `"new.target"` +- `"objectSuperProperties"` +- `"octalNumericLiterals"` +- `"propertyShorthands"` +- `"regexpU"` +- `"regexpY"` +- `"restParameters"` +- `"spreadElements"` +- `"templateLiterals"` +- `"unicodeCodePointEscapes"` + +
+ +[`engines`]: https://docs.npmjs.com/files/package.json#engines + +### Shared Settings + +The following options can be set by [shared settings](http://eslint.org/docs/user-guide/configuring.html#adding-shared-settings). +Several rules have the same option, but we can set this option at once. + +- `version` + +For Example: + +```json +{ + "settings": { + "node": { + "version": ">=16.0.0", + } + }, + "rules": { + "n/no-unsupported-features/es-syntax": ["error", { + "ignores": [] + }] + } +} +``` + +## 🔎 Implementation + +- [Rule source](../../../lib/rules/no-unsupported-features/es-syntax.js) +- [Test source](../../../tests/lib/rules/no-unsupported-features/es-syntax.js) diff --git a/docs/description/n_no-unsupported-features_node-builtins.md b/docs/description/n_no-unsupported-features_node-builtins.md new file mode 100644 index 000000000..a31dfc3d0 --- /dev/null +++ b/docs/description/n_no-unsupported-features_node-builtins.md @@ -0,0 +1,351 @@ +# Disallow unsupported Node.js built-in APIs on the specified version (`n/no-unsupported-features/node-builtins`) + +💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/eslint-community/eslint-plugin-n#-configs). + + + +Node.js community is improving built-in APIs continuously. +You can check [Node.js Documentation](https://nodejs.org/api/) to know which Node.js version supports each Node.js API. + +This rule reports unsupported Node.js built-in APIs on the configured Node.js version as lint errors. +Editor integrations of ESLint would be useful to know it in real-time. + +## 📖 Rule Details + +This rule reports APIs of Node.js built-in APIs on the basis of [Node.js v13.2.0 Documentation](https://nodejs.org/docs/v13.2.0/api/). + +### Configured Node.js version range + +[Configured Node.js version range](../../../README.md#configured-nodejs-version-range) + +### Options + +```json +{ + "n/no-unsupported-features/node-builtins": ["error", { + "version": ">=16.0.0", + "ignores": [] + }] +} +``` + +#### version + +As mentioned above, this rule reads the [`engines`] field of `package.json`. +But, you can overwrite the version by `version` option. + +The `version` option accepts [the valid version range of `node-semver`](https://github.com/npm/node-semver#range-grammar). + +#### ignores + +If you are using transpilers, maybe you want to ignore the warnings about some features. +You can use this `ignores` option to ignore the given features. + +The `"ignores"` option accepts an array of the following strings. + +
+ +**Globals:** + +- `"Buffer.alloc"` +- `"Buffer.allocUnsafe"` +- `"Buffer.allocUnsafeSlow"` +- `"Buffer.from"` +- `"TextDecoder"` +- `"TextEncoder"` +- `"URL"` +- `"URLSearchParams"` +- `"console.clear"` +- `"console.count"` +- `"console.countReset"` +- `"console.debug"` +- `"console.dirxml"` +- `"console.group"` +- `"console.groupCollapsed"` +- `"console.groupEnd"` +- `"console.table"` +- `"console.markTimeline"` +- `"console.profile"` +- `"console.profileEnd"` +- `"console.timeLog"` +- `"console.timeStamp"` +- `"console.timeline"` +- `"console.timelineEnd"` +- `"process.allowedNodeEnvironmentFlags"` +- `"process.argv0"` +- `"process.channel"` +- `"process.cpuUsage"` +- `"process.emitWarning"` +- `"process.getegid"` +- `"process.geteuid"` +- `"process.hasUncaughtExceptionCaptureCallback"` +- `"process.hrtime.bigint"` +- `"process.ppid"` +- `"process.release"` +- `"process.report"` +- `"process.setegid"` +- `"process.seteuid"` +- `"process.setUncaughtExceptionCaptureCallback"` +- `"process.stdout.getColorDepth"` +- `"process.stdout.hasColor"` +- `"process.stderr.getColorDepth"` +- `"process.stderr.hasColor"` +- `"queueMicrotask"` +- `"require.resolve.paths"` + +**`assert` module:** + +- `"assert.deepStrictEqual"` +- `"assert.doesNotReject"` +- `"assert.notDeepStrictEqual"` +- `"assert.rejects"` +- `"assert.strict"` +- `"assert.strict.doesNotReject"` +- `"assert.strict.rejects"` + +**`async_hooks` module:** + +- `"async_hooks"` +- `"async_hooks.createHook"` + +**`buffer` module:** + +- `"buffer.Buffer.alloc"` +- `"buffer.Buffer.allocUnsafe"` +- `"buffer.Buffer.allocUnsafeSlow"` +- `"buffer.Buffer.from"` +- `"buffer.constants"` +- `"buffer.kMaxLength"` +- `"buffer.transcode"` + +**`child_process` module:** + +- `"child_process.ChildProcess"` + +**`console` module:** + +- `"console.clear"` +- `"console.count"` +- `"console.countReset"` +- `"console.debug"` +- `"console.dirxml"` +- `"console.group"` +- `"console.groupCollapsed"` +- `"console.groupEnd"` +- `"console.table"` +- `"console.markTimeline"` +- `"console.profile"` +- `"console.profileEnd"` +- `"console.timeLog"` +- `"console.timeStamp"` +- `"console.timeline"` +- `"console.timelineEnd"` + +**`crypto` module:** + +- `"crypto.Certificate.exportChallenge"` +- `"crypto.Certificate.exportPublicKey"` +- `"crypto.Certificate.verifySpkac"` +- `"crypto.KeyObject"` +- `"crypto.createPrivateKey"` +- `"crypto.createPublicKey"` +- `"crypto.createSecretKey"` +- `"crypto.constants"` +- `"crypto.fips"` +- `"crypto.generateKeyPair"` +- `"crypto.generateKeyPairSync"` +- `"crypto.getCurves"` +- `"crypto.getFips"` +- `"crypto.privateEncrypt"` +- `"crypto.publicDecrypt"` +- `"crypto.randomFillSync"` +- `"crypto.randomFill"` +- `"crypto.scrypt"` +- `"crypto.scryptSync"` +- `"crypto.setFips"` +- `"crypto.sign"` +- `"crypto.timingSafeEqual"` +- `"crypto.verify"` + +**`dns` module:** + +- `"dns.Resolver"` +- `"dns.resolvePtr"` +- `"dns.promises"` + +**`events` module:** + +- `"events.EventEmitter.once"` +- `"events.once"` + +**`fs` module:** + +- `"fs.Dirent"` +- `"fs.copyFile"` +- `"fs.copyFileSync"` +- `"fs.mkdtemp"` +- `"fs.mkdtempSync"` +- `"fs.realpath.native"` +- `"fs.realpathSync.native"` +- `"fs.promises"` +- `"fs.writev"` +- `"fs.writevSync"` + +**`http2` module:** + +- `"http2"` + +**`inspector` module:** + +- `"inspector"` + +**`module` module:** + +- `"module.Module.builtinModules"` +- `"module.Module.createRequireFromPath"` +- `"module.Module.createRequire"` +- `"module.Module.syncBuiltinESMExports"` +- `"module.builtinModules"` +- `"module.createRequireFromPath"` +- `"module.createRequire"` +- `"module.syncBuiltinESMExports"` + +**`os` module:** + +- `"os.constants"` +- `"os.constants.priority"` +- `"os.getPriority"` +- `"os.homedir"` +- `"os.setPriority"` +- `"os.userInfo"` + +**`path` module:** + +- `"path.toNamespacedPath"` + +**`perf_hooks` module:** + +- `"perf_hooks"` +- `"perf_hooks.monitorEventLoopDelay"` + +**`process` module:** + +- `"process.allowedNodeEnvironmentFlags"` +- `"process.argv0"` +- `"process.channel"` +- `"process.cpuUsage"` +- `"process.emitWarning"` +- `"process.getegid"` +- `"process.geteuid"` +- `"process.hasUncaughtExceptionCaptureCallback"` +- `"process.hrtime.bigint"` +- `"process.ppid"` +- `"process.release"` +- `"process.report"` +- `"process.resourceUsage"` +- `"process.setegid"` +- `"process.seteuid"` +- `"process.setUncaughtExceptionCaptureCallback"` +- `"process.stdout.getColorDepth"` +- `"process.stdout.hasColor"` +- `"process.stderr.getColorDepth"` +- `"process.stderr.hasColor"` + +**`stream` module:** + +- `"stream.Readable.from"` +- `"stream.finished"` +- `"stream.pipeline"` + +**`trace_events` module:** + +- `"trace_events"` + +**`url` module:** + +- `"url.URL"` +- `"url.URLSearchParams"` +- `"url.domainToASCII"` +- `"url.domainToUnicode"` + +**`util` module:** + +- `"util.callbackify"` +- `"util.formatWithOptions"` +- `"util.getSystemErrorName"` +- `"util.inspect.custom"` +- `"util.inspect.defaultOptions"` +- `"util.inspect.replDefaults"` +- `"util.isDeepStrictEqual"` +- `"util.promisify"` +- `"util.TextDecoder"` +- `"util.TextEncoder"` +- `"util.types"` +- `"util.types.isBoxedPrimitive"` + +**`v8` module:** + +- `"v8"` +- `"v8.DefaultDeserializer"` +- `"v8.DefaultSerializer"` +- `"v8.Deserializer"` +- `"v8.Serializer"` +- `"v8.cachedDataVersionTag"` +- `"v8.deserialize"` +- `"v8.getHeapCodeStatistics"` +- `"v8.getHeapSnapshot"` +- `"v8.getHeapSpaceStatistics"` +- `"v8.serialize"` +- `"v8.writeHeapSnapshot"` + +**`vm` module:** + +- `"vm.Module"` +- `"vm.compileFunction"` + +**`worker_threads` module:** + +- `"worker_threads"` + +
+ +### Shared Settings + +The following options can be set by [shared settings](http://eslint.org/docs/user-guide/configuring.html#adding-shared-settings). +Several rules have the same option, but we can set this option at once. + +- `version` + +For Example: + +```json +{ + "settings": { + "node": { + "version": ">=16.0.0", + } + }, + "rules": { + "n/no-unsupported-features/node-builtins": ["error", { + "ignores": [] + }] + } +} +``` + +### Known limitations + +This rule cannot find non-static things. +For example: + +- New properties and methods of instances. +- New parameters of functions. +- New `options` properties of function parameters. +- New events. + +[`engines`]: https://docs.npmjs.com/files/package.json#engines + +## 🔎 Implementation + +- [Rule source](../../../lib/rules/no-unsupported-features/node-builtins.js) +- [Test source](../../../tests/lib/rules/no-unsupported-features/node-builtins.js) diff --git a/docs/description/n_prefer-global_buffer.md b/docs/description/n_prefer-global_buffer.md new file mode 100644 index 000000000..8acd74178 --- /dev/null +++ b/docs/description/n_prefer-global_buffer.md @@ -0,0 +1,71 @@ +# Enforce either `Buffer` or `require("buffer").Buffer` (`n/prefer-global/buffer`) + + + +The `Buffer` class of `buffer` module is defined as a global variable. + +```js +console.log(Buffer === require("buffer").Buffer) //→ true +``` + +It will be readable if we use either `Buffer` consistently. + +## 📖 Rule Details + +This rule enforces which `Buffer` we should use. + +### Options + +This rule has a string option. + +```json +{ + "n/prefer-global/buffer": ["error", "always" | "never"] +} +``` + +- `"always"` (default) ... enforces to use the global variable `Buffer` rather than `require("buffer").Buffer`. +- `"never"` ... enforces to use `require("buffer").Buffer` rather than the global variable `Buffer`. + +#### always + +Examples of 👎 **incorrect** code for this rule: + +```js +/*eslint n/prefer-global/buffer: [error]*/ + +const { Buffer } = require("buffer") +const b = Buffer.alloc(16) +``` + +Examples of 👍 **correct** code for this rule: + +```js +/*eslint n/prefer-global/buffer: [error]*/ + +const b = Buffer.alloc(16) +``` + +#### never + +Examples of 👎 **incorrect** code for the `"never"` option: + +```js +/*eslint n/prefer-global/buffer: [error, never]*/ + +const b = Buffer.alloc(16) +``` + +Examples of 👍 **correct** code for the `"never"` option: + +```js +/*eslint n/prefer-global/buffer: [error, never]*/ + +const { Buffer } = require("buffer") +const b = Buffer.alloc(16) +``` + +## 🔎 Implementation + +- [Rule source](../../../lib/rules/prefer-global/buffer.js) +- [Test source](../../../tests/lib/rules/prefer-global/buffer.js) diff --git a/docs/description/n_prefer-global_console.md b/docs/description/n_prefer-global_console.md new file mode 100644 index 000000000..f14fd6c94 --- /dev/null +++ b/docs/description/n_prefer-global_console.md @@ -0,0 +1,71 @@ +# Enforce either `console` or `require("console")` (`n/prefer-global/console`) + + + +The `console` module is defined as a global variable. + +```js +console.log(console === require("console")) //→ true +``` + +It will be readable if we use either `console` consistently. + +## 📖 Rule Details + +This rule enforces which `console` we should use. + +### Options + +This rule has a string option. + +```json +{ + "n/prefer-global/console": ["error", "always" | "never"] +} +``` + +- `"always"` (default) ... enforces to use the global variable `console` rather than `require("console")`. +- `"never"` ... enforces to use `require("console")` rather than the global variable `console`. + +#### always + +Examples of 👎 **incorrect** code for this rule: + +```js +/*eslint n/prefer-global/console: [error]*/ + +const console = require("console") +console.log("hello") +``` + +Examples of 👍 **correct** code for this rule: + +```js +/*eslint n/prefer-global/console: [error]*/ + +console.log("hello") +``` + +#### never + +Examples of 👎 **incorrect** code for the `"never"` option: + +```js +/*eslint n/prefer-global/console: [error, never]*/ + +console.log("hello") +``` + +Examples of 👍 **correct** code for the `"never"` option: + +```js +/*eslint n/prefer-global/console: [error, never]*/ + +const console = require("console") +console.log("hello") +``` + +## 🔎 Implementation + +- [Rule source](../../../lib/rules/prefer-global/console.js) +- [Test source](../../../tests/lib/rules/prefer-global/console.js) diff --git a/docs/description/n_prefer-global_process.md b/docs/description/n_prefer-global_process.md new file mode 100644 index 000000000..d99e27f51 --- /dev/null +++ b/docs/description/n_prefer-global_process.md @@ -0,0 +1,71 @@ +# Enforce either `process` or `require("process")` (`n/prefer-global/process`) + + + +The `process` module is defined as a global variable. + +```js +process.log(process === require("process")) //→ true +``` + +It will be readable if we use either `process` consistently. + +## 📖 Rule Details + +This rule enforces which `process` we should use. + +### Options + +This rule has a string option. + +```json +{ + "n/prefer-global/process": ["error", "always" | "never"] +} +``` + +- `"always"` (default) ... enforces to use the global variable `process` rather than `require("process")`. +- `"never"` ... enforces to use `require("process")` rather than the global variable `process`. + +#### always + +Examples of 👎 **incorrect** code for this rule: + +```js +/*eslint n/prefer-global/process: [error]*/ + +const process = require("process") +process.exit(0) +``` + +Examples of 👍 **correct** code for this rule: + +```js +/*eslint n/prefer-global/process: [error]*/ + +process.exit(0) +``` + +#### never + +Examples of 👎 **incorrect** code for the `"never"` option: + +```js +/*eslint n/prefer-global/process: [error, never]*/ + +process.exit(0) +``` + +Examples of 👍 **correct** code for the `"never"` option: + +```js +/*eslint n/prefer-global/process: [error, never]*/ + +const process = require("process") +process.exit(0) +``` + +## 🔎 Implementation + +- [Rule source](../../../lib/rules/prefer-global/process.js) +- [Test source](../../../tests/lib/rules/prefer-global/process.js) diff --git a/docs/description/n_prefer-global_text-decoder.md b/docs/description/n_prefer-global_text-decoder.md new file mode 100644 index 000000000..eeb523068 --- /dev/null +++ b/docs/description/n_prefer-global_text-decoder.md @@ -0,0 +1,71 @@ +# Enforce either `TextDecoder` or `require("util").TextDecoder` (`n/prefer-global/text-decoder`) + + + +The `TextDecoder` class of `util` module is defined as a global variable. + +```js +console.log(TextDecoder === require("util").TextDecoder) //→ true +``` + +It will be readable if we use either `TextDecoder` consistently. + +## 📖 Rule Details + +This rule enforces which `TextDecoder` we should use. + +### Options + +This rule has a string option. + +```json +{ + "n/prefer-global/text-decoder": ["error", "always" | "never"] +} +``` + +- `"always"` (default) ... enforces to use the global variable `TextDecoder` rather than `require("util").TextDecoder`. +- `"never"` ... enforces to use `require("util").TextDecoder` rather than the global variable `TextDecoder`. + +#### always + +Examples of 👎 **incorrect** code for this rule: + +```js +/*eslint n/prefer-global/text-decoder: [error]*/ + +const { TextDecoder } = require("util") +const u = new TextDecoder(s) +``` + +Examples of 👍 **correct** code for this rule: + +```js +/*eslint n/prefer-global/text-decoder: [error]*/ + +const u = new TextDecoder(s) +``` + +#### never + +Examples of 👎 **incorrect** code for the `"never"` option: + +```js +/*eslint n/prefer-global/text-decoder: [error, never]*/ + +const u = new TextDecoder(s) +``` + +Examples of 👍 **correct** code for the `"never"` option: + +```js +/*eslint n/prefer-global/text-decoder: [error, never]*/ + +const { TextDecoder } = require("util") +const u = new TextDecoder(s) +``` + +## 🔎 Implementation + +- [Rule source](../../../lib/rules/prefer-global/text-decoder.js) +- [Test source](../../../tests/lib/rules/prefer-global/text-decoder.js) diff --git a/docs/description/n_prefer-global_text-encoder.md b/docs/description/n_prefer-global_text-encoder.md new file mode 100644 index 000000000..371f9b3e2 --- /dev/null +++ b/docs/description/n_prefer-global_text-encoder.md @@ -0,0 +1,71 @@ +# Enforce either `TextEncoder` or `require("util").TextEncoder` (`n/prefer-global/text-encoder`) + + + +The `TextEncoder` class of `util` module is defined as a global variable. + +```js +console.log(TextEncoder === require("util").TextEncoder) //→ true +``` + +It will be readable if we use either `TextEncoder` consistently. + +## 📖 Rule Details + +This rule enforces which `TextEncoder` we should use. + +### Options + +This rule has a string option. + +```json +{ + "n/prefer-global/text-encoder": ["error", "always" | "never"] +} +``` + +- `"always"` (default) ... enforces to use the global variable `TextEncoder` rather than `require("util").TextEncoder`. +- `"never"` ... enforces to use `require("util").TextEncoder` rather than the global variable `TextEncoder`. + +#### always + +Examples of 👎 **incorrect** code for this rule: + +```js +/*eslint n/prefer-global/text-encoder: [error]*/ + +const { TextEncoder } = require("util") +const u = new TextEncoder(s) +``` + +Examples of 👍 **correct** code for this rule: + +```js +/*eslint n/prefer-global/text-encoder: [error]*/ + +const u = new TextEncoder(s) +``` + +#### never + +Examples of 👎 **incorrect** code for the `"never"` option: + +```js +/*eslint n/prefer-global/text-encoder: [error, never]*/ + +const u = new TextEncoder(s) +``` + +Examples of 👍 **correct** code for the `"never"` option: + +```js +/*eslint n/prefer-global/text-encoder: [error, never]*/ + +const { TextEncoder } = require("util") +const u = new TextEncoder(s) +``` + +## 🔎 Implementation + +- [Rule source](../../../lib/rules/prefer-global/text-encoder.js) +- [Test source](../../../tests/lib/rules/prefer-global/text-encoder.js) diff --git a/docs/description/n_prefer-global_url-search-params.md b/docs/description/n_prefer-global_url-search-params.md new file mode 100644 index 000000000..e2ff4b174 --- /dev/null +++ b/docs/description/n_prefer-global_url-search-params.md @@ -0,0 +1,71 @@ +# Enforce either `URLSearchParams` or `require("url").URLSearchParams` (`n/prefer-global/url-search-params`) + + + +The `URLSearchParams` class of `url` module is defined as a global variable. + +```js +console.log(URLSearchParams === require("url").URLSearchParams) //→ true +``` + +It will be readable if we use either `URLSearchParams` consistently. + +## 📖 Rule Details + +This rule enforces which `URLSearchParams` we should use. + +### Options + +This rule has a string option. + +```json +{ + "n/prefer-global/url-search-params": ["error", "always" | "never"] +} +``` + +- `"always"` (default) ... enforces to use the global variable `URLSearchParams` rather than `require("url").URLSearchParams`. +- `"never"` ... enforces to use `require("url").URLSearchParams` rather than the global variable `URLSearchParams`. + +#### always + +Examples of 👎 **incorrect** code for this rule: + +```js +/*eslint n/prefer-global/url-search-params: [error]*/ + +const { URLSearchParams } = require("url") +const u = new URLSearchParams(s) +``` + +Examples of 👍 **correct** code for this rule: + +```js +/*eslint n/prefer-global/url-search-params: [error]*/ + +const u = new URLSearchParams(s) +``` + +#### never + +Examples of 👎 **incorrect** code for the `"never"` option: + +```js +/*eslint n/prefer-global/url-search-params: [error, never]*/ + +const u = new URLSearchParams(s) +``` + +Examples of 👍 **correct** code for the `"never"` option: + +```js +/*eslint n/prefer-global/url-search-params: [error, never]*/ + +const { URLSearchParams } = require("url") +const u = new URLSearchParams(s) +``` + +## 🔎 Implementation + +- [Rule source](../../../lib/rules/prefer-global/url-search-params.js) +- [Test source](../../../tests/lib/rules/prefer-global/url-search-params.js) diff --git a/docs/description/n_prefer-global_url.md b/docs/description/n_prefer-global_url.md new file mode 100644 index 000000000..a38ab8f6e --- /dev/null +++ b/docs/description/n_prefer-global_url.md @@ -0,0 +1,71 @@ +# Enforce either `URL` or `require("url").URL` (`n/prefer-global/url`) + + + +The `URL` class of `url` module is defined as a global variable. + +```js +console.log(URL === require("url").URL) //→ true +``` + +It will be readable if we use either `URL` consistently. + +## 📖 Rule Details + +This rule enforces which `URL` we should use. + +### Options + +This rule has a string option. + +```json +{ + "n/prefer-global/url": ["error", "always" | "never"] +} +``` + +- `"always"` (default) ... enforces to use the global variable `URL` rather than `require("url").URL`. +- `"never"` ... enforces to use `require("url").URL` rather than the global variable `URL`. + +#### always + +Examples of 👎 **incorrect** code for this rule: + +```js +/*eslint n/prefer-global/url: [error]*/ + +const { URL } = require("url") +const u = new URL(s) +``` + +Examples of 👍 **correct** code for this rule: + +```js +/*eslint n/prefer-global/url: [error]*/ + +const u = new URL(s) +``` + +#### never + +Examples of 👎 **incorrect** code for the `"never"` option: + +```js +/*eslint n/prefer-global/url: [error, never]*/ + +const u = new URL(s) +``` + +Examples of 👍 **correct** code for the `"never"` option: + +```js +/*eslint n/prefer-global/url: [error, never]*/ + +const { URL } = require("url") +const u = new URL(s) +``` + +## 🔎 Implementation + +- [Rule source](../../../lib/rules/prefer-global/url.js) +- [Test source](../../../tests/lib/rules/prefer-global/url.js) diff --git a/docs/description/n_prefer-promises_dns.md b/docs/description/n_prefer-promises_dns.md new file mode 100644 index 000000000..6e0a73ff1 --- /dev/null +++ b/docs/description/n_prefer-promises_dns.md @@ -0,0 +1,61 @@ +# Enforce `require("dns").promises` (`n/prefer-promises/dns`) + + + +Since Node.js v11.14.0, `require("dns").promises` API has been stable. +Promise API and `async`/`await` syntax will make code more readable than callback API. + +## 📖 Rule Details + +This rule disallows callback API in favor of promise API. + +Examples of 👎 **incorrect** code for this rule: + +```js +/*eslint n/prefer-promises/dns: [error]*/ +const dns = require("dns") + +function lookup(hostname) { + dns.lookup(hostname, (error, address, family) => { + //... + }) +} +``` + +```js +/*eslint n/prefer-promises/dns: [error]*/ +import dns from "dns" + +function lookup(hostname) { + dns.lookup(hostname, (error, address, family) => { + //... + }) +} +``` + +Examples of 👍 **correct** code for this rule: + +```js +/*eslint n/prefer-promises/dns: [error]*/ +const { promises: dns } = require("dns") + +async function lookup(hostname) { + const { address, family } = await dns.lookup(hostname) + //... +} +``` + +```js +/*eslint n/prefer-promises/dns: [error]*/ +import { promises as dns } from "dns" + +async function lookup(hostname) { + const { address, family } = await dns.lookup(hostname) + //... +} +``` + +## 🔎 Implementation + +- [Rule source](../../../lib/rules/prefer-promises/dns.js) +- [Test source](../../../tests/lib/rules/prefer-promises/dns.js) diff --git a/docs/description/n_prefer-promises_fs.md b/docs/description/n_prefer-promises_fs.md new file mode 100644 index 000000000..e38130f4b --- /dev/null +++ b/docs/description/n_prefer-promises_fs.md @@ -0,0 +1,61 @@ +# Enforce `require("fs").promises` (`n/prefer-promises/fs`) + + + +Since Node.js v11.14.0, `require("fs").promises` API has been stable. +Promise API and `async`/`await` syntax will make code more readable than callback API. + +## 📖 Rule Details + +This rule disallows callback API in favor of promise API. + +Examples of 👎 **incorrect** code for this rule: + +```js +/*eslint n/prefer-promises/fs: [error]*/ +const fs = require("fs") + +function readData(filePath) { + fs.readFile(filePath, "utf8", (error, content) => { + //... + }) +} +``` + +```js +/*eslint n/prefer-promises/fs: [error]*/ +import fs from "fs" + +function readData(filePath) { + fs.readFile(filePath, "utf8", (error, content) => { + //... + }) +} +``` + +Examples of 👍 **correct** code for this rule: + +```js +/*eslint n/prefer-promises/fs: [error]*/ +const { promises: fs } = require("fs") + +async function readData(filePath) { + const content = await fs.readFile(filePath, "utf8") + //... +} +``` + +```js +/*eslint n/prefer-promises/fs: [error]*/ +import { promises as fs } from "fs" + +async function readData(filePath) { + const content = await fs.readFile(filePath, "utf8") + //... +} +``` + +## 🔎 Implementation + +- [Rule source](../../../lib/rules/prefer-promises/fs.js) +- [Test source](../../../tests/lib/rules/prefer-promises/fs.js) diff --git a/docs/description/n_process-exit-as-throw.md b/docs/description/n_process-exit-as-throw.md new file mode 100644 index 000000000..aaf0ef139 --- /dev/null +++ b/docs/description/n_process-exit-as-throw.md @@ -0,0 +1,38 @@ +# Require that `process.exit()` expressions use the same code path as `throw` (`n/process-exit-as-throw`) + +💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/eslint-community/eslint-plugin-n#-configs). + + + +## 📖 Rule Details + +```js +function foo(a) { + if (a) { + return new Bar(); + } else { + process.exit(1); + } +} +``` + +ESLint does not address `process.exit()` as stop in code path analysis, then [consistent-return] rule will warn the above code. + +If you turn this rule on, ESLint comes to address `process.exit()` as throw in code path analysis. So, above code will get expected code path. + +This rule itself never warn code. + +## 📚 Related Rules + +- [consistent-return] +- [no-fallthrough] +- [no-unreachable] + +[consistent-return]: http://eslint.org/docs/rules/consistent-return +[no-fallthrough]: http://eslint.org/docs/rules/no-fallthrough +[no-unreachable]: http://eslint.org/docs/rules/no-unreachable + +## 🔎 Implementation + +- [Rule source](../../lib/rules/process-exit-as-throw.js) +- [Test source](../../tests/lib/rules/process-exit-as-throw.js) diff --git a/docs/description/n_shebang.md b/docs/description/n_shebang.md new file mode 100644 index 000000000..63ab36392 --- /dev/null +++ b/docs/description/n_shebang.md @@ -0,0 +1,148 @@ +# Require correct usage of shebang (`n/shebang`) + +💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/eslint-community/eslint-plugin-n#-configs). + +🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + +When we make a CLI tool with Node.js, we add `bin` field to `package.json`, then we add a shebang the entry file. +This rule suggests correct usage of shebang. + +## 📖 Rule Details + +This rule looks up `package.json` file from each linting target file. +Starting from the directory of the target file, it goes up ancestor directories until found. + +If `package.json` was not found, this rule does nothing. + +This rule checks `bin` field of `package.json`, then if a target file matches one of `bin` files, it checks whether or not there is a correct shebang. +Otherwise it checks whether or not there is not a shebang. + +The following patterns are considered problems for files in `bin` field of `package.json`: + +```js +console.log("hello"); /*error This file needs shebang "#!/usr/bin/env node".*/ +``` + +```js +#!/usr/bin/env node /*error This file must not have Unicode BOM.*/ +console.log("hello"); +// If this file has Unicode BOM. +``` + +```js +#!/usr/bin/env node /*error This file must have Unix linebreaks (LF).*/ +console.log("hello"); +// If this file has Windows' linebreaks (CRLF). +``` + +The following patterns are considered problems for other files: + +```js +#!/usr/bin/env node /*error This file needs no shebang.*/ +console.log("hello"); +``` + +The following patterns are not considered problems for files in `bin` field of `package.json`: + +```js +#!/usr/bin/env node +console.log("hello"); +``` + +The following patterns are not considered problems for other files: + +```js +console.log("hello"); +``` + +### Options + +```json +{ + "n/shebang": ["error", {"convertPath": null}] +} +``` + +#### convertPath + +If we use transpilers (e.g. Babel), perhaps the file path to a source code is never handled as a bin file. +`convertPath` option tells to the rule, it needs to convert file paths. + +For example: + +```json +{ + "rules": { + "n/shebang": ["error", { + "convertPath": { + "src/**/*.jsx": ["^src/(.+?)\\.jsx$", "lib/$1.js"] + } + }] + } +} +``` + +This option has the following shape: `: [, ]` + +`targetFiles` is a glob pattern. +It converts paths which are matched to the pattern with the following way. + +```js +path.replace(new RegExp(fromRegExp), toString); +``` + +So on this example, `src/a/foo.jsx` is handled as `lib/a/foo.js`. + +The `convertPath` option can be an array as well. + +For example: + +```json +{ + "rules": { + "n/shebang": ["error", { + "convertPath": [ + { + "include": ["src/**/*.js"], + "exclude": ["**/*.spec.js"], + "replace": ["^src/(.+)$", "lib/$1"] + } + ] + }] + } +} +``` + +In this style, this option has the following shape as the same expression as above: `{include: [], replace: [, ]}`. +In addition, we can specify glob patterns to exclude files. + +### Shared Settings + +The following options can be set by [shared settings](http://eslint.org/docs/user-guide/configuring.html#adding-shared-settings). +Several rules have the same option, but we can set this option at once. + +- `convertPath` + +For Example: + +```json +{ + "settings": { + "node": { + "convertPath": { + "src/**/*.jsx": ["^src/(.+?)\\.jsx$", "lib/$1.js"] + } + } + }, + "rules": { + "n/shebang": "error" + } +} +``` + +## 🔎 Implementation + +- [Rule source](../../lib/rules/shebang.js) +- [Test source](../../tests/lib/rules/shebang.js) diff --git a/docs/multiple-tests/all-patterns-typescript/patterns.xml b/docs/multiple-tests/all-patterns-typescript/patterns.xml index caea37322..1199d74ce 100644 --- a/docs/multiple-tests/all-patterns-typescript/patterns.xml +++ b/docs/multiple-tests/all-patterns-typescript/patterns.xml @@ -317,6 +317,7 @@ + @@ -412,7 +413,6 @@ - @@ -424,7 +424,6 @@ - @@ -497,7 +496,6 @@ - @@ -585,6 +583,24 @@ + + + + + + + + + + + + + + + + + + @@ -1423,6 +1439,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1697,13 +1752,13 @@ - + @@ -1848,7 +1903,6 @@ - @@ -1869,6 +1923,7 @@ + diff --git a/docs/multiple-tests/all-patterns/patterns.xml b/docs/multiple-tests/all-patterns/patterns.xml index caea37322..1199d74ce 100644 --- a/docs/multiple-tests/all-patterns/patterns.xml +++ b/docs/multiple-tests/all-patterns/patterns.xml @@ -317,6 +317,7 @@ + @@ -412,7 +413,6 @@ - @@ -424,7 +424,6 @@ - @@ -497,7 +496,6 @@ - @@ -585,6 +583,24 @@ + + + + + + + + + + + + + + + + + + @@ -1423,6 +1439,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1697,13 +1752,13 @@ - + @@ -1848,7 +1903,6 @@ - @@ -1869,6 +1923,7 @@ + diff --git a/docs/patterns.json b/docs/patterns.json index ccd2de07c..e9ccf2b96 100644 --- a/docs/patterns.json +++ b/docs/patterns.json @@ -3105,6 +3105,13 @@ "parameters": [], "enabled": false }, + { + "patternId": "@angular-eslint_prefer-standalone-component", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, { "patternId": "@angular-eslint_prefer-output-readonly", "level": "Info", @@ -3888,18 +3895,6 @@ "parameters": [], "enabled": false }, - { - "patternId": "@typescript-eslint_no-duplicate-imports", - "level": "Info", - "category": "CodeStyle", - "parameters": [ - { - "name": "includeExports", - "default": false - } - ], - "enabled": false - }, { "patternId": "@typescript-eslint_no-duplicate-type-constituents", "level": "Info", @@ -3977,13 +3972,6 @@ "parameters": [], "enabled": false }, - { - "patternId": "@typescript-eslint_no-implicit-any-catch", - "level": "Info", - "category": "CodeStyle", - "parameters": [], - "enabled": false - }, { "patternId": "@typescript-eslint_no-implied-eval", "level": "Info", @@ -4536,13 +4524,6 @@ "parameters": [], "enabled": false }, - { - "patternId": "@typescript-eslint_sort-type-union-intersection-members", - "level": "Info", - "category": "CodeStyle", - "parameters": [], - "enabled": false - }, { "patternId": "@typescript-eslint_space-before-blocks", "level": "Info", @@ -5157,6 +5138,137 @@ "parameters": [], "enabled": false }, + { + "patternId": "canonical_destructuring-property-newline", + "level": "Info", + "category": "CodeStyle", + "parameters": [ + { + "name": "allowAllPropertiesOnSameLine", + "default": false + } + ], + "enabled": false + }, + { + "patternId": "canonical_export-specifier-newline", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, + { + "patternId": "canonical_filename-match-exported", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, + { + "patternId": "canonical_filename-match-regex", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, + { + "patternId": "canonical_filename-no-index", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, + { + "patternId": "canonical_import-specifier-newline", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, + { + "patternId": "canonical_no-barrel-import", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, + { + "patternId": "canonical_no-reassign-imports", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, + { + "patternId": "canonical_no-restricted-strings", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, + { + "patternId": "canonical_no-unused-exports", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, + { + "patternId": "canonical_no-use-extend-native", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, + { + "patternId": "canonical_prefer-import-alias", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, + { + "patternId": "canonical_prefer-inline-type-import", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, + { + "patternId": "canonical_prefer-react-lazy", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, + { + "patternId": "canonical_prefer-use-mount", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, + { + "patternId": "canonical_require-extension", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, + { + "patternId": "canonical_sort-keys", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, + { + "patternId": "canonical_virtual-module", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, { "patternId": "chai-expect_no-inner-compare", "level": "Info", @@ -11520,6 +11632,289 @@ "parameters": [], "enabled": false }, + { + "patternId": "n_callback-return", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, + { + "patternId": "n_exports-style", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, + { + "patternId": "n_file-extension-in-import", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, + { + "patternId": "n_global-require", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, + { + "patternId": "n_handle-callback-err", + "level": "Error", + "category": "ErrorProne", + "parameters": [], + "enabled": false + }, + { + "patternId": "n_no-callback-literal", + "level": "Error", + "category": "ErrorProne", + "parameters": [], + "enabled": false + }, + { + "patternId": "n_no-deprecated-api", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": true + }, + { + "patternId": "n_no-exports-assign", + "level": "Error", + "category": "ErrorProne", + "parameters": [], + "enabled": true + }, + { + "patternId": "n_no-extraneous-import", + "level": "Error", + "category": "ErrorProne", + "parameters": [], + "enabled": true + }, + { + "patternId": "n_no-extraneous-require", + "level": "Error", + "category": "ErrorProne", + "parameters": [], + "enabled": true + }, + { + "patternId": "n_no-missing-import", + "level": "Error", + "category": "ErrorProne", + "parameters": [], + "enabled": true + }, + { + "patternId": "n_no-missing-require", + "level": "Error", + "category": "ErrorProne", + "parameters": [], + "enabled": true + }, + { + "patternId": "n_no-mixed-requires", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, + { + "patternId": "n_no-new-require", + "level": "Error", + "category": "ErrorProne", + "parameters": [], + "enabled": false + }, + { + "patternId": "n_no-path-concat", + "level": "Error", + "category": "ErrorProne", + "parameters": [], + "enabled": false + }, + { + "patternId": "n_no-process-env", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, + { + "patternId": "n_no-process-exit", + "level": "Error", + "category": "ErrorProne", + "parameters": [], + "enabled": false + }, + { + "patternId": "n_no-restricted-import", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, + { + "patternId": "n_no-restricted-require", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, + { + "patternId": "n_no-sync", + "level": "Info", + "category": "CodeStyle", + "parameters": [ + { + "name": "allowAtRootLevel", + "default": false + } + ], + "enabled": false + }, + { + "patternId": "n_no-unpublished-bin", + "level": "Error", + "category": "ErrorProne", + "parameters": [], + "enabled": true + }, + { + "patternId": "n_no-unpublished-import", + "level": "Error", + "category": "ErrorProne", + "parameters": [ + { + "name": "ignoreTypeImport", + "default": false + } + ], + "enabled": true + }, + { + "patternId": "n_no-unpublished-require", + "level": "Error", + "category": "ErrorProne", + "parameters": [], + "enabled": true + }, + { + "patternId": "n_no-unsupported-features_es-builtins", + "level": "Error", + "category": "ErrorProne", + "parameters": [], + "enabled": true + }, + { + "patternId": "n_no-unsupported-features_es-syntax", + "level": "Error", + "category": "ErrorProne", + "parameters": [], + "enabled": true + }, + { + "patternId": "n_no-unsupported-features_node-builtins", + "level": "Error", + "category": "ErrorProne", + "parameters": [], + "enabled": true + }, + { + "patternId": "n_prefer-global_buffer", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, + { + "patternId": "n_prefer-global_console", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, + { + "patternId": "n_prefer-global_process", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, + { + "patternId": "n_prefer-global_text-decoder", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, + { + "patternId": "n_prefer-global_text-encoder", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, + { + "patternId": "n_prefer-global_url-search-params", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, + { + "patternId": "n_prefer-global_url", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, + { + "patternId": "n_prefer-promises_dns", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, + { + "patternId": "n_prefer-promises_fs", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, + { + "patternId": "n_process-exit-as-throw", + "level": "Error", + "category": "ErrorProne", + "parameters": [], + "enabled": true + }, + { + "patternId": "n_shebang", + "level": "Error", + "category": "ErrorProne", + "parameters": [], + "enabled": true + }, + { + "patternId": "n_no-hide-core-modules", + "level": "Error", + "category": "ErrorProne", + "parameters": [], + "enabled": false + }, + { + "patternId": "n_no-unsupported-features", + "level": "Error", + "category": "ErrorProne", + "parameters": [], + "enabled": false + }, { "patternId": "no-only-tests_no-only-tests", "level": "Error", @@ -13770,7 +14165,7 @@ "enabled": false }, { - "patternId": "scanjs-rules_call__Function", + "patternId": "scanjs-rules_call__addEventListener", "level": "Info", "category": "Security", "subcategory": "CommandInjection", @@ -13778,7 +14173,7 @@ "enabled": false }, { - "patternId": "scanjs-rules_call__addEventListener", + "patternId": "scanjs-rules_call__addEventListener__deviceproximity", "level": "Info", "category": "Security", "subcategory": "CommandInjection", @@ -13786,7 +14181,7 @@ "enabled": false }, { - "patternId": "scanjs-rules_call__addEventListener__deviceproximity", + "patternId": "scanjs-rules_call__addEventListener__message", "level": "Info", "category": "Security", "subcategory": "CommandInjection", @@ -13794,7 +14189,7 @@ "enabled": false }, { - "patternId": "scanjs-rules_call__addEventListener__message", + "patternId": "scanjs-rules_call__connect", "level": "Info", "category": "Security", "subcategory": "CommandInjection", @@ -13802,7 +14197,7 @@ "enabled": false }, { - "patternId": "scanjs-rules_call__connect", + "patternId": "scanjs-rules_call__eval", "level": "Info", "category": "Security", "subcategory": "CommandInjection", @@ -13810,7 +14205,7 @@ "enabled": false }, { - "patternId": "scanjs-rules_call__eval", + "patternId": "scanjs-rules_call__execScript", "level": "Info", "category": "Security", "subcategory": "CommandInjection", @@ -13818,7 +14213,7 @@ "enabled": false }, { - "patternId": "scanjs-rules_call__execScript", + "patternId": "scanjs-rules_call__Function", "level": "Info", "category": "Security", "subcategory": "CommandInjection", @@ -14377,7 +14772,7 @@ }, { "name": "langDir", - "default": "/Users/lorenzo/codacy/github/codacy-eslint/node_modules/eslint-plugin-spellcheck/rules/utils/dicts" + "default": "C:\\Users\\Vítor Pires\\repos\\codacy\\codacy-eslint\\node_modules\\eslint-plugin-spellcheck\\rules/utils/dicts" }, { "name": "skipWords", @@ -14961,13 +15356,6 @@ "parameters": [], "enabled": false }, - { - "patternId": "unicorn_no-unsafe-regex", - "level": "Info", - "category": "CodeStyle", - "parameters": [], - "enabled": false - }, { "patternId": "unicorn_no-unused-properties", "level": "Info", @@ -15113,6 +15501,13 @@ "parameters": [], "enabled": false }, + { + "patternId": "unicorn_no-unsafe-regex", + "level": "Info", + "category": "CodeStyle", + "parameters": [], + "enabled": false + }, { "patternId": "unused-imports_no-unused-vars", "level": "Info", diff --git a/package-lock.json b/package-lock.json index 51cc828ed..0178a978a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@angular-eslint/eslint-plugin-template": "^16.1.0", "@angular-eslint/schematics": "^16.1.0", "@angular-eslint/template-parser": "^16.1.0", - "@angular/compiler": "^16.1.5", + "@angular/compiler": "^16.1.6", "@babel/cli": "^7.22.9", "@babel/core": "^7.22.9", "@babel/eslint-parser": "^7.22.9", @@ -37,7 +37,7 @@ "@ngrx/eslint-plugin": "^16.1.0", "@nodelib/fs.walk": "^1.2.8", "@nrwl/cli": "^15.9.3", - "@nrwl/nx-cloud": "^16.1.0", + "@nrwl/nx-cloud": "^16.1.1", "@nuxtjs/eslint-config": "^12.0.0", "@nuxtjs/eslint-config-typescript": "^12.0.0", "@nx/cypress": "^16.5.3", @@ -55,7 +55,7 @@ "@nx/workspace": "^16.5.3", "@prodigy/eslint-config-prodigy": "^0.0.7", "@react-native-community/eslint-config": "^3.2.0", - "@remix-run/eslint-config": "^1.18.1", + "@remix-run/eslint-config": "^1.19.0", "@salesforce/eslint-config-lwc": "^3.5.2", "@salesforce/eslint-plugin-aura": "^2.1.0", "@salesforce/eslint-plugin-lightning": "^1.0.0", @@ -66,7 +66,7 @@ "@tailwindcss/line-clamp": "^0.4.4", "@tanstack/eslint-plugin-query": "^4.29.25", "@teambit/eslint-config-bit-react": "^0.0.367", - "@teambit/react.eslint-config-bit-react": "^0.0.814", + "@teambit/react.eslint-config-bit-react": "^0.0.815", "@types/eslint": "^8.44.0", "@types/fs-extra": "^11.0.1", "@types/jest": "^29.5.3", @@ -81,7 +81,7 @@ "@vitejs/plugin-vue": "^4.2.3", "@vitejs/plugin-vue2": "^2.2.0", "@vue/eslint-config-airbnb": "^7.0.0", - "@vue/eslint-config-prettier": "^7.1.0", + "@vue/eslint-config-prettier": "^8.0.0", "@vue/eslint-config-standard": "^8.0.1", "@vue/eslint-config-typescript": "^11.0.2", "assets-webpack-plugin": "^7.1.1", @@ -134,7 +134,7 @@ "eslint-config-strongloop": "^2.1.0", "eslint-config-ts-important-stuff": "^1.1.0", "eslint-config-ts-react-important-stuff": "^3.0.0", - "eslint-config-turbo": "^1.10.8", + "eslint-config-turbo": "^1.10.9", "eslint-config-universe": "^11.3.0", "eslint-config-vue": "^2.0.2", "eslint-config-winedirect": "^1.1.0", @@ -152,7 +152,7 @@ "eslint-plugin-awscdk": "^0.0.65", "eslint-plugin-backbone": "^2.1.1", "eslint-plugin-better-styled-components": "^1.1.2", - "eslint-plugin-canonical": "^4.4.4", + "eslint-plugin-canonical": "^4.6.0", "eslint-plugin-cdk": "^1.8.0", "eslint-plugin-chai": "^0.0.1", "eslint-plugin-chai-expect": "^3.0.0", @@ -198,6 +198,7 @@ "eslint-plugin-mocha": "^10.1.0", "eslint-plugin-mongodb": "^1.0.0", "eslint-plugin-monorepo": "^0.3.2", + "eslint-plugin-n": "^16.0.1", "eslint-plugin-no-only-tests": "^3.1.0", "eslint-plugin-no-unsanitized": "^4.0.2", "eslint-plugin-node": "^11.1.0", @@ -210,7 +211,7 @@ "eslint-plugin-prettier-vue": "^4.2.0", "eslint-plugin-promise": "^6.1.1", "eslint-plugin-ramda": "^2.5.1", - "eslint-plugin-react": "^7.32.2", + "eslint-plugin-react": "^7.33.0", "eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-react-native": "^4.0.0", "eslint-plugin-react-redux": "^4.0.0", @@ -230,13 +231,13 @@ "eslint-plugin-sort-keys-fix": "^1.1.2", "eslint-plugin-sorting": "^0.4.1", "eslint-plugin-spellcheck": "^0.0.20", - "eslint-plugin-storybook": "^0.6.11", + "eslint-plugin-storybook": "^0.6.13", "eslint-plugin-suitescript": "^1.2.1", "eslint-plugin-tailwindcss": "^3.13.0", "eslint-plugin-test-selectors": "^2.0.4", "eslint-plugin-testing-library": "^5.11.0", "eslint-plugin-tsdoc": "^0.2.17", - "eslint-plugin-turbo": "^1.10.8", + "eslint-plugin-turbo": "^1.10.9", "eslint-plugin-typescript-sort-keys": "^2.3.0", "eslint-plugin-unicorn": "^48.0.0", "eslint-plugin-unused-imports": "^3.0.0", @@ -258,9 +259,11 @@ "mocha": "^10.2.0", "next": "^13.4.10", "node-fetch": "^2.6.12", - "npm": "^9.8.0", + "npm": "^9.8.1", "prettier": "^3.0.0", "prettier-plugin-tailwindcss": "^0.4.1", + "react": "^18.2.0", + "react-dom": "^18.2.0", "react-hot-loader": "^4.13.1", "redux-saga": "^1.2.3", "simple-mock": "^0.8.0", @@ -273,12 +276,15 @@ "ts-node": "^10.9.1", "typescript": "^5.1.6", "typescript-eslint": "^0.0.1-alpha.0", - "vite": "^4.4.4", + "vite": "^4.4.5", "vue-eslint-parser": "^9.3.1", "webpack": "^5.88.2", "webpack-manifest-plugin": "^5.0.0", "ws": "^8.13.0", "xml2js": "^0.6.0" + }, + "engines": { + "node": ">=18.0.0" } }, "node_modules/@1stg/config": { @@ -1447,9 +1453,9 @@ } }, "node_modules/@angular/compiler": { - "version": "16.1.5", - "resolved": "https://registry.npmjs.org/@angular/compiler/-/compiler-16.1.5.tgz", - "integrity": "sha512-QNyisdr9lEN43v/e/fjS0H1vrJBMY8lIGpxVY1OOERFjA1clfMhaz5fiPE3vWFV5TOm3/ym9z2xuRXM6UoyWoA==", + "version": "16.1.6", + "resolved": "https://registry.npmjs.org/@angular/compiler/-/compiler-16.1.6.tgz", + "integrity": "sha512-BVDfKZLMb7mmLwdek+ZyzI43Zv0WNNNqnYpMeOI6egmkhtjNCxpQAy2YFKgNPse3bBGP8tKutwAtBB+Lqu/Kcw==", "dependencies": { "tslib": "^2.3.0" }, @@ -1457,7 +1463,7 @@ "node": "^16.14.0 || >=18.10.0" }, "peerDependencies": { - "@angular/core": "16.1.5" + "@angular/core": "16.1.6" }, "peerDependenciesMeta": { "@angular/core": { @@ -7954,11 +7960,11 @@ } }, "node_modules/@nrwl/nx-cloud": { - "version": "16.1.0", - "resolved": "https://registry.npmjs.org/@nrwl/nx-cloud/-/nx-cloud-16.1.0.tgz", - "integrity": "sha512-OFjbSqdCuZq9KRYU/mOlIN8SYLZREsLlZYqYpObZqXJ5meUgBDJbUSwRweUSUvt73fgRixLEau2jPysiLHKxSQ==", + "version": "16.1.1", + "resolved": "https://registry.npmjs.org/@nrwl/nx-cloud/-/nx-cloud-16.1.1.tgz", + "integrity": "sha512-iJIPP46+saFZK748FKU4u4YZH+Sv3ZvZPbMwGVMhwqhOYcrlO5aSa0lpilyoN8WuhooKNqcCfiqshx6V577fTg==", "dependencies": { - "nx-cloud": "16.1.0" + "nx-cloud": "16.1.1" } }, "node_modules/@nrwl/nx-darwin-arm64": { @@ -10756,9 +10762,9 @@ "integrity": "sha512-1dgmkh+3so0+LlBWRhGA33ua4MYr7tUOj+a9Si28vUi0IUFNbff1T3sgpeDJI/LaC75bBYnQ0A3wXjn0OrRNBA==" }, "node_modules/@remix-run/eslint-config": { - "version": "1.18.1", - "resolved": "https://registry.npmjs.org/@remix-run/eslint-config/-/eslint-config-1.18.1.tgz", - "integrity": "sha512-r0vjv+//isRseRShZ6RbX2bJSjQzfE7R2KOf4v1v+EVQZ59Vk0cR6UPwlxHN4Wc3jtTa2yBlLCm1H24ImKLQ4Q==", + "version": "1.19.0", + "resolved": "https://registry.npmjs.org/@remix-run/eslint-config/-/eslint-config-1.19.0.tgz", + "integrity": "sha512-pfGJnZ+Fv5+e/kF67K00dj1AA7okcsiUf/PqPwRr66mgGEe9CeLJQ5IZcczQx6TmIi574yy1G5sblz5L9EGlUg==", "dependencies": { "@babel/core": "^7.21.8", "@babel/eslint-parser": "^7.21.8", @@ -12672,9 +12678,9 @@ } }, "node_modules/@teambit/react.eslint-config-bit-react": { - "version": "0.0.814", - "resolved": "https://registry.npmjs.org/@teambit/react.eslint-config-bit-react/-/react.eslint-config-bit-react-0.0.814.tgz", - "integrity": "sha512-B0cK4xTMdf+JsI72UeYC4UuOwh6UWzNyZrYjHSpU4Xj9mfk/zF2q+Fa8/LKpqCNvyfleI+vWXNrakCTcyCNPEg==", + "version": "0.0.815", + "resolved": "https://registry.npmjs.org/@teambit/react.eslint-config-bit-react/-/react.eslint-config-bit-react-0.0.815.tgz", + "integrity": "sha512-wQ3YfnKxYOZEuqEfP7rUsnCW8nRfGotLd0mwheAgNGtTWeTeYA9xxTDsGgEou/74RuSOe/UoC94TZUEUf7ILsg==", "dependencies": { "@typescript-eslint/eslint-plugin": "5.35.1", "@typescript-eslint/parser": "5.35.1", @@ -12685,7 +12691,7 @@ "node": ">=12.22.0" }, "peerDependencies": { - "@teambit/legacy": "1.0.522", + "@teambit/legacy": "1.0.523", "eslint": "> 7.0.0" } }, @@ -14435,36 +14441,16 @@ } }, "node_modules/@vue/eslint-config-prettier": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/@vue/eslint-config-prettier/-/eslint-config-prettier-7.1.0.tgz", - "integrity": "sha512-Pv/lVr0bAzSIHLd9iz0KnvAr4GKyCEl+h52bc4e5yWuDVtLgFwycF7nrbWTAQAS+FU6q1geVd07lc6EWfJiWKQ==", - "dependencies": { - "eslint-config-prettier": "^8.3.0", - "eslint-plugin-prettier": "^4.0.0" - }, - "peerDependencies": { - "eslint": ">= 7.28.0", - "prettier": ">= 2.0.0" - } - }, - "node_modules/@vue/eslint-config-prettier/node_modules/eslint-plugin-prettier": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-4.2.1.tgz", - "integrity": "sha512-f/0rXLXUt0oFYs8ra4w49wYZBG5GKZpAYsJSm6rnYL5uVDjd+zowwMwVZHnAjf4edNrKpCDYfXDgmRE/Ak7QyQ==", + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/@vue/eslint-config-prettier/-/eslint-config-prettier-8.0.0.tgz", + "integrity": "sha512-55dPqtC4PM/yBjhAr+yEw6+7KzzdkBuLmnhBrDfp4I48+wy+Giqqj9yUr5T2uD/BkBROjjmqnLZmXRdOx/VtQg==", "dependencies": { - "prettier-linter-helpers": "^1.0.0" - }, - "engines": { - "node": ">=12.0.0" + "eslint-config-prettier": "^8.8.0", + "eslint-plugin-prettier": "^5.0.0" }, "peerDependencies": { - "eslint": ">=7.28.0", - "prettier": ">=2.0.0" - }, - "peerDependenciesMeta": { - "eslint-config-prettier": { - "optional": true - } + "eslint": ">= 8.0.0", + "prettier": ">= 3.0.0" } }, "node_modules/@vue/eslint-config-standard": { @@ -23932,11 +23918,11 @@ } }, "node_modules/eslint-config-turbo": { - "version": "1.10.8", - "resolved": "https://registry.npmjs.org/eslint-config-turbo/-/eslint-config-turbo-1.10.8.tgz", - "integrity": "sha512-fDJTyM04N9XUcvYFlM4r7Byvjx27TuO68iOnMNjtKF7vBtrJuBBBGtNM0aQIWGg0oTqjjcNTNQw9sQK+IcA5Gw==", + "version": "1.10.9", + "resolved": "https://registry.npmjs.org/eslint-config-turbo/-/eslint-config-turbo-1.10.9.tgz", + "integrity": "sha512-YA5QWxWte/NiRJL0/Cv7aATfIvS5sUAuyD6ZuyTZEzwyU7E6FUXGo44amjf9INkyj96HrJ2nYWoFkCRx3vs6Ag==", "dependencies": { - "eslint-plugin-turbo": "1.10.8" + "eslint-plugin-turbo": "1.10.9" }, "peerDependencies": { "eslint": ">6.6.0" @@ -25736,10 +25722,11 @@ } }, "node_modules/eslint-plugin-canonical": { - "version": "4.4.4", - "resolved": "https://registry.npmjs.org/eslint-plugin-canonical/-/eslint-plugin-canonical-4.4.4.tgz", - "integrity": "sha512-llVhmzqSSQZI5O1umolZjzmNCjy5mwnj6o0XNdTXNs/Ir87w9gjacf7YV4zB0Fhhtzk9Xx5JmFwkLd/tznhtSQ==", + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-canonical/-/eslint-plugin-canonical-4.6.0.tgz", + "integrity": "sha512-wPe4jE8PGTUjPun7+y9VGMc8mm0UaQI2YjhVJL/Z7zRUFgP024/egoYYcFWFLZQtsWqMeFnv9yI1sNaW6z8/+g==", "dependencies": { + "@typescript-eslint/utils": "^6.1.0", "debug": "^4.3.4", "eslint-import-resolver-typescript": "^3.5.3", "eslint-module-utils": "^2.7.4", @@ -28039,9 +28026,9 @@ } }, "node_modules/eslint-plugin-react": { - "version": "7.32.2", - "resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.32.2.tgz", - "integrity": "sha512-t2fBMa+XzonrrNkyVirzKlvn5RXzzPwRHtMvLAtVZrt8oxgnTQaYbU6SXTOO1mwQgp1y5+toMSKInnzGr0Knqg==", + "version": "7.33.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.33.0.tgz", + "integrity": "sha512-qewL/8P34WkY8jAqdQxsiL82pDUeT7nhs8IsuXgfgnsEloKCT4miAV9N9kGtx7/KM9NH/NCGUE7Edt9iGxLXFw==", "dependencies": { "array-includes": "^3.1.6", "array.prototype.flatmap": "^1.3.1", @@ -28056,7 +28043,7 @@ "object.values": "^1.1.6", "prop-types": "^15.8.1", "resolve": "^2.0.0-next.4", - "semver": "^6.3.0", + "semver": "^6.3.1", "string.prototype.matchall": "^4.0.8" }, "engines": { @@ -28147,9 +28134,9 @@ } }, "node_modules/eslint-plugin-react/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "bin": { "semver": "bin/semver.js" } @@ -28668,9 +28655,9 @@ } }, "node_modules/eslint-plugin-storybook": { - "version": "0.6.12", - "resolved": "https://registry.npmjs.org/eslint-plugin-storybook/-/eslint-plugin-storybook-0.6.12.tgz", - "integrity": "sha512-XbIvrq6hNVG6rpdBr+eBw63QhOMLpZneQVSooEDow8aQCWGCk/5vqtap1yxpVydNfSxi3S/3mBBRLQqKUqQRww==", + "version": "0.6.13", + "resolved": "https://registry.npmjs.org/eslint-plugin-storybook/-/eslint-plugin-storybook-0.6.13.tgz", + "integrity": "sha512-smd+CS0WH1jBqUEJ3znGS7DU4ayBE9z6lkQAK2yrSUv1+rq8BT/tiI5C/rKE7rmiqiAfojtNYZRhzo5HrulccQ==", "dependencies": { "@storybook/csf": "^0.0.1", "@typescript-eslint/utils": "^5.45.0", @@ -29057,9 +29044,9 @@ } }, "node_modules/eslint-plugin-turbo": { - "version": "1.10.8", - "resolved": "https://registry.npmjs.org/eslint-plugin-turbo/-/eslint-plugin-turbo-1.10.8.tgz", - "integrity": "sha512-0ULCoR0Zj/ec4mjmfeYhDa5OtqCvSgDkQdSD/tqLUSHM0GzcUrNvGPclVmsoCb5kmawzeqtlqnS2FKILc862qw==", + "version": "1.10.9", + "resolved": "https://registry.npmjs.org/eslint-plugin-turbo/-/eslint-plugin-turbo-1.10.9.tgz", + "integrity": "sha512-o8Nga4WFMvzF0lo3d3UyjGli2JOUn/4SRtRdvcf4EA9/TPotU/NUHqO16Cp0SHZJG/tGYIy5LY1O/EO7Mxbd1A==", "dependencies": { "dotenv": "16.0.3" }, @@ -40695,15 +40682,17 @@ } }, "node_modules/npm": { - "version": "9.8.0", - "resolved": "https://registry.npmjs.org/npm/-/npm-9.8.0.tgz", - "integrity": "sha512-AXeiBAdfM5K2jvBwA7EGLKeYyt0VnhmJRnlq4k2+M0Ao9v7yKJBqF8xFPzQL8kAybzwlfpTPCZwM4uTIszb3xA==", + "version": "9.8.1", + "resolved": "https://registry.npmjs.org/npm/-/npm-9.8.1.tgz", + "integrity": "sha512-AfDvThQzsIXhYgk9zhbk5R+lh811lKkLAeQMMhSypf1BM7zUafeIIBzMzespeuVEJ0+LvY36oRQYf7IKLzU3rw==", "bundleDependencies": [ "@isaacs/string-locale-compare", "@npmcli/arborist", "@npmcli/config", + "@npmcli/fs", "@npmcli/map-workspaces", "@npmcli/package-json", + "@npmcli/promise-spawn", "@npmcli/run-script", "abbrev", "archy", @@ -40770,13 +40759,15 @@ "@isaacs/string-locale-compare": "^1.1.0", "@npmcli/arborist": "^6.3.0", "@npmcli/config": "^6.2.1", + "@npmcli/fs": "^3.1.0", "@npmcli/map-workspaces": "^3.0.4", - "@npmcli/package-json": "^4.0.0", + "@npmcli/package-json": "^4.0.1", + "@npmcli/promise-spawn": "^6.0.2", "@npmcli/run-script": "^6.0.2", "abbrev": "^2.0.0", "archy": "~1.0.0", "cacache": "^17.1.3", - "chalk": "^5.2.0", + "chalk": "^5.3.0", "ci-info": "^3.8.0", "cli-columns": "^4.0.0", "cli-table3": "^0.6.3", @@ -40792,7 +40783,7 @@ "json-parse-even-better-errors": "^3.0.0", "libnpmaccess": "^7.0.2", "libnpmdiff": "^5.0.19", - "libnpmexec": "^6.0.2", + "libnpmexec": "^6.0.3", "libnpmfund": "^4.0.19", "libnpmhook": "^9.0.3", "libnpmorg": "^5.0.4", @@ -40802,7 +40793,7 @@ "libnpmteam": "^5.0.3", "libnpmversion": "^4.0.2", "make-fetch-happen": "^11.1.1", - "minimatch": "^9.0.0", + "minimatch": "^9.0.3", "minipass": "^5.0.0", "minipass-pipeline": "^1.2.4", "ms": "^2.1.2", @@ -40822,10 +40813,10 @@ "proc-log": "^3.0.0", "qrcode-terminal": "^0.12.0", "read": "^2.1.0", - "semver": "^7.5.2", + "semver": "^7.5.4", "sigstore": "^1.7.0", "ssri": "^10.0.4", - "supports-color": "^9.3.1", + "supports-color": "^9.4.0", "tar": "^6.1.15", "text-table": "~0.2.0", "tiny-relative-date": "^1.3.0", @@ -41101,16 +41092,17 @@ } }, "node_modules/npm/node_modules/@npmcli/package-json": { - "version": "4.0.0", + "version": "4.0.1", "inBundle": true, "license": "ISC", "dependencies": { "@npmcli/git": "^4.1.0", "glob": "^10.2.2", + "hosted-git-info": "^6.1.1", "json-parse-even-better-errors": "^3.0.0", "normalize-package-data": "^5.0.0", - "npm-normalize-package-bin": "^3.0.1", - "proc-log": "^3.0.0" + "proc-log": "^3.0.0", + "semver": "^7.5.3" }, "engines": { "node": "^14.17.0 || ^16.13.0 || >=18.0.0" @@ -41334,7 +41326,7 @@ "license": "MIT" }, "node_modules/npm/node_modules/bin-links": { - "version": "4.0.1", + "version": "4.0.2", "inBundle": true, "license": "ISC", "dependencies": { @@ -41417,7 +41409,7 @@ } }, "node_modules/npm/node_modules/chalk": { - "version": "5.2.0", + "version": "5.3.0", "inBundle": true, "license": "MIT", "engines": { @@ -42091,7 +42083,7 @@ } }, "node_modules/npm/node_modules/libnpmexec": { - "version": "6.0.2", + "version": "6.0.3", "inBundle": true, "license": "ISC", "dependencies": { @@ -42250,7 +42242,7 @@ } }, "node_modules/npm/node_modules/minimatch": { - "version": "9.0.1", + "version": "9.0.3", "inBundle": true, "license": "ISC", "dependencies": { @@ -43094,7 +43086,7 @@ "optional": true }, "node_modules/npm/node_modules/semver": { - "version": "7.5.2", + "version": "7.5.4", "inBundle": true, "license": "ISC", "dependencies": { @@ -43302,7 +43294,7 @@ } }, "node_modules/npm/node_modules/supports-color": { - "version": "9.3.1", + "version": "9.4.0", "inBundle": true, "license": "MIT", "engines": { @@ -43661,11 +43653,11 @@ } }, "node_modules/nx-cloud": { - "version": "16.1.0", - "resolved": "https://registry.npmjs.org/nx-cloud/-/nx-cloud-16.1.0.tgz", - "integrity": "sha512-2K5OuJ4MEDrn2solje2X+a3UxSCdfR5PIscCRQbBANyvJfl3hGJSTxz0n5xeJJX4cKcQlfAxDQFRH6DHNdTGPQ==", + "version": "16.1.1", + "resolved": "https://registry.npmjs.org/nx-cloud/-/nx-cloud-16.1.1.tgz", + "integrity": "sha512-Rq7ynvkYzAJ67N3pDqU6cMqwvWP7WXJGP4EFjLxgUrRHNCccqDPggeAqePodfk3nZEUrZB8F5QBKZuuw1DR3oA==", "dependencies": { - "@nrwl/nx-cloud": "16.1.0", + "@nrwl/nx-cloud": "16.1.1", "axios": "1.1.3", "chalk": "^4.1.0", "dotenv": "~10.0.0", @@ -44967,9 +44959,9 @@ } }, "node_modules/postcss": { - "version": "8.4.25", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.25.tgz", - "integrity": "sha512-7taJ/8t2av0Z+sQEvNzCkpDynl0tX3uJMCODi6nT3PfASC7dYCWV9aQ+uiCf+KBD4SEFcu+GvJdGdwzQ6OSjCw==", + "version": "8.4.26", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.26.tgz", + "integrity": "sha512-jrXHFF8iTloAenySjM/ob3gSj7pCu0Ji49hnjqzsgSRa50hkWCKD0HQ+gMNJkW38jBI68MpAAg7ZWwHwX8NMMw==", "funding": [ { "type": "opencollective", @@ -45540,6 +45532,29 @@ "node": ">= 0.8" } }, + "node_modules/react": { + "version": "18.2.0", + "resolved": "https://registry.npmjs.org/react/-/react-18.2.0.tgz", + "integrity": "sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==", + "dependencies": { + "loose-envify": "^1.1.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/react-dom": { + "version": "18.2.0", + "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.2.0.tgz", + "integrity": "sha512-6IMTriUmvsjHUjNtEDudZfuDQUoWXVxKHhlEGSk81n4YFS+r/Kl99wXiwlVXtPBtJenozv2P+hxDsw9eA7Xo6g==", + "dependencies": { + "loose-envify": "^1.1.0", + "scheduler": "^0.23.0" + }, + "peerDependencies": { + "react": "^18.2.0" + } + }, "node_modules/react-hot-loader": { "version": "4.13.1", "resolved": "https://registry.npmjs.org/react-hot-loader/-/react-hot-loader-4.13.1.tgz", @@ -46446,6 +46461,14 @@ "node": ">=10" } }, + "node_modules/scheduler": { + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.0.tgz", + "integrity": "sha512-CtuThmgHNg7zIZWAXi3AsyIzA3n4xx7aNyjwC2VJldO2LMVDhFK+63xGqq6CsJH4rTAt6/M+N4GhZiDYPx9eUw==", + "dependencies": { + "loose-envify": "^1.1.0" + } + }, "node_modules/schema-utils": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-4.2.0.tgz", @@ -49678,12 +49701,12 @@ } }, "node_modules/vite": { - "version": "4.4.4", - "resolved": "https://registry.npmjs.org/vite/-/vite-4.4.4.tgz", - "integrity": "sha512-4mvsTxjkveWrKDJI70QmelfVqTm+ihFAb6+xf4sjEU2TmUCTlVX87tmg/QooPEMQb/lM9qGHT99ebqPziEd3wg==", + "version": "4.4.5", + "resolved": "https://registry.npmjs.org/vite/-/vite-4.4.5.tgz", + "integrity": "sha512-4m5kEtAWHYr0O1Fu7rZp64CfO1PsRGZlD3TAB32UmQlpd7qg15VF7ROqGN5CyqN7HFuwr7ICNM2+fDWRqFEKaA==", "dependencies": { "esbuild": "^0.18.10", - "postcss": "^8.4.25", + "postcss": "^8.4.26", "rollup": "^3.25.2" }, "bin": { diff --git a/package.json b/package.json index d3e6d13a7..91375a403 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,9 @@ "require": "ts-node/register", "spec": "src/test/**/*.spec.ts" }, + "engines": { + "node": ">=18.0.0" + }, "dependencies": { "@1stg/eslint-config": "^7.0.0", "@angular-eslint/builder": "^16.1.0", @@ -62,7 +65,7 @@ "@angular-eslint/eslint-plugin-template": "^16.1.0", "@angular-eslint/schematics": "^16.1.0", "@angular-eslint/template-parser": "^16.1.0", - "@angular/compiler": "^16.1.5", + "@angular/compiler": "^16.1.6", "@babel/cli": "^7.22.9", "@babel/core": "^7.22.9", "@babel/eslint-parser": "^7.22.9", @@ -86,7 +89,7 @@ "@ngrx/eslint-plugin": "^16.1.0", "@nodelib/fs.walk": "^1.2.8", "@nrwl/cli": "^15.9.3", - "@nrwl/nx-cloud": "^16.1.0", + "@nrwl/nx-cloud": "^16.1.1", "@nuxtjs/eslint-config": "^12.0.0", "@nuxtjs/eslint-config-typescript": "^12.0.0", "@nx/cypress": "^16.5.3", @@ -104,7 +107,7 @@ "@nx/workspace": "^16.5.3", "@prodigy/eslint-config-prodigy": "^0.0.7", "@react-native-community/eslint-config": "^3.2.0", - "@remix-run/eslint-config": "^1.18.1", + "@remix-run/eslint-config": "^1.19.0", "@salesforce/eslint-config-lwc": "^3.5.2", "@salesforce/eslint-plugin-aura": "^2.1.0", "@salesforce/eslint-plugin-lightning": "^1.0.0", @@ -115,7 +118,7 @@ "@tailwindcss/line-clamp": "^0.4.4", "@tanstack/eslint-plugin-query": "^4.29.25", "@teambit/eslint-config-bit-react": "^0.0.367", - "@teambit/react.eslint-config-bit-react": "^0.0.814", + "@teambit/react.eslint-config-bit-react": "^0.0.815", "@types/eslint": "^8.44.0", "@types/fs-extra": "^11.0.1", "@types/jest": "^29.5.3", @@ -130,7 +133,7 @@ "@vitejs/plugin-vue": "^4.2.3", "@vitejs/plugin-vue2": "^2.2.0", "@vue/eslint-config-airbnb": "^7.0.0", - "@vue/eslint-config-prettier": "^7.1.0", + "@vue/eslint-config-prettier": "^8.0.0", "@vue/eslint-config-standard": "^8.0.1", "@vue/eslint-config-typescript": "^11.0.2", "assets-webpack-plugin": "^7.1.1", @@ -183,7 +186,7 @@ "eslint-config-strongloop": "^2.1.0", "eslint-config-ts-important-stuff": "^1.1.0", "eslint-config-ts-react-important-stuff": "^3.0.0", - "eslint-config-turbo": "^1.10.8", + "eslint-config-turbo": "^1.10.9", "eslint-config-universe": "^11.3.0", "eslint-config-vue": "^2.0.2", "eslint-config-winedirect": "^1.1.0", @@ -201,7 +204,7 @@ "eslint-plugin-awscdk": "^0.0.65", "eslint-plugin-backbone": "^2.1.1", "eslint-plugin-better-styled-components": "^1.1.2", - "eslint-plugin-canonical": "^4.4.4", + "eslint-plugin-canonical": "^4.6.0", "eslint-plugin-cdk": "^1.8.0", "eslint-plugin-chai": "^0.0.1", "eslint-plugin-chai-expect": "^3.0.0", @@ -247,6 +250,7 @@ "eslint-plugin-mocha": "^10.1.0", "eslint-plugin-mongodb": "^1.0.0", "eslint-plugin-monorepo": "^0.3.2", + "eslint-plugin-n": "^16.0.1", "eslint-plugin-no-only-tests": "^3.1.0", "eslint-plugin-no-unsanitized": "^4.0.2", "eslint-plugin-node": "^11.1.0", @@ -259,7 +263,7 @@ "eslint-plugin-prettier-vue": "^4.2.0", "eslint-plugin-promise": "^6.1.1", "eslint-plugin-ramda": "^2.5.1", - "eslint-plugin-react": "^7.32.2", + "eslint-plugin-react": "^7.33.0", "eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-react-native": "^4.0.0", "eslint-plugin-react-redux": "^4.0.0", @@ -279,13 +283,13 @@ "eslint-plugin-sort-keys-fix": "^1.1.2", "eslint-plugin-sorting": "^0.4.1", "eslint-plugin-spellcheck": "^0.0.20", - "eslint-plugin-storybook": "^0.6.11", + "eslint-plugin-storybook": "^0.6.13", "eslint-plugin-suitescript": "^1.2.1", "eslint-plugin-tailwindcss": "^3.13.0", "eslint-plugin-test-selectors": "^2.0.4", "eslint-plugin-testing-library": "^5.11.0", "eslint-plugin-tsdoc": "^0.2.17", - "eslint-plugin-turbo": "^1.10.8", + "eslint-plugin-turbo": "^1.10.9", "eslint-plugin-typescript-sort-keys": "^2.3.0", "eslint-plugin-unicorn": "^48.0.0", "eslint-plugin-unused-imports": "^3.0.0", @@ -307,9 +311,11 @@ "mocha": "^10.2.0", "next": "^13.4.10", "node-fetch": "^2.6.12", - "npm": "^9.8.0", + "npm": "^9.8.1", "prettier": "^3.0.0", "prettier-plugin-tailwindcss": "^0.4.1", + "react": "^18.2.0", + "react-dom": "^18.2.0", "react-hot-loader": "^4.13.1", "redux-saga": "^1.2.3", "simple-mock": "^0.8.0", @@ -322,7 +328,7 @@ "ts-node": "^10.9.1", "typescript": "^5.1.6", "typescript-eslint": "^0.0.1-alpha.0", - "vite": "^4.4.4", + "vite": "^4.4.5", "vue-eslint-parser": "^9.3.1", "webpack": "^5.88.2", "webpack-manifest-plugin": "^5.0.0", diff --git a/src/docGeneratorMain.ts b/src/docGeneratorMain.ts index b3bb46322..686bb3440 100644 --- a/src/docGeneratorMain.ts +++ b/src/docGeneratorMain.ts @@ -24,50 +24,43 @@ async function main() { console.log("Generate @angular-eslint description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/angular-eslint/angular-eslint/master/packages/eslint-plugin/docs/rules/`, "@angular-eslint" ) console.log("Generate @salesforce/aura description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/forcedotcom/eslint-plugin-aura/master/docs/rules/`, "@salesforce/aura" ) console.log("Generate @salesforce/lightning description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/salesforce/eslint-plugin-lightning/master/docs/rules/`, "@salesforce/lightning" ) console.log("Generate @shopify description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/Shopify/web-configs/main/packages/eslint-plugin/docs/rules/`, "@shopify" ) console.log("Generate @typescript-eslint description files") await docGenerator.downloadDocs( - - `${githubBaseUrl}/typescript-eslint/typescript-eslint/master/packages/eslint-plugin/docs/rules/`, + `${githubBaseUrl}/typescript-eslint/typescript-eslint/main/packages/eslint-plugin/docs/rules/`, "@typescript-eslint", false ) console.log("Generate angular description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/EmmanuelDemey/eslint-plugin-angular/master/docs/rules/`, "angular" ) console.log("Generate backbone description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/ilyavolodin/eslint-plugin-backbone/master/docs/rules/`, "backbone" ) @@ -83,55 +76,47 @@ async function main() { console.log("Generate compat description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/amilajack/eslint-plugin-compat/main/docs/rules/`, "compat" ) console.log("Generate cypress description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/cypress-io/eslint-plugin-cypress/master/docs/rules/`, "cypress" ) console.log("Generate ember description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/ember-cli/eslint-plugin-ember/master/docs/rules/`, "ember" ) console.log("Generate ember-suave description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/DockYard/eslint-plugin-ember-suave/master/docs/rules/`, "ember-suave" ) console.log("Generate es-x description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/eslint-community/eslint-plugin-es-x/master/docs/rules/`, "es-x" ) console.log("Generate eslint description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/eslint/eslint/main/docs/src/rules/` ) console.log("Generate eslint-plugin description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/eslint-community/eslint-plugin-eslint-plugin/main/docs/rules/`, "eslint-plugin" ) console.log("Generate functional description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/jonaskello/eslint-plugin-functional/master/docs/rules/`, "functional", false @@ -139,7 +124,6 @@ async function main() { console.log("Generate i18next description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/edvardchen/eslint-plugin-i18next/next/docs/rules/`, "i18next", false @@ -147,7 +131,6 @@ async function main() { console.log("Generate import description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/un-es/eslint-plugin-i/fork-release/docs/rules/`, "import", false @@ -155,98 +138,90 @@ async function main() { console.log("Generate jasmine description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/tlvince/eslint-plugin-jasmine/master/docs/rules/`, "jasmine" ) console.log("Generate jest description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/jest-community/eslint-plugin-jest/master/docs/rules/`, "jest" ) console.log("Generate jest-dom description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/testing-library/eslint-plugin-jest-dom/main/docs/rules/`, "jest-dom" ) console.log("Generate jest-extended description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/jest-community/eslint-plugin-jest-extended/main/docs/rules/`, "jest-extended" ) console.log("Generate jest-formating description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/dangreenisrael/eslint-plugin-jest-formatting/master/docs/rules/`, "jest-formating" ) console.log("Generate jsdoc description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/gajus/eslint-plugin-jsdoc/main/docs/rules/`, "jsdoc" ) console.log("Generate jsonc description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/ota-meshi/eslint-plugin-jsonc/master/docs/rules/`, "jsonc" ) console.log("Generate jsx-a11y description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/jsx-eslint/eslint-plugin-jsx-a11y/main/docs/rules/`, "jsx-a11y" ) console.log("Generate lit description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/43081j/eslint-plugin-lit/master/docs/rules/`, "lit" ) console.log("Generate lodash description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/wix-incubator/eslint-plugin-lodash/master/docs/rules/`, "lodash" ) console.log("Generate lodash-fp description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/jfmengels/eslint-plugin-lodash-fp/master/docs/rules/`, "lodash-fp" ) console.log("Generate meteor description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/dferber90/eslint-plugin-meteor/master/docs/rules/`, "meteor" ) console.log("Generate mocha description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/lo1tuma/eslint-plugin-mocha/master/docs/rules/`, "mocha" ) - console.log("Generate no-unsanitized description files") + console.log("Generate n description files") await docGenerator.downloadDocs( + `${githubBaseUrl}/eslint-community/eslint-plugin-n/master/docs/rules/`, + "n" + ) + console.log("Generate no-unsanitized description files") + await docGenerator.downloadDocs( `${githubBaseUrl}/mozilla/eslint-plugin-no-unsanitized/master/docs/rules/`, "no-unsanitized" ) @@ -261,7 +236,6 @@ async function main() { console.log("Generate nuxt description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/nuxt/eslint-plugin-nuxt/master/docs/rules/`, "nuxt", false @@ -269,119 +243,102 @@ async function main() { console.log("Generate perfectionist description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/azat-io/eslint-plugin-perfectionist/main/docs/rules/`, "perfectionist" ) console.log("Generate promise description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/xjamundx/eslint-plugin-promise/master/docs/rules/`, "promise" ) console.log("Generate react description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/jsx-eslint/eslint-plugin-react/master/docs/rules/`, "react" ) console.log("Generate react-native description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/Intellicode/eslint-plugin-react-native/master/docs/rules/`, "react-native" ) console.log("Generate redux-saga description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/pke/eslint-plugin-redux-saga/master/docs/rules/`, "redux-saga" ) console.log("Generate regexp description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/ota-meshi/eslint-plugin-regexp/master/docs/rules/`, "regexp" ) console.log("Generate rxjs description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/cartant/eslint-plugin-rxjs/main/docs/rules/`, "rxjs" ) console.log("Generate rxjs-angular description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/cartant/eslint-plugin-rxjs-angular/main/docs/rules/`, "rxjs-angular" ) console.log("Generate security description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/eslint-community/eslint-plugin-security/main/docs/rules/`, "security" ) console.log("Generate sonarjs description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/SonarSource/eslint-plugin-sonarjs/master/docs/rules/`, "sonarjs" ) console.log("Generate sort-destructure-keys description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/mthadley/eslint-plugin-sort-destructure-keys/master/docs/rules/`, "sort-destructure-keys" ) console.log("Generate storybook description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/storybookjs/eslint-plugin-storybook/master/docs/rules/`, "storybook" ) console.log("Generate tailwindcss description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/francoismassart/eslint-plugin-tailwindcss/master/docs/rules/`, "tailwindcss" ) console.log("Generate test-selectors description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/davidcalhoun/eslint-plugin-test-selectors/master/docs/rules/`, "test-selectors" ) console.log("Generate test-library description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/testing-library/eslint-plugin-testing-library/main/docs/rules/`, "test-library" ) console.log("Generate typescript-sort-keys description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/infctr/eslint-plugin-typescript-sort-keys/master/docs/rules/`, "typescript-sort-keys" ) console.log("Generate unicorn description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/sindresorhus/eslint-plugin-unicorn/main/docs/rules/`, "unicorn" ) @@ -395,35 +352,30 @@ async function main() { console.log("Generate vue description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/vuejs/eslint-plugin-vue/master/docs/rules/`, "vue" ) console.log("Generate vue-scoped-css description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/future-architect/eslint-plugin-vue-scoped-css/master/docs/rules/`, "vue-scoped-css" ) console.log("Generate wdio description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/webdriverio/webdriverio/main/packages/eslint-plugin-wdio/docs/rules/`, "wdio" ) console.log("Generate xss description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/Rantanen/eslint-plugin-xss/master/docs/rules/`, "xss" ) console.log("Generate yml description files") await docGenerator.downloadDocs( - `${githubBaseUrl}/ota-meshi/eslint-plugin-yml/master/docs/rules/`, "yml" ) diff --git a/src/eslintDefaultOptions.ts b/src/eslintDefaultOptions.ts index 3eeaa291e..661db97bc 100644 --- a/src/eslintDefaultOptions.ts +++ b/src/eslintDefaultOptions.ts @@ -4,37 +4,13 @@ import { pluginsNames } from "./eslintPlugins" const baseConfigs: string[] = [ "standard", "eslint:recommended", - "plugin:backbone/recommended", - "plugin:chai-expect/recommended", - "plugin:chai-friendly/recommended", - "plugin:compat/recommended", - "plugin:cypress/recommended", - "plugin:ember/recommended", "plugin:eslint-plugin/recommended", - "plugin:flowtype/recommended", - "plugin:i18next/recommended", - "plugin:import/recommended", - "plugin:import/typescript", - "plugin:jest-dom/recommended", - "plugin:jest-formatting/recommended", - "plugin:json/recommended", - "plugin:lit/recommended", - "plugin:lodash/recommended", - "plugin:monorepo/recommended", - //"plugin:@mysticatea/es2015", - //"plugin:@mysticatea/+eslint-plugin", - "plugin:perfectionist/recommended-natural", "plugin:prettier/recommended", - "plugin:react/recommended", - "plugin:security/recommended", - "plugin:test-selectors/recommended", - "plugin:you-dont-need-lodash-underscore/compatible" + "prettier", ] const typescriptConfigs: string[] = [ "plugin:node/recommended", - "plugin:@angular-eslint/recommended", - "plugin:@angular-eslint/template/process-inline-templates", "plugin:@typescript-eslint/recommended" ] @@ -42,7 +18,8 @@ export const defaultOptions: ESLint.Options = { baseConfig: { extends: baseConfigs, env: { - es6: true, + es2021: true, + esnext: true, node: true, browser: true, commonjs: true, @@ -54,17 +31,84 @@ export const defaultOptions: ESLint.Options = { worker: true, qunit: true, }, + globals: { + document: "readonly", + navigator: "readonly", + window: "readonly", + + // ECMAScript + ArrayBuffer: "readonly", + Atomics: "readonly", + BigInt: "readonly", + BigInt64Array: "readonly", + BigUint64Array: "readonly", + DataView: "readonly", + Float32Array: "readonly", + Float64Array: "readonly", + Int16Array: "readonly", + Int32Array: "readonly", + Int8Array: "readonly", + Map: "readonly", + Promise: "readonly", + Proxy: "readonly", + Reflect: "readonly", + Set: "readonly", + SharedArrayBuffer: "readonly", + Symbol: "readonly", + Uint16Array: "readonly", + Uint32Array: "readonly", + Uint8Array: "readonly", + Uint8ClampedArray: "readonly", + WeakMap: "readonly", + WeakSet: "readonly", + + // ECMAScript (experimental) + globalThis: "readonly", + + // ECMA-402 + Intl: "readonly", + + // Web Standard + TextDecoder: "readonly", + TextEncoder: "readonly", + URL: "readonly", + URLSearchParams: "readonly", + WebAssembly: "readonly", + clearInterval: "readonly", + clearTimeout: "readonly", + console: "readonly", + queueMicrotask: "readonly", + setInterval: "readonly", + setTimeout: "readonly", + + // Node.js + Buffer: "readonly", + GLOBAL: "readonly", + clearImmediate: "readonly", + global: "readonly", + process: "readonly", + root: "readonly", + setImmediate: "readonly", + + // Backbone + Backbone: false, + _: false, + + // Cypress + "cypress/globals": true, + }, ignorePatterns: [ "**/node_modules/**/*", "**/dist/**/*", "**/bin/**/*", "**/build/**/*", "**/docs/tests/**/*", - "tsconfig.json" + "tsconfig.json", ], plugins: pluginsNames, parser: "@typescript-eslint/parser", parserOptions: { + ecmaVersion: 2022, ecmaFeatures: { "jsx": true, }, @@ -72,13 +116,23 @@ export const defaultOptions: ESLint.Options = { sourceType: "module", }, settings: { - "node": { - "tryExtensions": [".js", ".json", ".node"], + node: { + paths: ["src"], + extensions: [".js", ".jsx", ".ts", ".tsx"], + tryExtensions: [".js", ".json", ".node"], + }, + "import/parsers": { + "@typescript-eslint/parser": [".ts", ".tsx"] }, "import/resolver": { + node: { + "extensions": [".js", ".jsx", ".ts", ".tsx"] + }, typescript: { - alwaysTryTypes: true, + alwaysTryTypes: true }, + webpack: true, + caseSensitive: false }, jest: { version: 26, @@ -95,6 +149,28 @@ export const defaultOptions: ESLint.Options = { project: ["/tsconfig.json"], sourceType: "module", }, + rules: { + 'constructor-super': 'off', // ts(2335) & ts(2377) + 'getter-return': 'off', // ts(2378) + 'no-const-assign': 'off', // ts(2588) + 'no-dupe-args': 'off', // ts(2300) + 'no-dupe-class-members': 'off', // ts(2393) & ts(2300) + 'no-dupe-keys': 'off', // ts(1117) + 'no-func-assign': 'off', // ts(2539) + 'no-import-assign': 'off', // ts(2539) & ts(2540) + 'no-new-symbol': 'off', // ts(7009) + 'no-obj-calls': 'off', // ts(2349) + 'no-redeclare': 'off', // ts(2451) + 'no-setter-return': 'off', // ts(2408) + 'no-this-before-super': 'off', // ts(2376) + 'no-undef': 'off', // ts(2304) + 'no-unreachable': 'off', // ts(7027) + 'no-unsafe-negation': 'off', // ts(2365) & ts(2360) & ts(2358) + 'no-var': 'error', // ts transpiles let/const to var, so no need for vars any more + 'prefer-const': 'error', // ts provides better types with const + 'prefer-rest-params': 'error', // ts provides better types with rest args over arguments + 'prefer-spread': 'error', // ts transpiles spread to apply, so no need for manual apply + }, }, { files: ["**/*.js", "**/*.json"], @@ -151,7 +227,7 @@ export const defaultOptions: ESLint.Options = { files: ["**/*.vue"], parser: require.resolve("vue-eslint-parser"), parserOptions: { - ecmaVersion: 2020, + ecmaVersion: 2022, sourceType: "module", }, }, @@ -168,6 +244,10 @@ export const defaultOptions: ESLint.Options = { files: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'], extends: ['plugin:testing-library/react'], }, + { + files: ['**/*.gjs', '**/*.gts'], + processor: 'ember/ +``` + +## 📚 Resources + +- [AXE](https://dequeuniversity.com/rules/axe/2.1/label) diff --git a/docs/description/vuejs-accessibility_heading-has-content.md b/docs/description/vuejs-accessibility_heading-has-content.md new file mode 100644 index 000000000..ffa4b4135 --- /dev/null +++ b/docs/description/vuejs-accessibility_heading-has-content.md @@ -0,0 +1,55 @@ +# heading-has-content + +Enforce that heading elements (`h1`, `h2`, etc.) have content and that the content is accessible to screen readers. Accessible means that it is not hidden using the `aria-hidden` prop. Refer to the references to learn about why this is important. + +## 🔧 Options + +This rule takes one optional object argument of type object: + +```json +{ + "rules": { + "vuejs-accessibility/heading-has-content": [ + "error", + { + "components": ["MyHeading"], + "accessibleChildren": ["MyAccessibleText"], + "accessibleDirectives": ["myAccessibleDirective"] + } + ] + } +} +``` + +For the `components` option, these strings determine which elements (**always including** `

` thru `

`) should be checked for having content. This is a good use case when you have a wrapper component that simply renders an `h1` element. + +For the `accessibleChildren` option, these strings determine which elements should be marked as acceptably accessible child elements. For example if you have something like a `` child that you know will translate into accessible text, then you should put the `Trans` component into this array. + +For the `accessibleDirectives` option, these strings declare an element should be marked as acceptably accessible if a directive is present. For example something like `

` may provide content in the same way `v-html` would. You would add `bb` into this array. _Notice these strings should not include the `v-` prefix._ + +### ✔ Succeed + +```vue + +``` + +### ❌ Fail + +```vue + +``` + +## 📚 Resources + +- [Deque University](https://dequeuniversity.com/rules/axe/1.1/empty-heading) diff --git a/docs/description/vuejs-accessibility_iframe-has-title.md b/docs/description/vuejs-accessibility_iframe-has-title.md new file mode 100644 index 000000000..e040f3474 --- /dev/null +++ b/docs/description/vuejs-accessibility_iframe-has-title.md @@ -0,0 +1,29 @@ +# iframe-has-title + +`