Skip to content

Commit 4d503f7

Browse files
authored
refactor: settings.kit to settings.svelte.kit (#290)
1 parent 8da870f commit 4d503f7

File tree

10 files changed

+79
-42
lines changed

10 files changed

+79
-42
lines changed

README.md

+24-11
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,6 @@ See also <https://github.com/ota-meshi/svelte-eslint-parser#readme>.
188188

189189
You can change the behavior of this plugin with some settings.
190190

191-
- `ignoreWarnings` (optional) ... Specifies an array of rules that ignore reports in the template.
192-
For example, set rules on the template that cannot avoid false positives.
193-
- `compileOptions` (optional) ... Specifies options for Svelte compile. Effects rules that use Svelte compile. The target rules are [svelte/valid-compile](https://ota-meshi.github.io/eslint-plugin-svelte/rules/valid-compile/) and [svelte/no-unused-svelte-ignore](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-unused-svelte-ignore/). **Note that it has no effect on ESLint's custom parser**.
194-
- `postcss` (optional) ... Specifies options related to PostCSS. You can disable the PostCSS process by specifying `false`.
195-
- `configFilePath` (optional) ... Specifies the path of the directory containing the PostCSS configuration.
196-
197191
e.g.
198192

199193
```js
@@ -210,13 +204,30 @@ module.exports = {
210204
configFilePath: "./path/to/my/postcss.config.js",
211205
},
212206
},
207+
kit: {
208+
files: {
209+
routes: "src/routes",
210+
},
211+
},
213212
},
214213
},
215214
// ...
216215
}
217216
```
218217

219-
#### settings.kit
218+
#### settings.svelte.ignoreWarnings
219+
220+
Specifies an array of rules that ignore reports in the template.
221+
For example, set rules on the template that cannot avoid false positives.
222+
223+
#### settings.svelte.compileOptions
224+
225+
Specifies options for Svelte compile. Effects rules that use Svelte compile. The target rules are [svelte/valid-compile](https://ota-meshi.github.io/eslint-plugin-svelte/rules/valid-compile/) and [svelte/no-unused-svelte-ignore](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-unused-svelte-ignore/). **Note that it has no effect on ESLint's custom parser**.
226+
227+
- `postcss` ... Specifies options related to PostCSS. You can disable the PostCSS process by specifying `false`.
228+
- `configFilePath` ... Specifies the path of the directory containing the PostCSS configuration.
229+
230+
#### settings.svelte.kit
220231

221232
If you use SvelteKit with not default configuration, you need to set below configurations.
222233
The schema is subset of SvelteKit's configuration.
@@ -228,9 +239,11 @@ e.g.
228239
module.exports = {
229240
// ...
230241
settings: {
231-
kit: {
232-
files: {
233-
routes: "src/routes",
242+
svelte: {
243+
kit: {
244+
files: {
245+
routes: "src/routes",
246+
},
234247
},
235248
},
236249
},
@@ -294,7 +307,7 @@ These rules relate to possible syntax or logic errors in Svelte code:
294307
| [svelte/no-shorthand-style-property-overrides](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-shorthand-style-property-overrides/) | disallow shorthand style properties that override related longhand properties | :star: |
295308
| [svelte/no-store-async](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-store-async/) | disallow using async/await inside svelte stores because it causes issues with the auto-unsubscribing features | |
296309
| [svelte/no-unknown-style-directive-property](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-unknown-style-directive-property/) | disallow unknown `style:property` | :star: |
297-
| [svelte/require-store-callbacks-use-set-param](https://ota-meshi.github.io/eslint-plugin-svelte/rules/require-store-callbacks-use-set-param/) | (no description) | |
310+
| [svelte/require-store-callbacks-use-set-param](https://ota-meshi.github.io/eslint-plugin-svelte/rules/require-store-callbacks-use-set-param/) | store callbacks must use `set` param | |
298311
| [svelte/valid-compile](https://ota-meshi.github.io/eslint-plugin-svelte/rules/valid-compile/) | disallow warnings when compiling. | :star: |
299312

300313
## Security Vulnerability

docs/rules.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ These rules relate to possible syntax or logic errors in Svelte code:
2525
| [svelte/no-shorthand-style-property-overrides](./rules/no-shorthand-style-property-overrides.md) | disallow shorthand style properties that override related longhand properties | :star: |
2626
| [svelte/no-store-async](./rules/no-store-async.md) | disallow using async/await inside svelte stores because it causes issues with the auto-unsubscribing features | |
2727
| [svelte/no-unknown-style-directive-property](./rules/no-unknown-style-directive-property.md) | disallow unknown `style:property` | :star: |
28-
| [svelte/require-store-callbacks-use-set-param](./rules/require-store-callbacks-use-set-param.md) | (no description) | |
28+
| [svelte/require-store-callbacks-use-set-param](./rules/require-store-callbacks-use-set-param.md) | store callbacks must use `set` param | |
2929
| [svelte/valid-compile](./rules/valid-compile.md) | disallow warnings when compiling. | :star: |
3030

3131
## Security Vulnerability

docs/rules/no-export-load-in-svelte-module-in-kit-pages.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ And the API has changed.
2020
<script>
2121
const config = {
2222
settings: {
23-
kit: {
24-
files: {
25-
routes: "",
23+
svelte: {
24+
kit: {
25+
files: {
26+
routes: "",
27+
},
2628
},
2729
},
2830
},
@@ -49,7 +51,7 @@ And the API has changed.
4951

5052
## :wrench: Options
5153

52-
Nothing. But if use are using not default routes folder, please set configuration according to the [user guide](../user-guide.md#settings-kit).
54+
Nothing. But if use are using not default routes folder, please set configuration according to the [user guide](../user-guide.md#settings-svelte-kit).
5355

5456
## :books: Further Reading
5557

docs/rules/require-store-callbacks-use-set-param.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ description: "store callbacks must use `set` param"
77

88
# svelte/require-store-callbacks-use-set-param
99

10-
> Store callbacks must use `set` param.
10+
> store callbacks must use `set` param
11+
12+
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> **_This rule has not been released yet._** </badge>
1113

1214
## :book: Rule Details
1315

docs/user-guide.md

+23-10
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,6 @@ See also <https://github.com/ota-meshi/svelte-eslint-parser#readme>.
140140

141141
You can change the behavior of this plugin with some settings.
142142

143-
- `ignoreWarnings` (optional) ... Specifies an array of rules that ignore reports in the template.
144-
For example, set rules on the template that cannot avoid false positives.
145-
- `compileOptions` (optional) ... Specifies options for Svelte compile. Effects rules that use Svelte compile. The target rules are [svelte/valid-compile](./rules/valid-compile.md) and [svelte/no-unused-svelte-ignore](./rules/no-unused-svelte-ignore.md). **Note that it has no effect on ESLint's custom parser**.
146-
- `postcss` (optional) ... Specifies options related to PostCSS. You can disable the PostCSS process by specifying `false`.
147-
- `configFilePath` (optional) ... Specifies the path of the directory containing the PostCSS configuration.
148-
149143
e.g.
150144

151145
```js
@@ -162,13 +156,30 @@ module.exports = {
162156
configFilePath: "./path/to/my/postcss.config.js",
163157
},
164158
},
159+
kit: {
160+
files: {
161+
routes: "src/routes",
162+
},
163+
},
165164
},
166165
},
167166
// ...
168167
}
169168
```
170169

171-
#### settings.kit
170+
#### settings.svelte.ignoreWarnings
171+
172+
Specifies an array of rules that ignore reports in the template.
173+
For example, set rules on the template that cannot avoid false positives.
174+
175+
#### settings.svelte.compileOptions
176+
177+
Specifies options for Svelte compile. Effects rules that use Svelte compile. The target rules are [svelte/valid-compile](./rules/valid-compile.md) and [svelte/no-unused-svelte-ignore](./rules/no-unused-svelte-ignore.md). **Note that it has no effect on ESLint's custom parser**.
178+
179+
- `postcss` ... Specifies options related to PostCSS. You can disable the PostCSS process by specifying `false`.
180+
- `configFilePath` ... Specifies the path of the directory containing the PostCSS configuration.
181+
182+
#### settings.svelte.kit
172183

173184
If you use SvelteKit with not default configuration, you need to set below configurations.
174185
The schema is subset of SvelteKit's configuration.
@@ -180,9 +191,11 @@ e.g.
180191
module.exports = {
181192
// ...
182193
settings: {
183-
kit: {
184-
files: {
185-
routes: "src/routes",
194+
svelte: {
195+
kit: {
196+
files: {
197+
routes: "src/routes",
198+
},
186199
},
187200
},
188201
},

src/types.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,16 @@ export type RuleContext = {
121121
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ignore
122122
options: any[]
123123
settings?: {
124-
["svelte"]?: {
124+
svelte?: {
125125
ignoreWarnings?: unknown
126126
compileOptions?: {
127127
babel?: boolean
128128
postcss?: false | { configFilePath?: unknown }
129129
}
130-
}
131-
["kit"]?: {
132-
files?: {
133-
routes?: string
130+
kit?: {
131+
files?: {
132+
routes?: string
133+
}
134134
}
135135
}
136136
}

src/utils/svelte-kit.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export function isKitPageComponent(context: RuleContext): boolean {
1919
if (isRunOnBrowser) return true
2020
if (!hasSvelteKit(context.getFilename())) return false
2121
const routes =
22-
context.settings?.kit?.files?.routes?.replace(/^\//, "") ?? "src/routes"
22+
context.settings?.svelte?.kit?.files?.routes?.replace(/^\//, "") ??
23+
"src/routes"
2324
const filePath = context.getFilename()
2425
const projectRootDir = getProjectRootDir(context.getFilename()) ?? ""
2526
return filePath.startsWith(path.join(projectRootDir, routes))

tests/fixtures/rules/no-export-load-in-svelte-module-in-kit-pages/invalid/_config.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
22
"settings": {
3-
"kit": {
4-
"files": {
5-
"routes": "tests/fixtures"
3+
"svelte": {
4+
"kit": {
5+
"files": {
6+
"routes": "tests/fixtures"
7+
}
68
}
79
}
810
}

tests/fixtures/rules/no-export-load-in-svelte-module-in-kit-pages/valid/_config.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
22
"settings": {
3-
"kit": {
4-
"files": {
5-
"routes": "tests/fixtures"
3+
"svelte": {
4+
"kit": {
5+
"files": {
6+
"routes": "tests/fixtures"
7+
}
68
}
79
}
810
}

tests/fixtures/rules/no-export-load-in-svelte-module-in-kit-pages/valid/not-page/_config.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
22
"settings": {
3-
"kit": {
4-
"files": {
5-
"routes": "some-path"
3+
"svelte": {
4+
"kit": {
5+
"files": {
6+
"routes": "some-path"
7+
}
68
}
79
}
810
}

0 commit comments

Comments
 (0)