Skip to content

Commit

Permalink
feat!: upgrade @typescript-eslint/utils to v7 (#66)
Browse files Browse the repository at this point in the history
* feat!: drop eslint <8.56 support

* feat!: remove eslint-compat-utils, remove compatibility codes
  • Loading branch information
JounQin authored Mar 31, 2024
1 parent db5641f commit 49418a0
Show file tree
Hide file tree
Showing 58 changed files with 1,261 additions and 1,378 deletions.
5 changes: 5 additions & 0 deletions .changeset/blue-pianos-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-import-x": minor
---

chore(dep)!: drop eslint <8.56 support
5 changes: 5 additions & 0 deletions .changeset/chilled-roses-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-import-x": minor
---

feat!: upgrade @typescript-eslint/utils to v7
9 changes: 2 additions & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
const eslintPkg = require('eslint/package.json')
const semver = require('semver')

/**
* @type {import('eslint').Linter.Config}
*/
Expand All @@ -12,11 +9,9 @@ module.exports = {
'plugin:eslint-plugin/recommended',
'plugin:import-x/recommended',
'plugin:n/recommended',
semver.satisfies(eslintPkg.version, '>=8')
? 'plugin:unicorn/recommended'
: undefined,
'plugin:unicorn/recommended',
'plugin:prettier/recommended',
].filter(Boolean),
],
env: {
node: true,
es6: true,
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ jobs:
- 18
- 20
eslint:
- 7.2
- 7
- 8
- '8.56'
- '8'
runs-on: ${{ matrix.os }}
steps:
- name: Checkout Repo
Expand Down Expand Up @@ -60,7 +59,7 @@ jobs:
EFF_NO_LINK_RULES: true
PARSER_NO_WATCH: true
SKIP_YARN_COREPACK_CHECK: 1
if: ${{ matrix.node == 20 && matrix.eslint == 8 }}
if: ${{ matrix.node == 20 }}

- name: Codecov
uses: codecov/codecov-action@v3
38 changes: 18 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,12 @@
"watch": "yarn test --watch"
},
"peerDependencies": {
"eslint": "^7.2.0 || ^8 || ^9.0.0-0"
"eslint": "^8.56.0 || ^9.0.0-0"
},
"dependencies": {
"@typescript-eslint/utils": "^5.62.0",
"@typescript-eslint/utils": "^7.4.0",
"debug": "^4.3.4",
"doctrine": "^3.0.0",
"eslint-compat-utils": "^0.5.0",
"eslint-import-resolver-node": "^0.3.9",
"get-tsconfig": "^4.7.3",
"is-glob": "^4.0.3",
Expand All @@ -62,33 +61,32 @@
"@1stg/prettier-config": "^4.0.1",
"@1stg/tsconfig": "^2.3.3",
"@angular-eslint/template-parser": "^17.3.0",
"@babel/core": "^7.24.0",
"@babel/eslint-parser": "^7.23.10",
"@babel/plugin-proposal-decorators": "^7.24.0",
"@babel/plugin-proposal-export-default-from": "^7.23.3",
"@babel/preset-env": "^7.24.0",
"@babel/preset-flow": "^7.24.0",
"@babel/preset-react": "^7.23.3",
"@babel/preset-typescript": "^7.23.3",
"@babel/core": "^7.24.3",
"@babel/eslint-parser": "^7.24.1",
"@babel/plugin-proposal-decorators": "^7.24.1",
"@babel/plugin-proposal-export-default-from": "^7.24.1",
"@babel/preset-env": "^7.24.3",
"@babel/preset-flow": "^7.24.1",
"@babel/preset-react": "^7.24.1",
"@babel/preset-typescript": "^7.24.1",
"@babel/register": "^7.23.7",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.1",
"@eslint/import-test-order-redirect-scoped": "link:./test/fixtures/order-redirect-scoped",
"@swc-node/jest": "^1.8.0",
"@swc/core": "^1.4.8",
"@swc/core": "^1.4.11",
"@swc/helpers": "^0.5.7",
"@test-scope/some-module": "link:./test/fixtures/symlinked-module",
"@total-typescript/ts-reset": "^0.5.1",
"@types/debug": "^4.1.12",
"@types/doctrine": "^0.0.9",
"@types/eslint": "^8.56.5",
"@types/eslint": "^8.56.6",
"@types/is-glob": "^4.0.4",
"@types/jest": "^29.5.12",
"@types/json-schema": "^7.0.15",
"@types/node": "^20.11.28",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"@typescript-eslint/typescript-estree": "^5.62.0",
"@types/node": "^20.11.30",
"@typescript-eslint/eslint-plugin": "^7.4.0",
"@typescript-eslint/parser": "^7.4.0",
"@unts/patch-package": "^8.0.0",
"cross-env": "^7.0.3",
"enhanced-resolve": "^5.16.0",
Expand All @@ -99,7 +97,7 @@
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-import-resolver-webpack": "^0.13.8",
"eslint-import-test-order-redirect": "link:./test/fixtures/order-redirect",
"eslint-plugin-eslint-plugin": "^5.4.0",
"eslint-plugin-eslint-plugin": "^5.4.1",
"eslint-plugin-import-x": "link:.",
"eslint-plugin-jest": "^27.9.0",
"eslint-plugin-json": "^3.1.0",
Expand All @@ -113,7 +111,7 @@
"rimraf": "^5.0.5",
"svelte": "^4.2.12",
"ts-node": "^10.9.2",
"type-fest": "^4.12.0",
"typescript": "~5.1.0"
"type-fest": "^4.14.0",
"typescript": "^5.4.3"
}
}
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
diff --git a/node_modules/@typescript-eslint/utils/dist/ts-eslint/Rule.d.ts b/node_modules/@typescript-eslint/utils/dist/ts-eslint/Rule.d.ts
index 9a3a1fd..c6ed412 100644
index 5ae7288..3d14a45 100644
--- a/node_modules/@typescript-eslint/utils/dist/ts-eslint/Rule.d.ts
+++ b/node_modules/@typescript-eslint/utils/dist/ts-eslint/Rule.d.ts
@@ -6,6 +6,10 @@ import type { Scope } from './Scope';
import type { SourceCode } from './SourceCode';
export type RuleRecommendation = 'error' | 'strict' | 'warn' | false;
interface RuleMetaDataDocs {
@@ -11,6 +11,10 @@ export interface RuleRecommendationAcrossConfigs<Options extends readonly unknow
strict: Partial<Options>;
}
export interface RuleMetaDataDocs<Options extends readonly unknown[]> {
+ /**
+ * The category the rule falls under
+ */
+ category?: string;
/**
* Concise description of the rule
*/
@@ -15,7 +19,7 @@ interface RuleMetaDataDocs {
@@ -20,7 +24,7 @@ export interface RuleMetaDataDocs<Options extends readonly unknown[]> {
* Used by the build tools to generate the recommended and strict configs.
* Set to false to not include it as a recommendation
* Exclude to not include it as a recommendation.
*/
- recommended: 'error' | 'strict' | 'warn' | false;
+ recommended?: 'error' | 'strict' | 'warn' | boolean;
- recommended?: RuleRecommendation | RuleRecommendationAcrossConfigs<Options>;
+ recommended?: RuleRecommendation | RuleRecommendationAcrossConfigs<Options> | boolean;
/**
* The URL of the rule's docs
*/
diff --git a/node_modules/@typescript-eslint/utils/dist/ts-eslint/RuleTester.d.ts b/node_modules/@typescript-eslint/utils/dist/ts-eslint/RuleTester.d.ts
index c8afefe..d629d04 100644
index 38d1f12..bf897a3 100644
--- a/node_modules/@typescript-eslint/utils/dist/ts-eslint/RuleTester.d.ts
+++ b/node_modules/@typescript-eslint/utils/dist/ts-eslint/RuleTester.d.ts
@@ -115,7 +115,7 @@ interface RunTests<TMessageIds extends string, TOptions extends Readonly<unknown
readonly invalid: readonly InvalidTestCase<TMessageIds, TOptions>[];
@@ -113,7 +113,7 @@ interface RunTests<MessageIds extends string, Options extends Readonly<unknown[]
readonly invalid: readonly InvalidTestCase<MessageIds, Options>[];
}
interface RuleTesterConfig extends Linter.Config {
interface RuleTesterConfig extends ClassicConfig.Config {
- readonly parser: string;
+ readonly parser?: string;
readonly parserOptions?: Readonly<ParserOptions>;
Expand Down
3 changes: 1 addition & 2 deletions src/rules/consistent-type-specifier-style.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { TSESLint, TSESTree } from '@typescript-eslint/utils'
import { getSourceCode } from 'eslint-compat-utils'

import { createRule } from '../utils'

Expand Down Expand Up @@ -74,7 +73,7 @@ export = createRule<[Options?], MessageId>({
},
defaultOptions: [],
create(context) {
const sourceCode = getSourceCode(context)
const { sourceCode } = context

if (context.options[0] === 'prefer-inline') {
return {
Expand Down
3 changes: 1 addition & 2 deletions src/rules/dynamic-import-chunkname.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import vm from 'node:vm'

import type { TSESTree } from '@typescript-eslint/utils'
import { getSourceCode } from 'eslint-compat-utils'

import { createRule } from '../utils'

Expand Down Expand Up @@ -75,7 +74,7 @@ export = createRule<[Options?], MessageId>({
const chunkSubstrRegex = new RegExp(chunkSubstrFormat)

function run(node: TSESTree.Node, arg: TSESTree.Node) {
const sourceCode = getSourceCode(context)
const { sourceCode } = context
const leadingComments = sourceCode.getCommentsBefore(arg)

if ((!leadingComments || leadingComments.length === 0) && !allowEmpty) {
Expand Down
11 changes: 7 additions & 4 deletions src/rules/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@ import {
} from '../utils'

const enumValues = {
enum: ['always', 'ignorePackages', 'never'] as const,
type: 'string' as const,
enum: ['always', 'ignorePackages', 'never'],
}

const patternProperties = {
type: 'object',
type: 'object' as const,
patternProperties: { '.*': enumValues },
}

const properties = {
type: 'object',
type: 'object' as const,
properties: {
pattern: patternProperties,
ignorePackages: { type: 'boolean' },
ignorePackages: {
type: 'boolean' as const,
},
},
}

Expand Down
3 changes: 1 addition & 2 deletions src/rules/first.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { TSESLint, TSESTree } from '@typescript-eslint/utils'
import { getSourceCode } from 'eslint-compat-utils'

import type { RuleContext } from '../types'
import { createRule } from '../utils'
Expand Down Expand Up @@ -53,7 +52,7 @@ export = createRule<['absolute-first'?], MessageId>({
}

const absoluteFirst = context.options[0] === 'absolute-first'
const sourceCode = getSourceCode(context)
const { sourceCode } = context
const originSourceCode = sourceCode.getText()

let nonImportCount = 0
Expand Down
2 changes: 1 addition & 1 deletion src/rules/group-exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export = createRule<[], 'ExportNamedDeclaration' | 'AssignmentExpression'>({
description:
'Prefer named exports to be grouped together in a single export declaration.',
},
schema: {},
schema: [],
messages: {
ExportNamedDeclaration:
'Multiple named export declarations; consolidate all named exports into a single export declaration',
Expand Down
10 changes: 2 additions & 8 deletions src/rules/named.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import path from 'node:path'

import type { TSESTree } from '@typescript-eslint/utils'
import { getFilename, getPhysicalFilename } from 'eslint-compat-utils'

import { ExportMap, createRule } from '../utils'
import type { ModuleOptions } from '../utils'
Expand Down Expand Up @@ -97,10 +96,7 @@ export = createRule<[ModuleOptions?], MessageId>({
if (deepLookup.path.length > 1) {
const deepPath = deepLookup.path
.map(i =>
path.relative(
path.dirname(getPhysicalFilename(context)),
i.path,
),
path.relative(path.dirname(context.physicalFilename), i.path),
)
.join(' -> ')

Expand Down Expand Up @@ -196,9 +192,7 @@ export = createRule<[ModuleOptions?], MessageId>({
if (!deepLookup.found) {
if (deepLookup.path.length > 1) {
const deepPath = deepLookup.path
.map(i =>
path.relative(path.dirname(getFilename(context)), i.path),
)
.map(i => path.relative(path.dirname(context.filename), i.path))
.join(' -> ')

context.report({
Expand Down
14 changes: 10 additions & 4 deletions src/rules/newline-after-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import type { TSESLint, TSESTree } from '@typescript-eslint/utils'
import debug from 'debug'
import { getPhysicalFilename } from 'eslint-compat-utils'

import { isStaticRequire, createRule, getScope } from '../utils'

Expand Down Expand Up @@ -245,7 +244,11 @@ export = createRule<[Options?], MessageId>({
}

// skip "export import"s
if (node.type === 'TSImportEqualsDeclaration' && node.isExport) {
if (
node.type === 'TSImportEqualsDeclaration' &&
// @ts-expect-error - legacy parser type
node.isExport
) {
return
}

Expand All @@ -254,7 +257,9 @@ export = createRule<[Options?], MessageId>({
} else if (
nextNode &&
nextNode.type !== 'ImportDeclaration' &&
(nextNode.type !== 'TSImportEqualsDeclaration' || nextNode.isExport)
(nextNode.type !== 'TSImportEqualsDeclaration' ||
// @ts-expect-error - legacy parser type
nextNode.isExport)
) {
checkForNewLine(node, nextNode, 'import')
}
Expand All @@ -269,7 +274,8 @@ export = createRule<[Options?], MessageId>({
}
},
'Program:exit'(node) {
log('exit processing for', getPhysicalFilename(context))
log('exit processing for', context.physicalFilename)

const scopeBody = getScopeBody(getScope(context, node))

log('got scope:', scopeBody)
Expand Down
5 changes: 1 addition & 4 deletions src/rules/no-absolute-path.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import path from 'node:path'

import { getPhysicalFilename } from 'eslint-compat-utils'

import {
isAbsolute,
createRule,
Expand Down Expand Up @@ -37,10 +35,9 @@ export = createRule<[ModuleOptions?], MessageId>({
node: source,
messageId: 'absolute',
fix(fixer) {
const resolvedContext = getPhysicalFilename(context)
// node.js and web imports work with posix style paths ("/")
let relativePath = path.posix.relative(
path.dirname(resolvedContext),
path.dirname(context.physicalFilename),
source.value,
)
if (!relativePath.startsWith('.')) {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-anonymous-default-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const schemaProperties = Object.fromEntries(
def.option,
{
description: def.description,
type: 'boolean',
type: 'boolean' as const,
},
]),
)
Expand Down
7 changes: 6 additions & 1 deletion src/rules/no-commonjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ export = createRule<[Options?], MessageId>({
anyOf: [
{
type: 'array',
items: [{ enum: ['allow-primitive-modules'] }],
items: [
{
type: 'string',
enum: ['allow-primitive-modules'],
},
],
additionalItems: false,
},
{
Expand Down
Loading

0 comments on commit 49418a0

Please sign in to comment.