diff --git a/.changeset/sixty-games-love.md b/.changeset/sixty-games-love.md new file mode 100644 index 0000000..043d18e --- /dev/null +++ b/.changeset/sixty-games-love.md @@ -0,0 +1,5 @@ +--- +"@intlify/eslint-plugin-svelte": minor +--- + +feat: add support for eslint v9 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0940e28..7b28810 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,6 +30,10 @@ jobs: os: [ubuntu-latest] node: [18, 20] eslint: [8] + include: + - node: 20 + eslint: ^9.0.0-0 + os: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2 diff --git a/lib/utils/index.ts b/lib/utils/index.ts index 9182ba4..86ce0ae 100644 --- a/lib/utils/index.ts +++ b/lib/utils/index.ts @@ -6,6 +6,7 @@ import type { Rule } from 'eslint' import { dirname, extname } from 'path' import { existsSync } from 'fs' import type { RuleContext, RuleListener } from '../types' +import { getFilename, getSourceCode } from 'eslint-compat-utils' const UNEXPECTED_ERROR_LOCATION = { line: 1, column: 0 } @@ -37,8 +38,9 @@ export function defineRule( } }, create(context) { - if (!context.parserServices.isSvelte) { - const filename = context.getFilename() + const sourceCode = getSourceCode(context) + if (!sourceCode.parserServices.isSvelte) { + const filename = getFilename(context) if (isSvelteFile(filename)) { context.report({ loc: UNEXPECTED_ERROR_LOCATION, diff --git a/package.json b/package.json index 2985837..ab9af8d 100644 --- a/package.json +++ b/package.json @@ -25,10 +25,11 @@ }, "dependencies": { "debug": "^4.3.1", + "eslint-compat-utils": "^0.4.1", "svelte-eslint-parser": ">=0.9.0 <1.0.0" }, "peerDependencies": { - "eslint": "^7.0.0 || ^8.0.0-0", + "eslint": "^7.0.0 || ^8.0.0-0 || ^9.0.0-0", "svelte": "^3.37.0 || ^4.0.5" }, "peerDependenciesMeta": { diff --git a/tests/lib/eslint-compat.ts b/tests/lib/eslint-compat.ts new file mode 100644 index 0000000..076bfbb --- /dev/null +++ b/tests/lib/eslint-compat.ts @@ -0,0 +1,3 @@ +import { getRuleTester } from 'eslint-compat-utils/rule-tester' + +export const RuleTester = getRuleTester() diff --git a/tests/lib/rules/no-raw-text.ts b/tests/lib/rules/no-raw-text.ts index 30e592d..135e384 100644 --- a/tests/lib/rules/no-raw-text.ts +++ b/tests/lib/rules/no-raw-text.ts @@ -1,12 +1,13 @@ /** * @author Yosuke Ota */ -import { RuleTester } from 'eslint' -import rule = require('../../../lib/rules/no-raw-text') +import { RuleTester } from '../eslint-compat' +import rule from '../../../lib/rules/no-raw-text' +import * as svelteParser from 'svelte-eslint-parser' const tester = new RuleTester({ - parser: require.resolve('svelte-eslint-parser'), - parserOptions: { + languageOptions: { + parser: svelteParser, ecmaVersion: 2021, sourceType: 'module' } @@ -235,7 +236,7 @@ tester.run('no-raw-text', rule as never, { code: ` - + text at the root of the template `, errors: [ diff --git a/tsconfig.json b/tsconfig.json index 14ea3a0..a611570 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,7 @@ /* Basic Options */ // "incremental": true, /* Enable incremental compilation */ "target": "es2015" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */, - "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */, + "module": "node16" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */, // "lib": [], /* Specify library files to be included in the compilation. */ "allowJs": true /* Allow javascript files to be compiled. */, // "checkJs": true, /* Report errors in .js files. */ @@ -39,7 +39,7 @@ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ /* Module Resolution Options */ - "moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */, + "moduleResolution": "node16" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */, "resolveJsonModule": true, // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ diff --git a/yarn.lock b/yarn.lock index f6e9834..62612cb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4378,6 +4378,13 @@ escape-string-regexp@^4.0.0: resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34" integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA== +eslint-compat-utils@^0.4.1: + version "0.4.1" + resolved "https://registry.yarnpkg.com/eslint-compat-utils/-/eslint-compat-utils-0.4.1.tgz#498d9dad03961174a283f7741838a3fbe4a34e89" + integrity sha512-5N7ZaJG5pZxUeNNJfUchurLVrunD1xJvyg5kYOIVF8kg1f3ajTikmAu/5fZ9w100omNPOoMjngRszh/Q/uFGMg== + dependencies: + semver "^7.5.4" + eslint-config-prettier@^8.0.0: version "8.0.0" resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-8.0.0.tgz#024d661444319686c588c8849c8da33815dbdb1c"