Skip to content

Commit 9725a74

Browse files
codiiniota-meshi
andauthored
feat: support eslint v9 flat config in plugin (#20)
* feat: create new flat and update old config scripts * chore: generate config file * chore: module exports * docs: update started docs * docs: update rule docs * chore: add module sourcetype for md files * feat: update docs script * Create rich-peaches-punch.md --------- Co-authored-by: Yosuke Ota <[email protected]>
1 parent 2446aca commit 9725a74

15 files changed

+196
-40
lines changed

.changeset/rich-peaches-punch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@intlify/eslint-plugin-svelte": minor
3+
---
4+
5+
feat: support eslint v9 flat config in plugin

.eslintrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ module.exports = {
127127
files: ['**/*.md/*.*'],
128128
rules: {
129129
'prettier/prettier': 'off'
130+
},
131+
parserOptions: {
132+
ecmaVersion: 2021,
133+
sourceType: 'module'
130134
}
131135
}
132136
]

docs/rules/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Available Rules
22

3-
- :star: mark: the rule which is enabled by `plugin:@intlify/svelte/recommended` preset.
3+
- :star: mark: the rule which is enabled by the `plugin:@intlify/svelte/recommended` or `*.configs.["flat/recommended"]` preset.
44
- :black_nib: mark: the rule which is fixable by `eslint --fix` command.
55

66
## Recommended

docs/rules/no-raw-text.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ since: v0.0.1
88

99
> disallow to string literal in template
1010
11-
- :star: The `"extends": "plugin:@intlify/svelte/recommended"` property in a configuration file enables this rule.
11+
- :star: The `"extends": "plugin:@intlify/svelte/recommended"` or `*.configs["flat/recommended"]` property in a configuration file enables this rule.
1212

1313
This rule warns the usage of string literal.
1414

docs/started.md

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,47 @@ npm install --save-dev eslint @intlify/eslint-plugin-svelte
1717

1818
## :rocket: Usage
1919

20-
### Configuration
20+
### Configuration `eslint.config.[c|m]js`
2121

22-
Configure your `.eslintrc.*` file.
22+
In ESLint v9, the the default way to configure files is using an `eslint.config.[c|m]js` file, but this can be used starting from ESLint v8.57.0.
2323

24-
For example:
24+
See also: https://eslint.org/docs/latest/use/configure/configuration-files-new.
25+
26+
Example `eslint.config.js`:
27+
28+
```js
29+
import intlifySvelte from '@intlify/eslint-plugin-svelte'
30+
31+
export default [
32+
// add more generic rulesets here, such as:
33+
//...eslintPluginSvelte.configs["flat/recommended"],
34+
35+
// Recommended
36+
...intlifySvelte.configs['flat/recommended'],
37+
{
38+
rules: {
39+
// override/add rules settings here, such as:
40+
'@intlify/svelte/no-raw-text': 'error'
41+
}
42+
}
43+
]
44+
```
45+
46+
See [the rule list](./rules/README.md)
47+
48+
#### Bundle Configurations `eslint.config.[c|m]js`
49+
50+
This plugin provides some predefined configs. You can use the following configs by adding them to `eslint.config.[c|m]js`. (All flat configs in this plugin are provided as arrays, so spread syntax is required when combining them with other configs.)
51+
52+
- `*configs["flat/base"]`: Settings and rules to enable correct ESlint parsing.
53+
- `*configs["flat/recommended"]`: Above, plus rules to enforce subjective community defaults to ensure consistency.
54+
55+
### Configuration `.eslintrc.*`
56+
57+
Use the `.eslintrc.*` file to configure rules in ESLint < v9. See also:
58+
https://eslint.org/docs/latest/use/configure/.
59+
60+
Example `.eslintrc.js`:
2561

2662
```js
2763
module.export = {
@@ -44,6 +80,13 @@ module.export = {
4480

4581
See [the rule list](./rules/README.md)
4682

83+
#### Bundle Configurations `eslintrc.*`
84+
85+
This plugin provides some predefined configs. You can use the following configs by adding them to `eslintrc.*`.
86+
87+
- `plugin:@intlify/svelte/base`: Settings and rules to enable correct ESlint parsing.
88+
- `plugin:@intlify/svelte/recommended`: Above, plus rules to enforce subjective community defaults to ensure consistency.
89+
4790
::: warning ❗ Attention
4891

4992
The `@intlify/eslint-plugin-svelte` can not be used with the [eslint-plugin-svelte3].

lib/configs.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

lib/configs/flat/base.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/** DON'T EDIT THIS FILE; was created by scripts. */
2+
export = [
3+
{
4+
name: '@intlify/vue-i18n:base:setup',
5+
plugins: {
6+
get '@intlify/svelte'() {
7+
return require('../../index')
8+
}
9+
}
10+
},
11+
{
12+
name: '@intlify/svelte:base:svelte',
13+
files: ['*.svelte'],
14+
languageOptions: {
15+
parser: require('svelte-eslint-parser')
16+
}
17+
}
18+
]

lib/configs/flat/recommended.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/** DON'T EDIT THIS FILE; was created by scripts. */
2+
import config from './base'
3+
export = [
4+
...config,
5+
{
6+
name: '@intlify/svelte:recommended:setup',
7+
languageOptions: {
8+
ecmaVersion: 2018,
9+
sourceType: 'module',
10+
parserOptions: {
11+
ecmaFeatures: {
12+
jsx: true
13+
}
14+
}
15+
}
16+
},
17+
{
18+
name: '@intlify/svelte:recommended:rules',
19+
rules: {
20+
'@intlify/svelte/no-raw-text': 'warn'
21+
}
22+
}
23+
]

lib/index.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,23 @@
22
* @fileoverview ESLint plugin for internationalization with Svelte
33
* @author Yosuke Ota
44
*/
5-
import configs from './configs'
5+
import legacyBase from './configs/base'
6+
import legacyRecommended from './configs/recommended'
7+
import flatBase from './configs/flat/base'
8+
import flatRecommended from './configs/flat/recommended'
69
import rules from './rules'
710
import * as meta from './meta'
811

912
export = {
1013
meta,
11-
configs,
14+
// eslintrc configs
15+
configs: {
16+
base: legacyBase,
17+
recommended: legacyRecommended,
18+
19+
// flat configs
20+
'flat/base': flatBase,
21+
'flat/recommended': flatRecommended
22+
},
1223
rules
1324
}

scripts/update-docs-index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ writeFileSync(
3737
resolve(__dirname, '../docs/rules/README.md'),
3838
`# Available Rules
3939
40-
- :star: mark: the rule which is enabled by \`plugin:@intlify/svelte/recommended\` preset.
40+
- :star: mark: the rule which is enabled by the \`plugin:@intlify/svelte/recommended\` or \`*.configs.["flat/recommended"]\` preset.
4141
- :black_nib: mark: the rule which is fixable by \`eslint --fix\` command.
4242
4343
${withCategories

0 commit comments

Comments
 (0)