Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: bump typescript-eslint to v8 #112

Merged
merged 37 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
8b3ff98
chore/ci: bump Node.js requirement to 18.18
SukkaW Jul 12, 2024
1d45ef5
chore(devDeps): bump typescript eslint to v8
SukkaW Jul 12, 2024
cf1d9b6
refactor: adapt typescript-eslint v8
SukkaW Jul 12, 2024
fe795c4
fix: avoid useless patch
SukkaW Jul 12, 2024
c08d150
ci: test against ESLint v9
SukkaW Jul 12, 2024
467363c
test: FlatRuleTester for both ESLint 8 & 9
SukkaW Jul 12, 2024
4889d3f
chore: housekeeping for ts-eslint 8
SukkaW Aug 2, 2024
980ec75
test: migrate rule tester runner config
SukkaW Aug 2, 2024
c5bf9f6
test: migrate new test cases config
SukkaW Aug 2, 2024
ff5263a
test: migrate new test cases config
SukkaW Aug 2, 2024
dc5d7f4
test: migrate new test cases config
SukkaW Aug 2, 2024
1216dd7
test: migrate new test cases
SukkaW Aug 7, 2024
42ff768
test: migrate new test cases
SukkaW Aug 7, 2024
d45e264
test: migrate new test cases
SukkaW Aug 7, 2024
e12af09
test: fix ts parser not recognizing export identifier
SukkaW Aug 7, 2024
d74394d
test: typescript eslint parser doesn't support export identifier
SukkaW Aug 7, 2024
7d2f452
test: fix cases
SukkaW Aug 7, 2024
29462c0
test: fix another 12 test cases
SukkaW Aug 7, 2024
f40ab8e
test: fix another 3 test cases
SukkaW Aug 7, 2024
ed1d953
test: fix cases
SukkaW Aug 7, 2024
3ef285a
test: fix another 1 case
SukkaW Aug 7, 2024
fc97ca6
chore: bump a few deps
SukkaW Aug 7, 2024
29491d0
chore: make eslint happy
SukkaW Aug 7, 2024
f77b4c2
Fix 88 tests
merrywhether Aug 14, 2024
945e8f8
test(extensions): update test group name
SukkaW Aug 14, 2024
a78a9a3
merge(#3): merrywhether/help-fix-some-tests
SukkaW Aug 14, 2024
152d3e9
test: fix no-absolute-path (#4)
merrywhether Aug 14, 2024
e523937
test: fix another error
SukkaW Aug 14, 2024
4fef125
chore: housekeeping
SukkaW Aug 14, 2024
49edefe
test: fix 4 tests
SukkaW Aug 14, 2024
c98e823
test: fix flow tests
SukkaW Aug 14, 2024
b534ddf
test: add hermes-eslint support
SukkaW Aug 14, 2024
8cc48a4
test: remove 2 meaningless tests
SukkaW Aug 14, 2024
5d4d2e2
test: use legacy eslint for eslintrc test
SukkaW Aug 14, 2024
098d6b7
chore: make lint happy
SukkaW Aug 14, 2024
04c58ed
chore: update eslint and node version
SukkaW Aug 14, 2024
f25124f
chore: add changeset
SukkaW Aug 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/smooth-donkeys-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-import-x": major
---

Use typescript-eslint v8. The minimum supported ESLint version is now >= 8.57.0 and the minimum required Node.js version is now 18.18.0.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {
},
rules: {
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-require-imports': 'off',

'eslint-plugin/consistent-output': ['error', 'always'],
'eslint-plugin/meta-property-ordering': 'error',
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ jobs:
- ubuntu-latest
# - windows-latest
node:
- 16
- 18
- 20
- 22
eslint:
- '8.56'
- '8'
- '9'
runs-on: ${{ matrix.os }}
steps:
- name: Checkout Repo
Expand Down
58 changes: 32 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "MIT",
"packageManager": "yarn@1.22.19",
"engines": {
"node": ">=16"
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
},
"main": "lib/index.js",
"exports": {
Expand Down Expand Up @@ -35,7 +35,7 @@
"codesandbox:install": "yarn --ignore-engines",
"lint": "run-p lint:*",
"lint:docs": "yarn update:eslint-docs --check",
"lint:es": "eslint . --cache",
"lint:es": "ESLINT_USE_FLAT_CONFIG=false eslint . --cache",
"lint:tsc": "tsc -p tsconfig.base.json --noEmit",
"prepare": "patch-package",
"release": "changeset publish",
Expand All @@ -45,57 +45,60 @@
"watch": "yarn test --watch"
},
"peerDependencies": {
"eslint": "^8.56.0 || ^9.0.0-0"
"eslint": "^8.57.0 || ^9.0.0"
},
"dependencies": {
"@typescript-eslint/utils": "^7.4.0",
"@typescript-eslint/utils": "^8.1.0",
"debug": "^4.3.4",
"doctrine": "^3.0.0",
"eslint-import-resolver-node": "^0.3.9",
"get-tsconfig": "^4.7.3",
"is-glob": "^4.0.3",
"minimatch": "^9.0.3",
"semver": "^7.6.0",
"semver": "^7.6.3",
"stable-hash": "^0.0.4",
"tslib": "^2.6.2"
"tslib": "^2.6.3"
},
"devDependencies": {
"@1stg/prettier-config": "^4.0.1",
"@1stg/tsconfig": "^2.3.3",
"@angular-eslint/template-parser": "^17.3.0",
"@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",
"@angular-eslint/template-parser": "^17.5.2",
"@babel/core": "^7.25.2",
"@babel/eslint-parser": "^7.25.1",
"@babel/plugin-proposal-decorators": "^7.24.7",
"@babel/plugin-proposal-export-default-from": "^7.24.7",
"@babel/preset-env": "^7.25.3",
"@babel/preset-flow": "^7.24.7",
"@babel/preset-react": "^7.24.7",
"@babel/preset-typescript": "^7.24.7",
"@babel/register": "^7.24.6",
"@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.11",
"@swc/helpers": "^0.5.7",
"@swc-node/jest": "^1.8.12",
"@swc/core": "^1.7.6",
"@swc/helpers": "^0.5.12",
"@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.6",
"@types/eslint": "^9.6.0",
"@types/eslint8.56": "npm:@types/eslint@^8.56.11",
"@types/eslint9": "npm:@types/eslint@^9.6.0",
"@types/is-glob": "^4.0.4",
"@types/jest": "^29.5.12",
"@types/json-schema": "^7.0.15",
"@types/node": "^20.11.30",
"@typescript-eslint/eslint-plugin": "^7.4.0",
"@typescript-eslint/parser": "^7.4.0",
"@typescript-eslint/eslint-plugin": "^8.1.0",
"@typescript-eslint/parser": "^8.1.0",
"@typescript-eslint/rule-tester": "^8.1.0",
"@unts/patch-package": "^8.0.0",
"cross-env": "^7.0.3",
"enhanced-resolve": "^5.16.0",
"escope": "^4.0.0",
"eslint": "^7.2.0 || ^8",
"eslint": "^9.9.0",
"eslint-config-prettier": "^9.1.0",
"eslint-doc-generator": "^1.7.0",
"eslint-doc-generator": "^1.7.1",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-import-resolver-webpack": "^0.13.8",
"eslint-import-test-order-redirect": "link:./test/fixtures/order-redirect",
Expand All @@ -106,14 +109,17 @@
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-unicorn": "^51.0.1",
"eslint8.56": "npm:eslint@^8.56.0",
"eslint9": "npm:eslint@^9.8.0",
"hermes-eslint": "^0.23.1",
"jest": "^29.7.0",
"npm-run-all2": "^6.1.2",
"prettier": "^3.2.5",
"redux": "^5.0.1",
"rimraf": "^5.0.5",
"rimraf": "^5.0.10",
"svelte": "^4.2.12",
"ts-node": "^10.9.2",
"type-fest": "^4.14.0",
"typescript": "^5.4.3"
"typescript": "^5.5.4"
}
}
37 changes: 0 additions & 37 deletions patches/@typescript-eslint+utils+7.4.0.patch

This file was deleted.

8 changes: 5 additions & 3 deletions src/config/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ export = {
settings: {
'import-x/extensions': ['.js', '.jsx'],
},
parserOptions: {
ecmaFeatures: {
jsx: true,
languageOptions: {
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
} satisfies PluginConfig
2 changes: 1 addition & 1 deletion src/rules/dynamic-import-chunkname.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import vm from 'node:vm'

import type { TSESTree } from '@typescript-eslint/utils'
import type { RuleFixer } from '@typescript-eslint/utils/dist/ts-eslint'
import type { RuleFixer } from '@typescript-eslint/utils/ts-eslint'

import { createRule } from '../utils'

Expand Down
8 changes: 1 addition & 7 deletions src/rules/imports-first.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import { ESLintUtils } from '@typescript-eslint/utils'

import { docsUrl } from '../utils/docs-url'
import { createRule } from '../utils'

import first from './first'

const createRule = ESLintUtils.RuleCreator(ruleName =>
docsUrl(ruleName, '7b25c1cb95ee18acc1531002fd343e1e6031f9ed'),
)

export = createRule({
...first,
name: 'imports-first',
Expand Down
18 changes: 11 additions & 7 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { TSESLint, TSESTree } from '@typescript-eslint/utils'
import type { ResolveOptions } from 'enhanced-resolve'
import type { TsResolverOptions } from 'eslint-import-resolver-typescript'
import type { MinimatchOptions } from 'minimatch'
import type { KebabCase, LiteralUnion } from 'type-fest'

Expand All @@ -21,6 +20,12 @@ export type WebpackResolverOptions = {
argv?: Record<string, unknown>
}

export type TsResolverOptions = {
alwaysTryTypes?: boolean
project?: string[] | string
extensions?: string[]
} & Omit<ResolveOptions, 'fileSystem' | 'useSyncFileSystemCalls'>

export type FileExtension = `.${string}`

export type DocStyle = 'jsdoc' | 'tomdoc'
Expand Down Expand Up @@ -63,7 +68,7 @@ export type PluginConfig = {
plugins?: [PluginName]
settings?: PluginSettings
rules?: Record<`${PluginName}/${string}`, TSESLint.Linter.RuleEntry>
} & TSESLint.Linter.Config
} & TSESLint.Linter.ConfigType

export type RuleContext<
TMessageIds extends string = string,
Expand All @@ -89,11 +94,10 @@ export type ParseError = {
column: number
} & Error

// eslint-disable-next-line @typescript-eslint/ban-types
export type CustomESTreeNode<Type extends string, T extends object = {}> = Omit<
TSESTree.BaseNode,
'type'
> & {
export type CustomESTreeNode<
Type extends string,
T extends object = object,
> = Omit<TSESTree.BaseNode, 'type'> & {
type: Type
} & T

Expand Down
11 changes: 10 additions & 1 deletion src/utils/create-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@ import { ESLintUtils } from '@typescript-eslint/utils'

import { docsUrl } from './docs-url'

export const createRule = ESLintUtils.RuleCreator(docsUrl)
type ImportXPluginDocs = {
/**
* The category the rule falls under
*/
category?: string

recommended?: true
}

export const createRule = ESLintUtils.RuleCreator<ImportXPluginDocs>(docsUrl)
7 changes: 4 additions & 3 deletions src/utils/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import { moduleRequire } from './module-require'
const log = debug('eslint-plugin-import-x:parse')

function keysFromParser(
parserPath: string | TSESLint.Linter.ParserModule,
parserInstance: TSESLint.Linter.ParserModule,
parsedResult?: TSESLint.Linter.ESLintParseResult,
parserPath: string | TSESLint.Parser.ParserModule,
parserInstance: TSESLint.Parser.ParserModule,
parsedResult?: TSESLint.Parser.ParseResult,
) {
// Exposed by @typescript-eslint/parser and @babel/eslint-parser
if (parsedResult && parsedResult.visitorKeys) {
Expand Down Expand Up @@ -130,6 +130,7 @@ export function parse(
console.warn(
// Can only be invalid for custom parser per imports/parser
`\`parseForESLint\` from parser \`${typeof parserOrPath === 'string' ? parserOrPath : '`context.languageOptions.parser`'}\` is invalid and will just be ignored`,
{ content, parserMeta: parser.meta },
)
} else {
return makeParseReturn(ast, keysFromParser(parserOrPath, parser))
Expand Down
12 changes: 5 additions & 7 deletions test/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@

import path from 'node:path'

import { ESLint } from 'eslint'
import eslintPkg from 'eslint/package.json'
import { LegacyESLint } from 'eslint/use-at-your-own-risk'
import semver from 'semver'

import importPlugin from 'eslint-plugin-import-x'

describe('CLI regression tests', () => {
describe('issue #210', () => {
it("doesn't throw an error on gratuitous, erroneous self-reference", () => {
const eslint = new ESLint({
useEslintrc: false,
const eslint = new LegacyESLint({
overrideConfigFile: './test/fixtures/issue210.config.js',
rulePaths: ['./src/rules'],
// rulePaths: ['./src/rules'],
overrideConfig: {
rules: {
named: 2,
Expand All @@ -34,10 +33,8 @@ describe('CLI regression tests', () => {
describe('issue #1645', () => {
it('throws an error on invalid JSON', async () => {
const invalidJSON = './test/fixtures/just-json-files/invalid.json'
const eslint = new ESLint({
useEslintrc: false,
const eslint = new LegacyESLint({
overrideConfigFile: './test/fixtures/just-json-files/.eslintrc.json',
rulePaths: ['./src/rules'],
ignore: false,
plugins: {
// @ts-expect-error - incompatible types
Expand All @@ -58,6 +55,7 @@ describe('CLI regression tests', () => {
nodeType: results[0].messages[0].nodeType, // we don't care about this one
ruleId: 'json/*',
severity: 2,
// @ts-expect-error - legacy types
source: results[0].messages[0].source, // NewLine-characters might differ depending on git-settings
},
],
Expand Down
Loading
Loading