eslint-plugin-unicorn
Advanced tools
Comparing version 52.0.0 to 53.0.0
27
index.js
@@ -6,4 +6,2 @@ 'use strict'; | ||
const flatConfigBase = require('./configs/flat-config-base.js'); | ||
const recommendedRules = require('./configs/recommended.js'); | ||
const allRules = require('./configs/all.js'); | ||
const {name, version} = require('./package.json'); | ||
@@ -32,6 +30,27 @@ | ||
const externalRules = { | ||
// Covered by `unicorn/no-negated-condition` | ||
'no-negated-condition': 'off', | ||
// Covered by `unicorn/no-nested-ternary` | ||
'no-nested-ternary': 'off', | ||
}; | ||
const rules = loadRules(); | ||
const recommendedRules = Object.fromEntries( | ||
Object.entries(rules).map(([id, rule]) => [ | ||
`unicorn/${id}`, | ||
rule.meta.docs.recommended ? 'error' : 'off', | ||
]), | ||
); | ||
const allRules = Object.fromEntries( | ||
Object.keys(rules).map(id => [ | ||
`unicorn/${id}`, | ||
'error', | ||
]), | ||
); | ||
const createConfig = (rules, isLegacyConfig = false) => ({ | ||
...(isLegacyConfig ? legacyConfigBase : flatConfigBase), | ||
plugins: isLegacyConfig ? ['unicorn'] : {unicorn}, | ||
rules, | ||
rules: {...externalRules, ...rules}, | ||
}); | ||
@@ -45,3 +64,3 @@ | ||
rules: { | ||
...loadRules(), | ||
...rules, | ||
...deprecatedRules, | ||
@@ -48,0 +67,0 @@ }, |
{ | ||
"name": "eslint-plugin-unicorn", | ||
"version": "52.0.0", | ||
"version": "53.0.0", | ||
"description": "More than 100 powerful ESLint rules", | ||
@@ -16,5 +16,6 @@ "license": "MIT", | ||
"engines": { | ||
"node": ">=16" | ||
"node": ">=18.18" | ||
}, | ||
"scripts": { | ||
"bundle-lodash": "echo \"export {defaultsDeep, camelCase, kebabCase, snakeCase, upperFirst, lowerFirst} from 'lodash-es';\" | npx esbuild --bundle --outfile=rules/utils/lodash.js --format=cjs", | ||
"create-rule": "node ./scripts/create-rule.mjs && npm run fix:eslint-docs", | ||
@@ -32,3 +33,2 @@ "fix": "run-p --continue-on-error fix:*", | ||
"run-rules-on-codebase": "node ./test/run-rules-on-codebase/lint.mjs", | ||
"bundle-lodash": "echo \"export {defaultsDeep, camelCase, kebabCase, snakeCase, upperFirst, lowerFirst} from 'lodash-es';\" | npx esbuild --bundle --outfile=rules/utils/lodash.js --format=cjs", | ||
"smoke": "eslint-remote-tester --config ./test/smoke/eslint-remote-tester.config.js", | ||
@@ -54,8 +54,8 @@ "test": "npm-run-all --continue-on-error lint test:*", | ||
"dependencies": { | ||
"@babel/helper-validator-identifier": "^7.22.20", | ||
"@babel/helper-validator-identifier": "^7.24.5", | ||
"@eslint-community/eslint-utils": "^4.4.0", | ||
"@eslint/eslintrc": "^2.1.4", | ||
"@eslint/eslintrc": "^3.0.2", | ||
"ci-info": "^4.0.0", | ||
"clean-regexp": "^1.0.0", | ||
"core-js-compat": "^3.34.0", | ||
"core-js-compat": "^3.37.0", | ||
"esquery": "^1.5.0", | ||
@@ -69,35 +69,36 @@ "indent-string": "^4.0.0", | ||
"regjsparser": "^0.10.0", | ||
"semver": "^7.5.4", | ||
"semver": "^7.6.1", | ||
"strip-indent": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/code-frame": "^7.23.5", | ||
"@babel/core": "^7.23.6", | ||
"@babel/eslint-parser": "^7.23.3", | ||
"@babel/code-frame": "^7.24.2", | ||
"@babel/core": "^7.24.5", | ||
"@babel/eslint-parser": "^7.24.5", | ||
"@lubien/fixture-beta-package": "^1.0.0-beta.1", | ||
"@typescript-eslint/parser": "^6.15.0", | ||
"ava": "^6.0.1", | ||
"c8": "^8.0.1", | ||
"@typescript-eslint/parser": "^7.8.0", | ||
"ava": "^6.1.3", | ||
"c8": "^9.1.0", | ||
"chalk": "^5.3.0", | ||
"enquirer": "^2.4.1", | ||
"eslint": "^8.56.0", | ||
"eslint": "^9.2.0", | ||
"eslint-ava-rule-tester": "^5.0.1", | ||
"eslint-doc-generator": "^1.7.0", | ||
"eslint-plugin-eslint-plugin": "^5.2.1", | ||
"eslint-doc-generator": "1.7.0", | ||
"eslint-plugin-eslint-plugin": "^6.1.0", | ||
"eslint-plugin-internal-rules": "file:./scripts/internal-rules/", | ||
"eslint-remote-tester": "^3.0.1", | ||
"eslint-remote-tester-repositories": "^1.0.1", | ||
"espree": "^10.0.1", | ||
"execa": "^8.0.1", | ||
"listr": "^0.14.3", | ||
"lodash-es": "^4.17.21", | ||
"markdownlint-cli": "^0.38.0", | ||
"markdownlint-cli": "^0.40.0", | ||
"memoize": "^10.0.0", | ||
"npm-package-json-lint": "^7.1.0", | ||
"npm-run-all2": "^6.1.1", | ||
"npm-run-all2": "^6.1.2", | ||
"outdent": "^0.8.0", | ||
"pretty-ms": "^8.0.0", | ||
"typescript": "^5.3.3", | ||
"vue-eslint-parser": "^9.3.2", | ||
"xo": "^0.56.0", | ||
"yaml": "^2.3.4" | ||
"pretty-ms": "^9.0.0", | ||
"typescript": "^5.4.5", | ||
"vue-eslint-parser": "^9.4.2", | ||
"xo": "^0.58.0", | ||
"yaml": "^2.4.2" | ||
}, | ||
@@ -130,3 +131,5 @@ "peerDependencies": { | ||
"rules": { | ||
"unicorn/escape-case": "off", | ||
"unicorn/expiring-todo-comments": "off", | ||
"unicorn/no-hex-escape": "off", | ||
"unicorn/no-null": "error", | ||
@@ -181,15 +184,3 @@ "unicorn/prefer-array-flat": [ | ||
] | ||
}, | ||
"npmpackagejsonlint": { | ||
"rules": { | ||
"prefer-caret-version-devDependencies": [ | ||
"error", | ||
{ | ||
"exceptions": [ | ||
"eslint-plugin-internal-rules" | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} |
@@ -20,3 +20,3 @@ # eslint-plugin-unicorn [![Coverage Status](https://codecov.io/gh/sindresorhus/eslint-plugin-unicorn/branch/main/graph/badge.svg)](https://codecov.io/gh/sindresorhus/eslint-plugin-unicorn/branch/main) [![npm version](https://img.shields.io/npm/v/eslint-plugin-unicorn.svg?style=flat)](https://npmjs.com/package/eslint-plugin-unicorn) | ||
**Requires ESLint `>=8.23.0`.** | ||
**Requires ESLint `>=8.56.0`.** | ||
@@ -107,4 +107,4 @@ Use a [preset config](#preset-configs-eslintconfigjs) or configure each rule in `eslint.config.js`. | ||
💼 [Configurations](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs) enabled in.\ | ||
✅ Set in the `recommended` [configuration](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs).\ | ||
💼 [Configurations](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs-eslintconfigjs) enabled in.\ | ||
✅ Set in the `recommended` [configuration](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs-eslintconfigjs).\ | ||
🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).\ | ||
@@ -118,2 +118,3 @@ 💡 Manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions). | ||
| [consistent-destructuring](docs/rules/consistent-destructuring.md) | Use destructured variables over properties. | | 🔧 | 💡 | | ||
| [consistent-empty-array-spread](docs/rules/consistent-empty-array-spread.md) | Prefer consistent types when spreading a ternary in an array literal. | ✅ | 🔧 | | | ||
| [consistent-function-scoping](docs/rules/consistent-function-scoping.md) | Move function definitions to the highest possible scope. | ✅ | | | | ||
@@ -144,5 +145,7 @@ | [custom-error-definition](docs/rules/custom-error-definition.md) | Enforce correct `Error` subclassing. | | 🔧 | | | ||
| [no-instanceof-array](docs/rules/no-instanceof-array.md) | Require `Array.isArray()` instead of `instanceof Array`. | ✅ | 🔧 | | | ||
| [no-invalid-fetch-options](docs/rules/no-invalid-fetch-options.md) | Disallow invalid options in `fetch()` and `new Request()`. | ✅ | | | | ||
| [no-invalid-remove-event-listener](docs/rules/no-invalid-remove-event-listener.md) | Prevent calling `EventTarget#removeEventListener()` with the result of an expression. | ✅ | | | | ||
| [no-keyword-prefix](docs/rules/no-keyword-prefix.md) | Disallow identifiers starting with `new` or `class`. | | | | | ||
| [no-lonely-if](docs/rules/no-lonely-if.md) | Disallow `if` statements as the only statement in `if` blocks without `else`. | ✅ | 🔧 | | | ||
| [no-magic-array-flat-depth](docs/rules/no-magic-array-flat-depth.md) | Disallow a magic number as the `depth` argument in `Array#flat(…).` | ✅ | | | | ||
| [no-negated-condition](docs/rules/no-negated-condition.md) | Disallow negated conditions. | ✅ | 🔧 | | | ||
@@ -212,2 +215,3 @@ | [no-nested-ternary](docs/rules/no-nested-ternary.md) | Disallow nested ternary expressions. | ✅ | 🔧 | | | ||
| [prefer-spread](docs/rules/prefer-spread.md) | Prefer the spread operator over `Array.from(…)`, `Array#concat(…)`, `Array#{slice,toSpliced}()` and `String#split('')`. | ✅ | 🔧 | 💡 | | ||
| [prefer-string-raw](docs/rules/prefer-string-raw.md) | Prefer using the `String.raw` tag to avoid escaping `\`. | ✅ | 🔧 | | | ||
| [prefer-string-replace-all](docs/rules/prefer-string-replace-all.md) | Prefer `String#replaceAll()` over regex searches with the global flag. | ✅ | 🔧 | | | ||
@@ -217,2 +221,3 @@ | [prefer-string-slice](docs/rules/prefer-string-slice.md) | Prefer `String#slice()` over `String#substr()` and `String#substring()`. | ✅ | 🔧 | | | ||
| [prefer-string-trim-start-end](docs/rules/prefer-string-trim-start-end.md) | Prefer `String#trimStart()` / `String#trimEnd()` over `String#trimLeft()` / `String#trimRight()`. | ✅ | 🔧 | | | ||
| [prefer-structured-clone](docs/rules/prefer-structured-clone.md) | Prefer using `structuredClone` to create a deep clone. | ✅ | | 💡 | | ||
| [prefer-switch](docs/rules/prefer-switch.md) | Prefer `switch` over multiple `else-if`. | ✅ | 🔧 | | | ||
@@ -231,3 +236,3 @@ | [prefer-ternary](docs/rules/prefer-ternary.md) | Prefer ternary expressions over simple `if-else` statements. | ✅ | 🔧 | | | ||
| [text-encoding-identifier-case](docs/rules/text-encoding-identifier-case.md) | Enforce consistent case for text encoding identifiers. | ✅ | 🔧 | 💡 | | ||
| [throw-new-error](docs/rules/throw-new-error.md) | Require `new` when throwing an error. | ✅ | 🔧 | | | ||
| [throw-new-error](docs/rules/throw-new-error.md) | Require `new` when creating an error. | ✅ | 🔧 | | | ||
@@ -234,0 +239,0 @@ <!-- end auto-generated rules list --> |
@@ -28,2 +28,3 @@ 'use strict'; | ||
isCallOrNewExpression, | ||
isDirective: require('./is-directive.js'), | ||
isEmptyNode: require('./is-empty-node.js'), | ||
@@ -37,2 +38,3 @@ isExpressionStatement: require('./is-expression-statement.js'), | ||
isStaticRequire: require('./is-static-require.js'), | ||
isTaggedTemplateLiteral: require('./is-tagged-template-literal.js'), | ||
isUndefined: require('./is-undefined.js'), | ||
@@ -39,0 +41,0 @@ |
@@ -139,2 +139,3 @@ 'use strict'; | ||
description: 'Improve regexes by making them shorter, consistent, and safer.', | ||
recommended: true, | ||
}, | ||
@@ -141,0 +142,0 @@ fixable: 'code', |
@@ -131,2 +131,3 @@ 'use strict'; | ||
description: 'Enforce a specific parameter name in catch clauses.', | ||
recommended: true, | ||
}, | ||
@@ -133,0 +134,0 @@ fixable: 'code', |
@@ -160,2 +160,3 @@ 'use strict'; | ||
description: 'Use destructured variables over properties.', | ||
recommended: false, | ||
}, | ||
@@ -162,0 +163,0 @@ fixable: 'code', |
@@ -219,2 +219,3 @@ 'use strict'; | ||
description: 'Move function definitions to the highest possible scope.', | ||
recommended: true, | ||
}, | ||
@@ -221,0 +222,0 @@ schema, |
@@ -211,2 +211,3 @@ 'use strict'; | ||
description: 'Enforce correct `Error` subclassing.', | ||
recommended: false, | ||
}, | ||
@@ -213,0 +214,0 @@ fixable: 'code', |
@@ -68,2 +68,3 @@ 'use strict'; | ||
description: 'Enforce no spaces between braces.', | ||
recommended: true, | ||
}, | ||
@@ -70,0 +71,0 @@ fixable: 'whitespace', |
@@ -101,2 +101,3 @@ 'use strict'; | ||
description: 'Enforce passing a `message` value when creating a built-in error.', | ||
recommended: true, | ||
}, | ||
@@ -103,0 +104,0 @@ messages, |
'use strict'; | ||
const {replaceTemplateElement} = require('./fix/index.js'); | ||
const {isRegexLiteral, isStringLiteral} = require('./ast/index.js'); | ||
const { | ||
isRegexLiteral, | ||
isStringLiteral, | ||
isTaggedTemplateLiteral, | ||
} = require('./ast/index.js'); | ||
@@ -45,7 +49,13 @@ const MESSAGE_ID = 'escape-case'; | ||
context.on('TemplateElement', node => getProblem({ | ||
node, | ||
original: node.value.raw, | ||
fix: (fixer, fixed) => replaceTemplateElement(fixer, node, fixed), | ||
})); | ||
context.on('TemplateElement', node => { | ||
if (isTaggedTemplateLiteral(node.parent, ['String.raw'])) { | ||
return; | ||
} | ||
return getProblem({ | ||
node, | ||
original: node.value.raw, | ||
fix: (fixer, fixed) => replaceTemplateElement(fixer, node, fixed), | ||
}); | ||
}); | ||
}; | ||
@@ -60,2 +70,3 @@ | ||
description: 'Require escape sequences to use uppercase values.', | ||
recommended: true, | ||
}, | ||
@@ -62,0 +73,0 @@ fixable: 'code', |
@@ -189,3 +189,11 @@ 'use strict'; | ||
return {packageResult, hasPackage, packageJson, packageDependencies, parseArgument, parseTodoMessage, parseTodoWithArguments}; | ||
return { | ||
packageResult, | ||
hasPackage, | ||
packageJson, | ||
packageDependencies, | ||
parseArgument, | ||
parseTodoMessage, | ||
parseTodoWithArguments, | ||
}; | ||
} | ||
@@ -201,3 +209,3 @@ | ||
for (const {value, type} of arguments_) { | ||
groups[type] = groups[type] || []; | ||
groups[type] ??= []; | ||
groups[type].push(value); | ||
@@ -578,2 +586,3 @@ } | ||
description: 'Add expiration conditions to TODO comments.', | ||
recommended: true, | ||
}, | ||
@@ -580,0 +589,0 @@ schema, |
@@ -197,3 +197,8 @@ 'use strict'; | ||
if (node) { | ||
return getProblem({node, isZeroLengthCheck, lengthNode, autoFix}); | ||
return getProblem({ | ||
node, | ||
isZeroLengthCheck, | ||
lengthNode, | ||
autoFix, | ||
}); | ||
} | ||
@@ -224,2 +229,3 @@ }, | ||
description: 'Enforce explicitly comparing the `length` or `size` property of a value.', | ||
recommended: true, | ||
}, | ||
@@ -226,0 +232,0 @@ fixable: 'code', |
@@ -287,2 +287,3 @@ 'use strict'; | ||
description: 'Enforce a case style for filenames.', | ||
recommended: true, | ||
}, | ||
@@ -289,0 +290,0 @@ schema, |
@@ -366,2 +366,3 @@ 'use strict'; | ||
description: 'Enforce specific import styles per module.', | ||
recommended: true, | ||
}, | ||
@@ -368,0 +369,0 @@ schema, |
@@ -81,2 +81,3 @@ 'use strict'; | ||
description: 'Enforce the use of `new` for all builtins, except `String`, `Number`, `Boolean`, `Symbol` and `BigInt`.', | ||
recommended: true, | ||
}, | ||
@@ -83,0 +84,0 @@ fixable: 'code', |
@@ -45,2 +45,3 @@ 'use strict'; | ||
description: 'Enforce specifying rules to disable in `eslint-disable` comments.', | ||
recommended: true, | ||
}, | ||
@@ -47,0 +48,0 @@ messages, |
@@ -208,2 +208,3 @@ 'use strict'; | ||
description: 'Disallow anonymous functions and classes as the default export.', | ||
recommended: true, | ||
}, | ||
@@ -210,0 +211,0 @@ hasSuggestions: true, |
@@ -281,2 +281,3 @@ 'use strict'; | ||
description: 'Prevent passing a function reference directly to iterator methods.', | ||
recommended: true, | ||
}, | ||
@@ -283,0 +284,0 @@ hasSuggestions: true, |
@@ -350,3 +350,8 @@ 'use strict'; | ||
|| parameters.some(({type, typeAnnotation}) => type === 'RestElement' || typeAnnotation) | ||
|| !isFunctionParametersSafeToFix(callback, {scope, callExpression, allIdentifiers, sourceCode}) | ||
|| !isFunctionParametersSafeToFix(callback, { | ||
scope, | ||
callExpression, | ||
allIdentifiers, | ||
sourceCode, | ||
}) | ||
) { | ||
@@ -438,3 +443,8 @@ return false; | ||
if (!isFixable(node, {scope, allIdentifiers, functionInfo, sourceCode})) { | ||
if (!isFixable(node, { | ||
scope, | ||
allIdentifiers, | ||
functionInfo, | ||
sourceCode, | ||
})) { | ||
yield problem; | ||
@@ -470,2 +480,3 @@ continue; | ||
description: 'Prefer `for…of` over the `forEach` method.', | ||
recommended: true, | ||
}, | ||
@@ -472,0 +483,0 @@ fixable: 'code', |
@@ -187,3 +187,3 @@ 'use strict'; | ||
// `Array.from()` | ||
// `Array.from()` and `Array.fromAsync()` | ||
context.on('CallExpression', callExpression => { | ||
@@ -193,3 +193,3 @@ if ( | ||
object: 'Array', | ||
method: 'from', | ||
methods: ['from', 'fromAsync'], | ||
argumentsLength: 3, | ||
@@ -221,2 +221,3 @@ optionalCall: false, | ||
description: 'Disallow using the `this` argument in array methods.', | ||
recommended: true, | ||
}, | ||
@@ -223,0 +224,0 @@ fixable: 'code', |
'use strict'; | ||
const {hasSideEffect, isCommaToken, isSemicolonToken} = require('@eslint-community/eslint-utils'); | ||
const getCallExpressionArgumentsText = require('./utils/get-call-expression-arguments-text.js'); | ||
const {hasSideEffect, isSemicolonToken} = require('@eslint-community/eslint-utils'); | ||
const { | ||
getCallExpressionTokens, | ||
getCallExpressionArgumentsText, | ||
} = require('./utils/index.js'); | ||
const isSameReference = require('./utils/is-same-reference.js'); | ||
@@ -81,9 +84,13 @@ const {isNodeMatches} = require('./utils/is-node-matches.js'); | ||
if (secondCallArguments.length > 0) { | ||
const text = getCallExpressionArgumentsText(secondCall, sourceCode); | ||
const text = getCallExpressionArgumentsText(sourceCode, secondCall); | ||
const [penultimateToken, lastToken] = sourceCode.getLastTokens(firstCall, 2); | ||
const { | ||
trailingCommaToken, | ||
closingParenthesisToken, | ||
} = getCallExpressionTokens(sourceCode, firstCall); | ||
yield ( | ||
isCommaToken(penultimateToken) | ||
? fixer.insertTextAfter(penultimateToken, ` ${text}`) | ||
: fixer.insertTextBefore(lastToken, firstCall.arguments.length > 0 ? `, ${text}` : text) | ||
trailingCommaToken | ||
? fixer.insertTextAfter(trailingCommaToken, ` ${text}`) | ||
: fixer.insertTextBefore(closingParenthesisToken, firstCall.arguments.length > 0 ? `, ${text}` : text) | ||
); | ||
@@ -139,2 +146,3 @@ } | ||
description: 'Enforce combining multiple `Array#push()` into one call.', | ||
recommended: true, | ||
}, | ||
@@ -141,0 +149,0 @@ fixable: 'code', |
@@ -122,2 +122,3 @@ 'use strict'; | ||
description: 'Disallow `Array#reduce()` and `Array#reduceRight()`.', | ||
recommended: true, | ||
}, | ||
@@ -124,0 +125,0 @@ schema, |
@@ -86,2 +86,3 @@ 'use strict'; | ||
description: 'Disallow member access from await expression.', | ||
recommended: true, | ||
}, | ||
@@ -88,0 +89,0 @@ fixable: 'code', |
@@ -64,2 +64,3 @@ 'use strict'; | ||
description: 'Disallow using `await` in `Promise` method parameters.', | ||
recommended: true, | ||
}, | ||
@@ -66,0 +67,0 @@ hasSuggestions: true, |
@@ -82,2 +82,3 @@ 'use strict'; | ||
description: 'Do not use leading/trailing space between `console.log` parameters.', | ||
recommended: true, | ||
}, | ||
@@ -84,0 +85,0 @@ fixable: 'code', |
@@ -22,2 +22,3 @@ 'use strict'; | ||
description: 'Do not use `document.cookie` directly.', | ||
recommended: true, | ||
}, | ||
@@ -24,0 +25,0 @@ messages, |
'use strict'; | ||
const {isEmptyNode} = require('./ast/index.js'); | ||
const {isEmptyNode, isDirective} = require('./ast/index.js'); | ||
@@ -9,3 +9,2 @@ const MESSAGE_ID = 'no-empty-file'; | ||
const isDirective = node => node.type === 'ExpressionStatement' && typeof node.directive === 'string'; | ||
const isEmpty = node => isEmptyNode(node, isDirective); | ||
@@ -55,2 +54,3 @@ | ||
description: 'Disallow empty files.', | ||
recommended: true, | ||
}, | ||
@@ -57,0 +57,0 @@ messages, |
@@ -422,2 +422,3 @@ 'use strict'; | ||
description: 'Do not use a `for` loop that can be replaced with a `for-of` loop.', | ||
recommended: true, | ||
}, | ||
@@ -424,0 +425,0 @@ fixable: 'code', |
'use strict'; | ||
const {replaceTemplateElement} = require('./fix/index.js'); | ||
const {isStringLiteral, isRegexLiteral} = require('./ast/index.js'); | ||
const { | ||
isStringLiteral, | ||
isRegexLiteral, | ||
isTaggedTemplateLiteral, | ||
} = require('./ast/index.js'); | ||
@@ -32,3 +36,9 @@ const MESSAGE_ID = 'no-hex-escape'; | ||
}, | ||
TemplateElement: node => checkEscape(context, node, node.value.raw), | ||
TemplateElement(node) { | ||
if (isTaggedTemplateLiteral(node.parent, ['String.raw'])) { | ||
return; | ||
} | ||
return checkEscape(context, node, node.value.raw); | ||
}, | ||
}); | ||
@@ -43,2 +53,3 @@ | ||
description: 'Enforce the use of Unicode escapes instead of hexadecimal escapes.', | ||
recommended: true, | ||
}, | ||
@@ -45,0 +56,0 @@ fixable: 'code', |
@@ -61,2 +61,3 @@ 'use strict'; | ||
description: 'Require `Array.isArray()` instead of `instanceof Array`.', | ||
recommended: true, | ||
}, | ||
@@ -63,0 +64,0 @@ fixable: 'code', |
@@ -57,2 +57,3 @@ 'use strict'; | ||
description: 'Prevent calling `EventTarget#removeEventListener()` with the result of an expression.', | ||
recommended: true, | ||
}, | ||
@@ -59,0 +60,0 @@ messages, |
@@ -195,2 +195,3 @@ 'use strict'; | ||
description: 'Disallow identifiers starting with `new` or `class`.', | ||
recommended: false, | ||
}, | ||
@@ -197,0 +198,0 @@ schema, |
@@ -147,2 +147,3 @@ 'use strict'; | ||
description: 'Disallow `if` statements as the only statement in `if` blocks without `else`.', | ||
recommended: true, | ||
}, | ||
@@ -149,0 +150,0 @@ fixable: 'code', |
@@ -140,2 +140,3 @@ /* | ||
description: 'Disallow negated conditions.', | ||
recommended: true, | ||
}, | ||
@@ -142,0 +143,0 @@ fixable: 'code', |
@@ -54,2 +54,3 @@ 'use strict'; | ||
description: 'Disallow nested ternary expressions.', | ||
recommended: true, | ||
}, | ||
@@ -56,0 +57,0 @@ fixable: 'code', |
@@ -99,2 +99,3 @@ 'use strict'; | ||
description: 'Disallow `new Array()`.', | ||
recommended: true, | ||
}, | ||
@@ -101,0 +102,0 @@ fixable: 'code', |
@@ -93,2 +93,3 @@ 'use strict'; | ||
description: 'Enforce the use of `Buffer.from()` and `Buffer.alloc()` instead of the deprecated `new Buffer()`.', | ||
recommended: true, | ||
}, | ||
@@ -95,0 +96,0 @@ fixable: 'code', |
@@ -147,2 +147,3 @@ 'use strict'; | ||
description: 'Disallow the use of the `null` literal.', | ||
recommended: true, | ||
}, | ||
@@ -149,0 +150,0 @@ fixable: 'code', |
@@ -47,2 +47,3 @@ 'use strict'; | ||
description: 'Disallow the use of objects as default parameters.', | ||
recommended: true, | ||
}, | ||
@@ -49,0 +50,0 @@ messages, |
@@ -101,2 +101,3 @@ 'use strict'; | ||
description: 'Disallow `process.exit()`.', | ||
recommended: true, | ||
}, | ||
@@ -103,0 +104,0 @@ messages, |
@@ -162,2 +162,3 @@ 'use strict'; | ||
description: 'Disallow passing single-element arrays to `Promise` methods.', | ||
recommended: true, | ||
}, | ||
@@ -164,0 +165,0 @@ fixable: 'code', |
@@ -220,2 +220,3 @@ 'use strict'; | ||
description: 'Disallow classes that only have static members.', | ||
recommended: true, | ||
}, | ||
@@ -222,0 +223,0 @@ fixable: 'code', |
@@ -195,2 +195,3 @@ 'use strict'; | ||
description: 'Disallow `then` property.', | ||
recommended: true, | ||
}, | ||
@@ -197,0 +198,0 @@ messages, |
@@ -35,2 +35,3 @@ 'use strict'; | ||
description: 'Disallow assigning `this` to a variable.', | ||
recommended: true, | ||
}, | ||
@@ -37,0 +38,0 @@ messages, |
@@ -137,2 +137,3 @@ 'use strict'; | ||
description: 'Disallow comparing `undefined` using `typeof`.', | ||
recommended: true, | ||
}, | ||
@@ -139,0 +140,0 @@ fixable: 'code', |
@@ -102,2 +102,3 @@ 'use strict'; | ||
description: 'Disallow awaiting non-promise values.', | ||
recommended: true, | ||
}, | ||
@@ -104,0 +105,0 @@ fixable: 'code', |
@@ -26,3 +26,3 @@ 'use strict'; | ||
const suffixes = '(-polyfill)'; | ||
const delimiter = '(\\.|-|\\.prototype\\.|/)?'; | ||
const delimiter = String.raw`(\.|-|\.prototype\.|/)?`; | ||
@@ -33,3 +33,3 @@ const polyfills = Object.keys(compatData).map(feature => { | ||
if (ecmaVersion === 'es') { | ||
ecmaVersion = '(es\\d*)'; | ||
ecmaVersion = String.raw`(es\d*)`; | ||
} | ||
@@ -174,2 +174,3 @@ | ||
description: 'Enforce the use of built-in methods instead of unnecessary polyfills.', | ||
recommended: true, | ||
}, | ||
@@ -176,0 +177,0 @@ schema, |
@@ -79,2 +79,3 @@ 'use strict'; | ||
description: 'Disallow unreadable array destructuring.', | ||
recommended: true, | ||
}, | ||
@@ -81,0 +82,0 @@ fixable: 'code', |
@@ -41,2 +41,3 @@ 'use strict'; | ||
description: 'Disallow unreadable IIFEs.', | ||
recommended: true, | ||
}, | ||
@@ -43,0 +44,0 @@ hasSuggestions: false, |
@@ -235,2 +235,3 @@ 'use strict'; | ||
description: 'Disallow unused object properties.', | ||
recommended: false, | ||
}, | ||
@@ -237,0 +238,0 @@ messages, |
@@ -63,2 +63,3 @@ 'use strict'; | ||
description: 'Disallow useless fallback when spreading in object literals.', | ||
recommended: true, | ||
}, | ||
@@ -65,0 +66,0 @@ fixable: 'code', |
@@ -148,2 +148,3 @@ 'use strict'; | ||
description: 'Disallow useless array length check.', | ||
recommended: true, | ||
}, | ||
@@ -150,0 +151,0 @@ fixable: 'code', |
@@ -114,3 +114,3 @@ 'use strict'; | ||
// `return Promise.reject()` -> `throw undefined` | ||
text = text || 'undefined'; | ||
text ||= 'undefined'; | ||
text = `throw ${text}`; | ||
@@ -147,3 +147,3 @@ | ||
// `=> Promise.resolve()` -> `=> {}` | ||
text = text || '{}'; | ||
text ||= '{}'; | ||
} | ||
@@ -210,2 +210,3 @@ } | ||
description: 'Disallow returning/yielding `Promise.resolve/reject()` in async functions or promise callbacks', | ||
recommended: true, | ||
}, | ||
@@ -212,0 +213,0 @@ fixable: 'code', |
@@ -377,2 +377,3 @@ 'use strict'; | ||
description: 'Disallow unnecessary spread.', | ||
recommended: true, | ||
}, | ||
@@ -379,0 +380,0 @@ fixable: 'code', |
@@ -19,27 +19,13 @@ 'use strict'; | ||
// TypeScript allows multiple `default` cases | ||
const defaultCases = cases.filter(switchCase => switchCase.test === null); | ||
if (defaultCases.length !== 1) { | ||
return; | ||
} | ||
const [defaultCase] = defaultCases; | ||
// We only check cases where the last case is the `default` case | ||
if (defaultCase !== cases.at(-1)) { | ||
if (cases.length < 2 || cases.at(-1).test !== null) { | ||
return; | ||
} | ||
const uselessCases = []; | ||
for (let index = cases.length - 2; index >= 0; index--) { | ||
const node = cases[index]; | ||
if (isEmptySwitchCase(node)) { | ||
uselessCases.unshift(node); | ||
} else { | ||
if (!isEmptySwitchCase(node)) { | ||
break; | ||
} | ||
} | ||
for (const node of uselessCases) { | ||
yield { | ||
@@ -68,2 +54,3 @@ node, | ||
description: 'Disallow useless case in switch statements.', | ||
recommended: true, | ||
}, | ||
@@ -70,0 +57,0 @@ hasSuggestions: true, |
@@ -296,2 +296,3 @@ 'use strict'; | ||
description: 'Disallow useless `undefined`.', | ||
recommended: true, | ||
}, | ||
@@ -298,0 +299,0 @@ fixable: 'code', |
@@ -75,2 +75,3 @@ 'use strict'; | ||
description: 'Disallow number literals with zero fractions or dangling dots.', | ||
recommended: true, | ||
}, | ||
@@ -77,0 +78,0 @@ fixable: 'code', |
@@ -48,2 +48,3 @@ 'use strict'; | ||
description: 'Enforce proper case for numeric literals.', | ||
recommended: true, | ||
}, | ||
@@ -50,0 +51,0 @@ fixable: 'code', |
@@ -176,2 +176,3 @@ 'use strict'; | ||
description: 'Enforce the style of numeric separators by correctly grouping digits.', | ||
recommended: true, | ||
}, | ||
@@ -178,0 +179,0 @@ fixable: 'code', |
@@ -92,3 +92,3 @@ 'use strict'; | ||
ReturnStatement(node) { | ||
codePathInfo.returnsSomething = codePathInfo.returnsSomething || Boolean(node.argument); | ||
codePathInfo.returnsSomething ||= Boolean(node.argument); | ||
}, | ||
@@ -184,2 +184,3 @@ | ||
description: 'Prefer `.addEventListener()` and `.removeEventListener()` over `on`-functions.', | ||
recommended: true, | ||
}, | ||
@@ -186,0 +187,0 @@ fixable: 'code', |
@@ -445,2 +445,3 @@ 'use strict'; | ||
description: 'Prefer `.find(…)` and `.findLast(…)` over the first or last element from `.filter(…)`.', | ||
recommended: true, | ||
}, | ||
@@ -447,0 +448,0 @@ fixable: 'code', |
@@ -78,2 +78,3 @@ 'use strict'; | ||
description: 'Prefer `.flatMap(…)` over `.map(…).flat()`.', | ||
recommended: true, | ||
}, | ||
@@ -80,0 +81,0 @@ fixable: 'code', |
@@ -49,2 +49,3 @@ 'use strict'; | ||
description: 'Array#flatMap()', | ||
recommended: true, | ||
}; | ||
@@ -103,2 +104,3 @@ | ||
description: 'Array#reduce()', | ||
recommended: true, | ||
}; | ||
@@ -124,2 +126,3 @@ | ||
description: '[].concat()', | ||
recommended: true, | ||
shouldSwitchToArray: node => node.arguments[0].type !== 'SpreadElement', | ||
@@ -160,2 +163,3 @@ }; | ||
description: 'Array.prototype.concat()', | ||
recommended: true, | ||
shouldSwitchToArray: node => node.arguments[1].type !== 'SpreadElement' && node.callee.property.name === 'call', | ||
@@ -278,2 +282,3 @@ }; | ||
description: 'Prefer `Array#flat()` over legacy techniques to flatten arrays.', | ||
recommended: true, | ||
}, | ||
@@ -280,0 +285,0 @@ fixable: 'code', |
@@ -24,2 +24,3 @@ 'use strict'; | ||
description: 'Prefer `Array#{indexOf,lastIndexOf}()` over `Array#{findIndex,findLastIndex}()` when looking for the index of an item.', | ||
recommended: true, | ||
}, | ||
@@ -26,0 +27,0 @@ fixable: 'code', |
@@ -152,2 +152,3 @@ 'use strict'; | ||
description: 'Prefer `.some(…)` over `.filter(…).length` check and `.{find,findLast}(…)`.', | ||
recommended: true, | ||
}, | ||
@@ -154,0 +155,0 @@ fixable: 'code', |
@@ -368,2 +368,3 @@ 'use strict'; | ||
description: 'Prefer `.at()` method for index access and `String#charAt()`.', | ||
recommended: true, | ||
}, | ||
@@ -370,0 +371,0 @@ fixable: 'code', |
@@ -42,2 +42,3 @@ 'use strict'; | ||
description: 'Prefer `Blob#arrayBuffer()` over `FileReader#readAsArrayBuffer(…)` and `Blob#text()` over `FileReader#readAsText(…)`.', | ||
recommended: true, | ||
}, | ||
@@ -44,0 +45,0 @@ messages, |
@@ -63,2 +63,3 @@ 'use strict'; | ||
description: 'Prefer `String#codePointAt(…)` over `String#charCodeAt(…)` and `String.fromCodePoint(…)` over `String.fromCharCode(…)`.', | ||
recommended: true, | ||
}, | ||
@@ -65,0 +66,0 @@ hasSuggestions: true, |
@@ -131,2 +131,3 @@ 'use strict'; | ||
description: 'Prefer `Date.now()` to get the number of milliseconds since the Unix Epoch.', | ||
recommended: true, | ||
}, | ||
@@ -133,0 +134,0 @@ fixable: 'code', |
@@ -211,2 +211,3 @@ 'use strict'; | ||
description: 'Prefer default parameters over reassignment.', | ||
recommended: true, | ||
}, | ||
@@ -213,0 +214,0 @@ fixable: 'code', |
@@ -44,2 +44,3 @@ 'use strict'; | ||
description: 'Prefer `Node#append()` over `Node#appendChild()`.', | ||
recommended: true, | ||
}, | ||
@@ -46,0 +47,0 @@ fixable: 'code', |
@@ -94,2 +94,13 @@ 'use strict'; | ||
const method = callExpression.callee.property.name; | ||
// Playwright's `Locator#getAttribute()` returns a promise. | ||
// https://playwright.dev/docs/api/class-locator#locator-get-attribute | ||
if ( | ||
callExpression.parent.type === 'AwaitExpression' | ||
&& callExpression.parent.argument === callExpression | ||
&& method === 'getAttribute' | ||
) { | ||
return; | ||
} | ||
const attributeName = callExpression.arguments[0].value.toLowerCase(); | ||
@@ -117,2 +128,3 @@ | ||
description: 'Prefer using `.dataset` on DOM elements over calling attribute methods.', | ||
recommended: true, | ||
}, | ||
@@ -119,0 +131,0 @@ fixable: 'code', |
@@ -117,2 +117,3 @@ 'use strict'; | ||
description: 'Prefer `childNode.remove()` over `parentNode.removeChild(childNode)`.', | ||
recommended: true, | ||
}, | ||
@@ -119,0 +120,0 @@ fixable: 'code', |
@@ -71,2 +71,3 @@ 'use strict'; | ||
description: 'Prefer `.textContent` over `.innerText`.', | ||
recommended: true, | ||
}, | ||
@@ -73,0 +74,0 @@ hasSuggestions: true, |
@@ -114,2 +114,3 @@ 'use strict'; | ||
description: 'Prefer `EventTarget` over `EventEmitter`.', | ||
recommended: true, | ||
}, | ||
@@ -116,0 +117,0 @@ messages, |
@@ -129,5 +129,3 @@ 'use strict'; | ||
if (!exportDeclaration) { | ||
exportDeclaration = exportDeclarations.find(({source, exportKind}) => source.value === sourceValue && exportKind !== 'type'); | ||
} | ||
exportDeclaration ||= exportDeclarations.find(({source, exportKind}) => source.value === sourceValue && exportKind !== 'type'); | ||
@@ -408,2 +406,3 @@ /** @param {import('eslint').Rule.RuleFixer} fixer */ | ||
description: 'Prefer `export…from` when re-exporting.', | ||
recommended: true, | ||
}, | ||
@@ -410,0 +409,0 @@ fixable: 'code', |
@@ -90,2 +90,3 @@ 'use strict'; | ||
description: 'Prefer `.includes()` over `.indexOf()` and `Array#some()` when checking for existence or non-existence.', | ||
recommended: true, | ||
}, | ||
@@ -92,0 +93,0 @@ fixable: 'code', |
@@ -155,2 +155,3 @@ 'use strict'; | ||
description: 'Prefer reading a JSON file as a buffer.', | ||
recommended: false, | ||
}, | ||
@@ -157,0 +158,0 @@ fixable: 'code', |
@@ -182,2 +182,3 @@ 'use strict'; | ||
description: 'Prefer `KeyboardEvent#key` over `KeyboardEvent#keyCode`.', | ||
recommended: true, | ||
}, | ||
@@ -184,0 +185,0 @@ fixable: 'code', |
@@ -154,2 +154,3 @@ 'use strict'; | ||
description: 'Prefer using a logical operator over a ternary.', | ||
recommended: true, | ||
}, | ||
@@ -156,0 +157,0 @@ |
@@ -104,2 +104,3 @@ 'use strict'; | ||
description: 'Enforce the use of `Math.trunc` instead of bitwise operators.', | ||
recommended: true, | ||
}, | ||
@@ -106,0 +107,0 @@ fixable: 'code', |
@@ -137,2 +137,3 @@ 'use strict'; | ||
description: 'Prefer `.before()` over `.insertBefore()`, `.replaceWith()` over `.replaceChild()`, prefer one of `.before()`, `.after()`, `.append()` or `.prepend()` over `insertAdjacentText()` and `insertAdjacentElement()`.', | ||
recommended: true, | ||
}, | ||
@@ -139,0 +140,0 @@ fixable: 'code', |
@@ -157,2 +157,3 @@ 'use strict'; | ||
description: 'Math.sqrt(…)', | ||
recommended: true, | ||
}, | ||
@@ -209,2 +210,3 @@ * fix(fixer) { | ||
description: 'Prefer modern `Math` APIs over legacy patterns.', | ||
recommended: true, | ||
}, | ||
@@ -211,0 +213,0 @@ fixable: 'code', |
'use strict'; | ||
const {isOpeningParenToken} = require('@eslint-community/eslint-utils'); | ||
const isShadowed = require('./utils/is-shadowed.js'); | ||
const assertToken = require('./utils/assert-token.js'); | ||
const {getCallExpressionTokens} = require('./utils/index.js'); | ||
const {isStaticRequire, isReferenceIdentifier, isFunction} = require('./ast/index.js'); | ||
@@ -29,3 +29,3 @@ const { | ||
[SUGGESTION_IMPORT_META_URL_TO_DIRNAME]: 'Replace `__dirname` with `…(import.meta.url)`.', | ||
[SUGGESTION_IMPORT_META_FILENAME]: 'Replace `__dirname` with `import.meta.filename`.', | ||
[SUGGESTION_IMPORT_META_FILENAME]: 'Replace `__filename` with `import.meta.filename`.', | ||
[SUGGESTION_IMPORT_META_URL_TO_FILENAME]: 'Replace `__filename` with `…(import.meta.url)`.', | ||
@@ -81,8 +81,8 @@ [SUGGESTION_IMPORT]: 'Switch to `import`.', | ||
yield fixer.replaceText(callee, 'import'); | ||
const openingParenthesisToken = sourceCode.getTokenAfter( | ||
callee, | ||
isOpeningParenToken, | ||
); | ||
const { | ||
openingParenthesisToken, | ||
closingParenthesisToken, | ||
} = getCallExpressionTokens(sourceCode, requireCall); | ||
yield fixer.replaceText(openingParenthesisToken, ' '); | ||
const closingParenthesisToken = sourceCode.getLastToken(requireCall); | ||
yield fixer.remove(closingParenthesisToken); | ||
@@ -142,8 +142,8 @@ | ||
yield fixer.remove(callee); | ||
const openingParenthesisToken = sourceCode.getTokenAfter( | ||
callee, | ||
isOpeningParenToken, | ||
); | ||
const { | ||
openingParenthesisToken, | ||
closingParenthesisToken, | ||
} = getCallExpressionTokens(sourceCode, requireCall); | ||
yield fixer.remove(openingParenthesisToken); | ||
const closingParenthesisToken = sourceCode.getLastToken(requireCall); | ||
yield fixer.remove(closingParenthesisToken); | ||
@@ -378,2 +378,3 @@ | ||
description: 'Prefer JavaScript modules (ESM) over CommonJS.', | ||
recommended: true, | ||
}, | ||
@@ -380,0 +381,0 @@ fixable: 'code', |
@@ -181,2 +181,3 @@ 'use strict'; | ||
description: 'Prefer using `String`, `Number`, `BigInt`, `Boolean`, and `Symbol` directly.', | ||
recommended: true, | ||
}, | ||
@@ -183,0 +184,0 @@ fixable: 'code', |
@@ -209,2 +209,3 @@ 'use strict'; | ||
description: 'Prefer negative index over `.length - index` when possible.', | ||
recommended: true, | ||
}, | ||
@@ -211,0 +212,0 @@ fixable: 'code', |
@@ -58,2 +58,3 @@ 'use strict'; | ||
description: 'Prefer using the `node:` protocol when importing Node.js builtin modules.', | ||
recommended: true, | ||
}, | ||
@@ -60,0 +61,0 @@ fixable: 'code', |
@@ -80,4 +80,6 @@ 'use strict'; | ||
checkInfinity, | ||
checkNaN, | ||
} = { | ||
checkInfinity: true, | ||
checkInfinity: false, | ||
checkNaN: true, | ||
...context.options[0], | ||
@@ -87,7 +89,14 @@ }; | ||
let objects = Object.keys(globalObjects); | ||
if (!checkInfinity) { | ||
objects = objects.filter(name => name !== 'Infinity'); | ||
} | ||
const objects = Object.keys(globalObjects).filter(name => { | ||
if (!checkInfinity && name === 'Infinity') { | ||
return false; | ||
} | ||
if (!checkNaN && name === 'NaN') { | ||
return false; | ||
} | ||
return true; | ||
}); | ||
const tracker = new GlobalReferenceTracker({ | ||
@@ -109,2 +118,6 @@ objects, | ||
type: 'boolean', | ||
default: false, | ||
}, | ||
checkNaN: { | ||
type: 'boolean', | ||
default: true, | ||
@@ -123,2 +136,3 @@ }, | ||
description: 'Prefer `Number` static properties over global ones.', | ||
recommended: true, | ||
}, | ||
@@ -125,0 +139,0 @@ fixable: 'code', |
@@ -247,2 +247,3 @@ 'use strict'; | ||
description: 'Prefer using `Object.fromEntries(…)` to transform a list of key-value pairs into an object.', | ||
recommended: true, | ||
}, | ||
@@ -249,0 +250,0 @@ fixable: 'code', |
@@ -71,2 +71,3 @@ 'use strict'; | ||
description: 'Prefer omitting the `catch` binding parameter.', | ||
recommended: true, | ||
}, | ||
@@ -73,0 +74,0 @@ fixable: 'code', |
@@ -156,2 +156,3 @@ 'use strict'; | ||
description: 'Prefer borrowing methods from the prototype instead of the instance.', | ||
recommended: true, | ||
}, | ||
@@ -158,0 +159,0 @@ fixable: 'code', |
@@ -131,2 +131,3 @@ 'use strict'; | ||
description: 'Prefer `.querySelector()` over `.getElementById()`, `.querySelectorAll()` over `.getElementsByClassName()` and `.getElementsByTagName()`.', | ||
recommended: true, | ||
}, | ||
@@ -133,0 +134,0 @@ fixable: 'code', |
@@ -93,2 +93,3 @@ 'use strict'; | ||
description: 'Prefer `Reflect.apply()` over `Function#apply()`.', | ||
recommended: true, | ||
}, | ||
@@ -95,0 +96,0 @@ fixable: 'code', |
@@ -151,2 +151,3 @@ 'use strict'; | ||
description: 'Prefer `RegExp#test()` over `String#match()` and `RegExp#exec()`.', | ||
recommended: true, | ||
}, | ||
@@ -153,0 +154,0 @@ fixable: 'code', |
@@ -181,2 +181,3 @@ 'use strict'; | ||
description: 'Prefer `Set#has()` over `Array#includes()` when checking for existence or non-existence.', | ||
recommended: true, | ||
}, | ||
@@ -183,0 +184,0 @@ fixable: 'code', |
@@ -99,2 +99,3 @@ 'use strict'; | ||
description: 'Prefer using `Set#size` instead of `Array#length`.', | ||
recommended: true, | ||
}, | ||
@@ -101,0 +102,0 @@ fixable: 'code', |
@@ -511,2 +511,3 @@ 'use strict'; | ||
description: 'Prefer the spread operator over `Array.from(…)`, `Array#concat(…)`, `Array#{slice,toSpliced}()` and `String#split(\'\')`.', | ||
recommended: true, | ||
}, | ||
@@ -513,0 +514,0 @@ fixable: 'code', |
@@ -141,2 +141,3 @@ 'use strict'; | ||
description: 'Prefer `String#replaceAll()` over regex searches with the global flag.', | ||
recommended: true, | ||
}, | ||
@@ -143,0 +144,0 @@ fixable: 'code', |
@@ -165,3 +165,8 @@ 'use strict'; | ||
const fixArguments = method === 'substr' ? fixSubstrArguments : fixSubstringArguments; | ||
yield * fixArguments({node, fixer, context, abort}); | ||
yield * fixArguments({ | ||
node, | ||
fixer, | ||
context, | ||
abort, | ||
}); | ||
}, | ||
@@ -179,2 +184,3 @@ }; | ||
description: 'Prefer `String#slice()` over `String#substr()` and `String#substring()`.', | ||
recommended: true, | ||
}, | ||
@@ -181,0 +187,0 @@ fixable: 'code', |
@@ -194,2 +194,3 @@ 'use strict'; | ||
description: 'Prefer `String#startsWith()` & `String#endsWith()` over `RegExp#test()`.', | ||
recommended: true, | ||
}, | ||
@@ -196,0 +197,0 @@ fixable: 'code', |
@@ -40,2 +40,3 @@ 'use strict'; | ||
description: 'Prefer `String#trimStart()` / `String#trimEnd()` over `String#trimLeft()` / `String#trimRight()`.', | ||
recommended: true, | ||
}, | ||
@@ -42,0 +43,0 @@ fixable: 'code', |
@@ -339,2 +339,3 @@ 'use strict'; | ||
description: 'Prefer `switch` over multiple `else-if`.', | ||
recommended: true, | ||
}, | ||
@@ -341,0 +342,0 @@ fixable: 'code', |
@@ -275,2 +275,3 @@ 'use strict'; | ||
description: 'Prefer ternary expressions over simple `if-else` statements.', | ||
recommended: true, | ||
}, | ||
@@ -277,0 +278,0 @@ fixable: 'code', |
@@ -148,2 +148,3 @@ 'use strict'; | ||
description: 'Prefer top-level await over top-level promises and async function calls.', | ||
recommended: true, | ||
}, | ||
@@ -150,0 +151,0 @@ hasSuggestions: true, |
@@ -147,2 +147,3 @@ 'use strict'; | ||
description: 'Enforce throwing `TypeError` in type checking conditions.', | ||
recommended: true, | ||
}, | ||
@@ -149,0 +150,0 @@ fixable: 'code', |
@@ -119,3 +119,3 @@ 'use strict'; | ||
// Split words | ||
const words = name.split(/(?=[^a-z])|(?<=[^A-Za-z])/).filter(Boolean); | ||
const words = name.split(/(?=\P{Lowercase_Letter})|(?<=\P{Letter})/u).filter(Boolean); | ||
@@ -641,2 +641,3 @@ let hasReplacements = false; | ||
description: 'Prevent abbreviations.', | ||
recommended: true, | ||
}, | ||
@@ -643,0 +644,0 @@ fixable: 'code', |
@@ -162,2 +162,3 @@ 'use strict'; | ||
description: 'Enforce consistent relative URL style.', | ||
recommended: true, | ||
}, | ||
@@ -164,0 +165,0 @@ fixable: 'code', |
@@ -59,2 +59,3 @@ 'use strict'; | ||
description: 'Enforce using the separator argument with `Array#join()`.', | ||
recommended: true, | ||
}, | ||
@@ -61,0 +62,0 @@ fixable: 'code', |
@@ -50,2 +50,3 @@ 'use strict'; | ||
description: 'Enforce using the digits argument with `Number#toFixed()`.', | ||
recommended: true, | ||
}, | ||
@@ -52,0 +53,0 @@ fixable: 'code', |
@@ -67,2 +67,5 @@ 'use strict'; | ||
description: 'Enforce using the `targetOrigin` argument with `window.postMessage()`.', | ||
// Turned off because we can't distinguish `window.postMessage` and `{Worker,MessagePort,Client,BroadcastChannel}#postMessage()` | ||
// See #1396 | ||
recommended: false, | ||
}, | ||
@@ -69,0 +72,0 @@ hasSuggestions: true, |
@@ -169,3 +169,4 @@ 'use strict'; | ||
], | ||
}}, | ||
}, | ||
}, | ||
}, | ||
@@ -182,2 +183,3 @@ }, | ||
description: 'Enforce better string content.', | ||
recommended: false, | ||
}, | ||
@@ -184,0 +186,0 @@ fixable: 'code', |
@@ -104,2 +104,3 @@ 'use strict'; | ||
description: 'Enforce consistent brace style for `case` clauses.', | ||
recommended: true, | ||
}, | ||
@@ -106,0 +107,0 @@ fixable: 'code', |
@@ -6,3 +6,8 @@ 'use strict'; | ||
const {replaceTemplateElement} = require('./fix/index.js'); | ||
const {isMethodCall, isCallExpression} = require('./ast/index.js'); | ||
const { | ||
isMethodCall, | ||
isCallExpression, | ||
isTaggedTemplateLiteral, | ||
} = require('./ast/index.js'); | ||
const {isNodeMatches} = require('./utils/index.js'); | ||
@@ -118,6 +123,3 @@ const MESSAGE_ID_IMPROPERLY_INDENTED_TEMPLATE = 'template-indent'; | ||
options.tags.length > 0 | ||
&& node.parent.type === 'TaggedTemplateExpression' | ||
&& node.parent.quasi === node | ||
&& node.parent.tag.type === 'Identifier' | ||
&& options.tags.includes(node.parent.tag.name) | ||
&& isTaggedTemplateLiteral(node, options.tags) | ||
) { | ||
@@ -131,4 +133,3 @@ return true; | ||
&& node.parent.arguments.includes(node) | ||
&& node.parent.callee.type === 'Identifier' | ||
&& options.functions.includes(node.parent.callee.name) | ||
&& isNodeMatches(node.parent.callee, options.functions) | ||
) { | ||
@@ -217,2 +218,3 @@ return true; | ||
description: 'Fix whitespace-insensitive template indentation.', | ||
recommended: true, | ||
}, | ||
@@ -219,0 +221,0 @@ fixable: 'code', |
@@ -103,2 +103,3 @@ 'use strict'; | ||
description: 'Enforce consistent case for text encoding identifiers.', | ||
recommended: true, | ||
}, | ||
@@ -105,0 +106,0 @@ fixable: 'code', |
@@ -6,3 +6,3 @@ 'use strict'; | ||
const messages = { | ||
[messageId]: 'Use `new` when throwing an error.', | ||
[messageId]: 'Use `new` when creating an error.', | ||
}; | ||
@@ -15,9 +15,2 @@ | ||
CallExpression(node) { | ||
if (!( | ||
node.parent.type === 'ThrowStatement' | ||
&& node.parent.argument === node | ||
)) { | ||
return; | ||
} | ||
const {callee} = node; | ||
@@ -50,3 +43,4 @@ if (!( | ||
docs: { | ||
description: 'Require `new` when throwing an error.', | ||
description: 'Require `new` when creating an error.', | ||
recommended: true, | ||
}, | ||
@@ -53,0 +47,0 @@ fixable: 'code', |
@@ -5,4 +5,4 @@ 'use strict'; | ||
/(?<=(?:^|[^\\])(?:\\\\)*)(?<symbol>(?:`|\$(?={)))/g, | ||
'\\$<symbol>', | ||
String.raw`\$<symbol>`, | ||
); | ||
module.exports = escapeTemplateElementRaw; |
'use strict'; | ||
const {isOpeningParenToken} = require('@eslint-community/eslint-utils'); | ||
const getCallExpressionTokens = require('./get-call-expression-tokens.js'); | ||
/** @typedef {import('estree').CallExpression} CallExpression */ | ||
/** | ||
Get the text of the arguments list of `CallExpression`. | ||
@param {Node} node - The `CallExpression` node. | ||
@param {import('eslint').SourceCode} sourceCode - The source code object. | ||
@param {CallExpression} callExpression - The `CallExpression` node. | ||
@param {SourceCode} sourceCode - The source code object. | ||
@returns {string} | ||
*/ | ||
const getCallExpressionArgumentsText = (node, sourceCode) => { | ||
const openingParenthesisToken = sourceCode.getTokenAfter(node.callee, isOpeningParenToken); | ||
const closingParenthesisToken = sourceCode.getLastToken(node); | ||
function getCallExpressionArgumentsText(sourceCode, callExpression) { | ||
const { | ||
openingParenthesisToken, | ||
closingParenthesisToken, | ||
} = getCallExpressionTokens(sourceCode, callExpression); | ||
@@ -19,4 +24,4 @@ return sourceCode.text.slice( | ||
); | ||
}; | ||
} | ||
module.exports = getCallExpressionArgumentsText; |
@@ -21,2 +21,4 @@ 'use strict'; | ||
getBooleanAncestor, | ||
getCallExpressionArgumentsText: require('./get-call-expression-arguments-text.js'), | ||
getCallExpressionTokens: require('./get-call-expression-tokens.js'), | ||
getParentheses, | ||
@@ -23,0 +25,0 @@ getParenthesizedRange, |
@@ -34,3 +34,8 @@ 'use strict'; | ||
return {number, mark, sign, power}; | ||
return { | ||
number, | ||
mark, | ||
sign, | ||
power, | ||
}; | ||
} | ||
@@ -37,0 +42,0 @@ |
@@ -50,11 +50,7 @@ 'use strict'; | ||
if (problem.fix) { | ||
problem.fix = wrapFixFunction(problem.fix); | ||
} | ||
problem.fix &&= wrapFixFunction(problem.fix); | ||
if (Array.isArray(problem.suggest)) { | ||
for (const suggest of problem.suggest) { | ||
if (suggest.fix) { | ||
suggest.fix = wrapFixFunction(suggest.fix); | ||
} | ||
suggest.fix &&= wrapFixFunction(suggest.fix); | ||
@@ -61,0 +57,0 @@ suggest.data = { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
690648
223
21987
365
30
- Removed@eslint/eslintrc@2.1.4(transitive)
- Removedespree@9.6.1(transitive)
- Removedglobals@13.24.0(transitive)
- Removedtype-fest@0.20.2(transitive)
Updated@eslint/eslintrc@^3.0.2
Updatedcore-js-compat@^3.37.0
Updatedsemver@^7.6.1