diff --git a/.eslintrc.js b/.eslintrc.js index 93dfb07dc..e0371599c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -34,7 +34,7 @@ module.exports = { 'eslint-plugin/report-message-format': 'error', 'eslint-plugin/require-meta-docs-description': [ 'error', - { pattern: '^(Enforce|Ensure|Prefer|Forbid).+\\.$' }, + { pattern: String.raw`^(Enforce|Ensure|Prefer|Forbid).+\.$` }, ], 'eslint-plugin/require-meta-schema': 'error', 'eslint-plugin/require-meta-type': 'error', diff --git a/package.json b/package.json index 046bd0527..7635a7568 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "eslint": "^8.57.0 || ^9.0.0" }, "dependencies": { + "@typescript-eslint/scope-manager": "^8.1.0", "@typescript-eslint/utils": "^8.1.0", "debug": "^4.3.4", "doctrine": "^3.0.0", @@ -82,8 +83,8 @@ "@total-typescript/ts-reset": "^0.5.1", "@types/debug": "^4.1.12", "@types/doctrine": "^0.0.9", - "@types/eslint8.56": "npm:@types/eslint@^8.56.11", "@types/eslint": "^9.6.1", + "@types/eslint8.56": "npm:@types/eslint@^8.56.11", "@types/eslint9": "npm:@types/eslint@^9.6.1", "@types/is-glob": "^4.0.4", "@types/jest": "^29.5.12", @@ -97,9 +98,7 @@ "cross-env": "^7.0.3", "enhanced-resolve": "^5.16.0", "escope": "^4.0.0", - "eslint8.56": "npm:eslint@^8.56.0", "eslint": "^9.15.0", - "eslint9": "npm:eslint@^9.15.0", "eslint-config-prettier": "^9.1.0", "eslint-doc-generator": "^1.7.1", "eslint-import-resolver-typescript": "^3.6.1", @@ -112,6 +111,8 @@ "eslint-plugin-n": "^16.6.2", "eslint-plugin-prettier": "^5.1.3", "eslint-plugin-unicorn": "^56.0.1", + "eslint8.56": "npm:eslint@^8.56.0", + "eslint9": "npm:eslint@^9.15.0", "hermes-eslint": "^0.23.1", "jest": "^29.7.0", "klaw-sync": "^6.0.0", diff --git a/src/rules/dynamic-import-chunkname.ts b/src/rules/dynamic-import-chunkname.ts index fdde52e39..2b27c4131 100644 --- a/src/rules/dynamic-import-chunkname.ts +++ b/src/rules/dynamic-import-chunkname.ts @@ -73,7 +73,7 @@ export = createRule<[Options?], MessageId>({ const { importFunctions = [], allowEmpty = false, - webpackChunknameFormat = '([0-9a-zA-Z-_/.]|\\[(request|index)\\])+', + webpackChunknameFormat = String.raw`([0-9a-zA-Z-_/.]|\[(request|index)\])+`, } = context.options[0] || {} const paddedCommentRegex = /^ (\S[\S\s]+\S) $/ diff --git a/src/rules/no-default-export.ts b/src/rules/no-default-export.ts index d41b33b41..565c5e91e 100644 --- a/src/rules/no-default-export.ts +++ b/src/rules/no-default-export.ts @@ -37,7 +37,8 @@ export = createRule({ ExportNamedDeclaration(node) { for (const specifier of node.specifiers.filter( - specifier => getValue(specifier.exported) === 'default')) { + specifier => getValue(specifier.exported) === 'default', + )) { const { loc } = sourceCode.getFirstTokens(node)[1] || {} // @ts-expect-error - experimental parser type if (specifier.type === 'ExportDefaultSpecifier') { diff --git a/src/rules/no-duplicates.ts b/src/rules/no-duplicates.ts index 2ed7cb503..93813609c 100644 --- a/src/rules/no-duplicates.ts +++ b/src/rules/no-duplicates.ts @@ -381,7 +381,7 @@ function hasCommentInsideNonSpecifiers( // `node` (only inside). If there's a `{...}` part, look for comments before // the `{`, but not before the `}` (hence the `+1`s). const someTokens = - openBraceIndex >= 0 && closeBraceIndex >= 0 + openBraceIndex !== -1 && closeBraceIndex !== -1 ? [ ...tokens.slice(1, openBraceIndex + 1), ...tokens.slice(closeBraceIndex + 1), diff --git a/src/rules/no-import-module-exports.ts b/src/rules/no-import-module-exports.ts index 29c54002f..d2cdf0981 100644 --- a/src/rules/no-import-module-exports.ts +++ b/src/rules/no-import-module-exports.ts @@ -21,17 +21,15 @@ function getEntryPoint(context: RuleContext) { function findScope(context: RuleContext, identifier: string) { const { scopeManager } = context.sourceCode - return ( - scopeManager?.scopes - // eslint-disable-next-line unicorn/prefer-spread - .slice() - .reverse() - .find(scope => - scope.variables.some(variable => - variable.identifiers.some(node => node.name === identifier), - ), - ) - ) + return scopeManager?.scopes + + .slice() + .reverse() + .find(scope => + scope.variables.some(variable => + variable.identifiers.some(node => node.name === identifier), + ), + ) } function findDefinition(objectScope: TSESLint.Scope.Scope, identifier: string) { diff --git a/src/rules/no-named-export.ts b/src/rules/no-named-export.ts index bf4d8f968..b7a6b9d2d 100644 --- a/src/rules/no-named-export.ts +++ b/src/rules/no-named-export.ts @@ -32,8 +32,7 @@ export = createRule({ } const someNamed = node.specifiers.some( - specifier => getValue(specifier.exported) !== - 'default', + specifier => getValue(specifier.exported) !== 'default', ) if (someNamed) { context.report({ node, messageId: 'noAllowed' }) diff --git a/src/rules/prefer-default-export.ts b/src/rules/prefer-default-export.ts index aace88227..ea9f25d5e 100644 --- a/src/rules/prefer-default-export.ts +++ b/src/rules/prefer-default-export.ts @@ -69,9 +69,7 @@ export = createRule<[Options?], MessageId>({ }, ExportSpecifier(node) { - if ( - getValue(node.exported) === 'default' - ) { + if (getValue(node.exported) === 'default') { hasDefaultExport = true } else { specifierExportCount++ diff --git a/src/utils/declared-scope.ts b/src/utils/declared-scope.ts index 8a25d811f..c6c5a0c64 100644 --- a/src/utils/declared-scope.ts +++ b/src/utils/declared-scope.ts @@ -1,5 +1,5 @@ +import type { ScopeType } from '@typescript-eslint/scope-manager' import type { TSESTree } from '@typescript-eslint/utils' -import type { ScopeType } from '@typescript-eslint/scope-manager'; import type { RuleContext } from '../types' diff --git a/src/utils/export-map.ts b/src/utils/export-map.ts index d01bbe615..442357f0e 100644 --- a/src/utils/export-map.ts +++ b/src/utils/export-map.ts @@ -241,7 +241,10 @@ export class ExportMap { } } - function addNamespace(object: object, identifier: TSESTree.Identifier | TSESTree.StringLiteral) { + function addNamespace( + object: object, + identifier: TSESTree.Identifier | TSESTree.StringLiteral, + ) { const nsfn = getNamespace(getValue(identifier)) if (nsfn) { Object.defineProperty(object, 'namespace', { get: nsfn }) diff --git a/test/rules/no-unresolved.spec.ts b/test/rules/no-unresolved.spec.ts index fd6e793db..fea7598fc 100644 --- a/test/rules/no-unresolved.spec.ts +++ b/test/rules/no-unresolved.spec.ts @@ -149,7 +149,7 @@ function runResolverTests(resolver: 'node' | 'webpack') { invalid: [ tInvalid({ code: 'import reallyfake from "./reallyfake/module"', - settings: { 'import-x/ignore': ['^\\./fake/'] }, + settings: { 'import-x/ignore': [String.raw`^\./fake/`] }, errors: [createError('unresolved', './reallyfake/module')], }), diff --git a/test/rules/order.spec.ts b/test/rules/order.spec.ts index 6495c2018..37e72c3c4 100644 --- a/test/rules/order.spec.ts +++ b/test/rules/order.spec.ts @@ -2384,7 +2384,7 @@ ruleTester.run('order', rule, { }, ], settings: { - 'import-x/internal-regex': '^(a|b|c|d|e|f|g|h|i|j|k)(\\/|$)', + 'import-x/internal-regex': String.raw`^(a|b|c|d|e|f|g|h|i|j|k)(\/|$)`, }, errors: Array.from({ length: 11 }, () => ({ messageId: 'oneLineBetweenGroups', diff --git a/test/utils/import-type.spec.ts b/test/utils/import-type.spec.ts index 2fe50d7a0..2762e6c87 100644 --- a/test/utils/import-type.spec.ts +++ b/test/utils/import-type.spec.ts @@ -313,21 +313,23 @@ describe('importType(name)', () => { it('`isExternalModule` works with windows directory separator', () => { const context = testContext() expect( - isExternalModule('foo', 'E:\\path\\to\\node_modules\\foo', context), + isExternalModule('foo', String.raw`E:\path\to\node_modules\foo`, context), ).toBe(true) expect( isExternalModule( '@foo/bar', - 'E:\\path\\to\\node_modules\\@foo\\bar', + String.raw`E:\path\to\node_modules\@foo\bar`, context, ), ).toBe(true) expect( isExternalModule( 'foo', - 'E:\\path\\to\\node_modules\\foo', + String.raw`E:\path\to\node_modules\foo`, testContext({ - 'import-x/external-module-folders': ['E:\\path\\to\\node_modules'], + 'import-x/external-module-folders': [ + String.raw`E:\path\to\node_modules`, + ], }), ), ).toBe(true) diff --git a/yarn.lock b/yarn.lock index 9d14efbdd..dfe2a1bda 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2420,7 +2420,7 @@ "@typescript-eslint/types" "5.62.0" "@typescript-eslint/visitor-keys" "5.62.0" -"@typescript-eslint/scope-manager@8.15.0": +"@typescript-eslint/scope-manager@8.15.0", "@typescript-eslint/scope-manager@^8.1.0": version "8.15.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-8.15.0.tgz#28a1a0f13038f382424f45a988961acaca38f7c6" integrity sha512-QRGy8ADi4J7ii95xz4UoiymmmMd/zuy9azCaamnZ3FM8T5fZcex8UfJcjkiEZjJSztKfEBe3dZ5T/5RHAmw2mA==