Skip to content

Commit

Permalink
feat: support typescript-eslint@8 (#418)
Browse files Browse the repository at this point in the history
* feat: support typescript-eslint@8

* Create late-dancers-guess.md

---------

Co-authored-by: Yosuke Ota <otameshiyo23@gmail.com>
  • Loading branch information
JoshuaKGoldberg and ota-meshi authored Sep 13, 2024
1 parent 4d771f7 commit b03d0d5
Show file tree
Hide file tree
Showing 22 changed files with 83 additions and 74 deletions.
5 changes: 5 additions & 0 deletions .changeset/late-dancers-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-astro": patch
---

feat: support typescript-eslint@8
4 changes: 2 additions & 2 deletions docs-build/src/components/eslint/MonacoEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
}
}
$: {
// eslint-disable-next-line no-unused-expressions -- reactive
// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- reactive
language
disposeCodeActionProvider()
if (provideCodeActions) {
Expand All @@ -78,7 +78,7 @@
}
}
$: {
// eslint-disable-next-line no-unused-expressions -- reactive
// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- reactive
language
// Set the language to the current editors.
for (const editor of [getLeftEditor?.(), getRightEditor?.()]) {
Expand Down
17 changes: 13 additions & 4 deletions docs-build/src/components/eslint/scripts/linter.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Linter, Rule } from "eslint"
import { builtinRules } from "eslint/use-at-your-own-risk"
import * as astroEslintParser from "astro-eslint-parser"
import * as processors from "../../../../../src/processor/index.js"
import type { RuleModule } from "../../../../../src/types.js"
import globals from "globals"

export const categories: {
Expand Down Expand Up @@ -72,12 +73,19 @@ export const categories: {
]
export const DEFAULT_RULES_CONFIG: Record<string, string> = {}

const rules = []
interface DocsRuleLike {
ruleId: string
rule: RuleModule | Rule.RuleModule
classes: string
url: string | undefined
}

const rules: DocsRuleLike[] = []
for (const rule of pluginRules) {
if (rule.meta.deprecated) {
continue
}
const data = {
const data: DocsRuleLike = {
ruleId: rule.meta.docs.ruleId,
rule,
classes: "svelte-rule",
Expand All @@ -96,7 +104,7 @@ for (const [ruleId, rule] of builtinRules) {
if (rule.meta!.deprecated) {
continue
}
const data = {
const data: DocsRuleLike = {
ruleId,
rule,
classes: "core-rule",
Expand Down Expand Up @@ -132,7 +140,7 @@ export function rulesMap(): Map<string, Rule.RuleModule> {
])
}

export async function createLinterConfig(): Promise<Linter.FlatConfig[]> {
export async function createLinterConfig(): Promise<Linter.Config[]> {
const tsParser = await import("@typescript-eslint/parser")

await (astroEslintParser as any).setup()
Expand All @@ -141,6 +149,7 @@ export async function createLinterConfig(): Promise<Linter.FlatConfig[]> {
files: ["**"],
plugins: {
astro: {
// @ts-expect-error -- typing bug
rules: Object.fromEntries(
pluginRules.map((rule) => [rule.meta.docs.ruleName, rule]),
) as Record<string, Rule.RuleModule>,
Expand Down
1 change: 1 addition & 0 deletions eslint.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ module.exports = [
"one-var": "off",
"func-style": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-empty-object-type": "off",
"prefer-const": "off",
"@typescript-eslint/no-unused-vars": "off",

Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"dependencies": {
"@eslint-community/eslint-utils": "^4.2.0",
"@jridgewell/sourcemap-codec": "^1.4.14",
"@typescript-eslint/types": "^7.7.1",
"@typescript-eslint/types": "^7.7.1 || ^8",
"astro-eslint-parser": "^1.0.2",
"eslint-compat-utils": "^0.5.0",
"globals": "^15.0.0",
Expand Down Expand Up @@ -96,16 +96,16 @@
"@types/react": "^18.0.15",
"@types/semver": "^7.3.9",
"@types/stylus": "^0.48.38",
"@typescript-eslint/eslint-plugin": "^7.7.1",
"@typescript-eslint/parser": "^7.7.1",
"@typescript-eslint/eslint-plugin": "^8.5.0",
"@typescript-eslint/parser": "^8.5.0",
"assert": "^2.0.0",
"astro": "^4.5.0",
"env-cmd": "^10.1.0",
"esbuild": "^0.23.0",
"esbuild-register": "^3.3.3",
"eslint": "^9.0.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-astro": "^1.0.2",
"eslint-plugin-astro": "^1.2.3",
"eslint-plugin-eslint-plugin": "^6.0.0",
"eslint-plugin-jsdoc": "^50.0.0",
"eslint-plugin-json-schema-validator": "^5.0.0",
Expand Down Expand Up @@ -136,7 +136,7 @@
"svelte": "^4.0.0",
"tsup": "^8.0.2",
"typescript": "~5.4.0",
"typescript-eslint": "^7.5.0",
"typescript-eslint": "^8.5.0",
"vite-plugin-eslint4b": "^0.4.0"
},
"publishConfig": {
Expand Down
4 changes: 2 additions & 2 deletions src/a11y/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import flatBase from "../configs/flat/base"
import type { Linter } from "eslint"

/** Build a11y configs */
export function buildFlatConfigs(): Record<string, Linter.FlatConfig[]> {
const configs: Record<string, Linter.FlatConfig[]> = {}
export function buildFlatConfigs(): Record<string, Linter.Config[]> {
const configs: Record<string, Linter.Config[]> = {}

for (const configName of a11yConfigKeys) {
// flat config
Expand Down
2 changes: 1 addition & 1 deletion src/a11y/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function buildA11yRules(): RuleModule[] {
}

/** Build a11y configs */
export function buildA11yFlatConfigs(): Record<string, Linter.FlatConfig[]> {
export function buildA11yFlatConfigs(): Record<string, Linter.Config[]> {
return buildFlatConfigs()
}

Expand Down
38 changes: 19 additions & 19 deletions src/cjs-config-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import { buildA11yFlatConfigs, buildA11yLegacyConfigs } from "./a11y"
import type { Linter } from "eslint"

type CJSConfigs = {
base: Linter.Config
recommended: Linter.Config
all: Linter.Config
"jsx-a11y-strict": Linter.Config
"jsx-a11y-recommended": Linter.Config
"flat/base": Linter.FlatConfig[]
"flat/recommended": Linter.FlatConfig[]
"flat/all": Linter.FlatConfig[]
"flat/jsx-a11y-strict": Linter.FlatConfig[]
"flat/jsx-a11y-recommended": Linter.FlatConfig[]
base: Linter.LegacyConfig
recommended: Linter.LegacyConfig
all: Linter.LegacyConfig
"jsx-a11y-strict": Linter.LegacyConfig
"jsx-a11y-recommended": Linter.LegacyConfig
"flat/base": Linter.Config[]
"flat/recommended": Linter.Config[]
"flat/all": Linter.Config[]
"flat/jsx-a11y-strict": Linter.Config[]
"flat/jsx-a11y-recommended": Linter.Config[]
}

/**
Expand All @@ -26,15 +26,15 @@ type CJSConfigs = {
export function buildCjsConfigs(): CJSConfigs {
const cjsConfigs: CJSConfigs = {
base: buildLegacyBase(),
recommended: recommended as Linter.Config,
all: all as Linter.Config,
"jsx-a11y-strict": null as never as Linter.Config,
"jsx-a11y-recommended": null as never as Linter.Config,
"flat/base": flatBase as Linter.FlatConfig[],
"flat/recommended": flatRecommended as Linter.FlatConfig[],
"flat/all": flatAll as Linter.FlatConfig[],
"flat/jsx-a11y-strict": null as never as Linter.FlatConfig[],
"flat/jsx-a11y-recommended": null as never as Linter.FlatConfig[],
recommended: recommended as Linter.LegacyConfig,
all: all as Linter.LegacyConfig,
"jsx-a11y-strict": null as never as Linter.LegacyConfig,
"jsx-a11y-recommended": null as never as Linter.LegacyConfig,
"flat/base": flatBase as Linter.Config[],
"flat/recommended": flatRecommended as Linter.Config[],
"flat/all": flatAll as Linter.Config[],
"flat/jsx-a11y-strict": null as never as Linter.Config[],
"flat/jsx-a11y-recommended": null as never as Linter.Config[],
}

const a11yFlatConfigs = buildA11yFlatConfigs()
Expand Down
2 changes: 1 addition & 1 deletion src/configs/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { hasTypescriptEslintParser } from "./has-typescript-eslint-parser"
/**
* Build legacy base config
*/
export function buildLegacyBase(): Linter.Config {
export function buildLegacyBase(): Linter.LegacyConfig {
return {
plugins: ["astro"],
overrides: [
Expand Down
32 changes: 16 additions & 16 deletions src/esm-config-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,32 @@ import { buildA11yFlatConfigs } from "./a11y"
import type { Linter } from "eslint"

type ESMConfigs = {
base: Linter.FlatConfig[]
recommended: Linter.FlatConfig[]
all: Linter.FlatConfig[]
"jsx-a11y-strict": Linter.FlatConfig[]
"jsx-a11y-recommended": Linter.FlatConfig[]
base: Linter.Config[]
recommended: Linter.Config[]
all: Linter.Config[]
"jsx-a11y-strict": Linter.Config[]
"jsx-a11y-recommended": Linter.Config[]
// For backward compatibility
"flat/base": Linter.FlatConfig[]
"flat/recommended": Linter.FlatConfig[]
"flat/all": Linter.FlatConfig[]
"flat/jsx-a11y-strict": Linter.FlatConfig[]
"flat/jsx-a11y-recommended": Linter.FlatConfig[]
"flat/base": Linter.Config[]
"flat/recommended": Linter.Config[]
"flat/all": Linter.Config[]
"flat/jsx-a11y-strict": Linter.Config[]
"flat/jsx-a11y-recommended": Linter.Config[]
}
/**
* Build configs for ESM Module
*/
export function buildEsmConfigs(): ESMConfigs {
const esmConfigs: ESMConfigs = {
base: flatBase as Linter.FlatConfig[],
recommended: flatRecommended as Linter.FlatConfig[],
all: flatAll as Linter.FlatConfig[],
base: flatBase as Linter.Config[],
recommended: flatRecommended as Linter.Config[],
all: flatAll as Linter.Config[],
"jsx-a11y-strict": null as never,
"jsx-a11y-recommended": null as never,
// For backward compatibility
"flat/base": flatBase as Linter.FlatConfig[],
"flat/recommended": flatRecommended as Linter.FlatConfig[],
"flat/all": flatAll as Linter.FlatConfig[],
"flat/base": flatBase as Linter.Config[],
"flat/recommended": flatRecommended as Linter.Config[],
"flat/all": flatAll as Linter.Config[],
"flat/jsx-a11y-strict": null as never,
"flat/jsx-a11y-recommended": null as never,
}
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-unused-css-selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default createRule("no-unused-css-selector", {
let root
try {
root = postcss.parse(css.css)
} catch (_e) {
} catch {
return
}
const ignoreNodes = new Set<PostcssNode>()
Expand Down
2 changes: 1 addition & 1 deletion src/utils/transform/less.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function transform(
output: output.css,
mappings: JSON.parse(output.map).mappings,
}
} catch (_e) {
} catch {
return null
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/utils/transform/postcss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ export function transform(
output: result.content,
mappings: result.map.toJSON().mappings,
}
} catch (_e) {
// console.log(_e)
} catch {
return null
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/transform/sass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function transform(
output: output.css,
mappings: output.sourceMap!.mappings,
}
} catch (_e) {
} catch {
return null
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/transform/stylus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function transform(
mappings: (style as unknown as { sourcemap: RawSourceMap }).sourcemap
.mappings,
}
} catch (_e) {
} catch {
return null
}
}
Expand Down
5 changes: 1 addition & 4 deletions tests/src/config/recommended.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe("`recommended` config", () => {
astro: plugin as never,
},
baseConfig: {
// @ts-expect-error -- typing bug

Check failure on line 22 in tests/src/config/recommended.ts

View workflow job for this annotation

GitHub Actions / test-for-eslint-v8

Unused '@ts-expect-error' directive.
parserOptions: {
ecmaVersion: 2020,
},
Expand Down Expand Up @@ -46,9 +47,7 @@ describe("`recommended` config", () => {
})
it("`flat/recommended` config should work. ", async () => {
const linter = new FlatESLint({
// @ts-expect-error -- typing bug
overrideConfigFile: true,

Check failure on line 50 in tests/src/config/recommended.ts

View workflow job for this annotation

GitHub Actions / test-for-eslint-v8

Type 'boolean' is not assignable to type 'string'.
// @ts-expect-error -- typing bug
overrideConfig: [...plugin.configs["flat/recommended"]],

Check failure on line 51 in tests/src/config/recommended.ts

View workflow job for this annotation

GitHub Actions / test-for-eslint-v8

Type 'Config<RulesRecord, RulesRecord>[]' has no properties in common with type 'Config<RulesRecord, RulesRecord>'.
})
const result = await linter.lintText(code, { filePath: "test.astro" })
Expand All @@ -71,9 +70,7 @@ describe("`recommended` config", () => {
})
it("`flat/recommended` config with *.js should work. ", async () => {
const linter = new FlatESLint({
// @ts-expect-error -- typing bug
overrideConfigFile: true,

Check failure on line 73 in tests/src/config/recommended.ts

View workflow job for this annotation

GitHub Actions / test-for-eslint-v8

Type 'boolean' is not assignable to type 'string'.
// @ts-expect-error -- typing bug
overrideConfig: [...plugin.configs["flat/recommended"]],

Check failure on line 74 in tests/src/config/recommended.ts

View workflow job for this annotation

GitHub Actions / test-for-eslint-v8

Type 'Config<RulesRecord, RulesRecord>[]' has no properties in common with type 'Config<RulesRecord, RulesRecord>'.
})

Expand Down
2 changes: 1 addition & 1 deletion tests/src/integration/client-javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe("Integration test for client-side script", () => {
},
useEslintrc: false,
overrideConfig: {
// @ts-expect-error -- typing bug

Check failure on line 31 in tests/src/integration/client-javascript.ts

View workflow job for this annotation

GitHub Actions / test-for-eslint-v8

Unused '@ts-expect-error' directive.
extends: ["plugin:astro/base"],
rules: {
"no-restricted-syntax": ["error", "Identifier[name='id']"],
Expand All @@ -36,7 +37,6 @@ describe("Integration test for client-side script", () => {
})
: new ESLint({
overrideConfigFile: true as any,
// @ts-expect-error -- typing bug
overrideConfig: [

Check failure on line 40 in tests/src/integration/client-javascript.ts

View workflow job for this annotation

GitHub Actions / test-for-eslint-v8

Type '(Config<RulesRecord, RulesRecord> | { rules: Record<string, any>; })[]' has no properties in common with type 'Config<RulesRecord, RulesRecord>'.
...astroPlugin.configs["flat/base"],
{
Expand Down
4 changes: 3 additions & 1 deletion tests/src/integration/client-typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe("Integration test for client-side ts", () => {
},
useEslintrc: false,
overrideConfig: {
// @ts-expect-error -- typing bug

Check failure on line 32 in tests/src/integration/client-typescript.ts

View workflow job for this annotation

GitHub Actions / test-for-eslint-v8

Unused '@ts-expect-error' directive.
extends: ["plugin:astro/base"],
parser: "@typescript-eslint/parser",
rules: {
Expand All @@ -49,11 +50,12 @@ describe("Integration test for client-side ts", () => {
})
: new ESLint({
overrideConfigFile: true as any,
// @ts-expect-error -- typing bug
overrideConfig: [

Check failure on line 53 in tests/src/integration/client-typescript.ts

View workflow job for this annotation

GitHub Actions / test-for-eslint-v8

Type '(Config<RulesRecord, RulesRecord> | { files: string[]; languageOptions: { parser: typeof import("/home/runner/work/eslint-plugin-astro/eslint-plugin-astro/node_modules/@typescript-eslint/parser/dist/index") | null; }; rules: Record<...>; })[]' has no properties in common with type 'Config<RulesRecord, RulesRecord>'.
// @ts-expect-error -- typing bug

Check failure on line 54 in tests/src/integration/client-typescript.ts

View workflow job for this annotation

GitHub Actions / test-for-eslint-v8

Unused '@ts-expect-error' directive.
...astroPlugin.configs["flat/base"],
{
files: ["*.ts", "**/*.ts"],
// @ts-expect-error -- typing bug
languageOptions: {
parser: tsESLintParser,
},
Expand Down
4 changes: 2 additions & 2 deletions tests/src/integration/config-for-a11y.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ describe("Integration test for a11y config", () => {
},
useEslintrc: false,
overrideConfig: {
// @ts-expect-error -- typing bug
extends: ["plugin:astro/jsx-a11y-strict"],
},
})
: new ESLint({
overrideConfigFile: true as any,
// @ts-expect-error -- typing bug
overrideConfig: astroPlugin.configs["flat/jsx-a11y-strict"],
})

Expand Down Expand Up @@ -80,12 +80,12 @@ const src = 'icon.png'
},
useEslintrc: false,
overrideConfig: {
// @ts-expect-error -- typing bug
extends: ["plugin:astro/jsx-a11y-recommended"],
},
})
: new ESLint({
overrideConfigFile: true as any,
// @ts-expect-error -- typing bug
overrideConfig: astroPlugin.configs["flat/jsx-a11y-recommended"],
})

Expand Down
Loading

0 comments on commit b03d0d5

Please sign in to comment.