Skip to content

Commit

Permalink
feat: add support for eslint v9 (#12)
Browse files Browse the repository at this point in the history
* feat: add support for eslint v9

* Create sixty-games-love.md

* fix
  • Loading branch information
ota-meshi authored Jan 17, 2024
1 parent bdfeb70 commit e0acb96
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-games-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@intlify/eslint-plugin-svelte": minor
---

feat: add support for eslint v9
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
3 changes: 3 additions & 0 deletions tests/lib/eslint-compat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { getRuleTester } from 'eslint-compat-utils/rule-tester'

export const RuleTester = getRuleTester()
11 changes: 6 additions & 5 deletions tests/lib/rules/no-raw-text.ts
Original file line number Diff line number Diff line change
@@ -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'
}
Expand Down Expand Up @@ -235,7 +236,7 @@ tester.run('no-raw-text', rule as never, {
code: `
<script>
</script>
text at the root of the template
`,
errors: [
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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'. */
Expand Down
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit e0acb96

Please sign in to comment.