Skip to content

Commit 0c550fb

Browse files
authored
feat: add support for flat config (#338)
* feat: add support for flat config * Create clean-wasps-bake.md * fix config
1 parent 8988d3d commit 0c550fb

40 files changed

+387
-74
lines changed

.changeset/clean-wasps-bake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-vue-scoped-css": minor
3+
---
4+
5+
feat: add support for flat config

README.md

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ npm install --save-dev eslint eslint-plugin-vue-scoped-css vue-eslint-parser
4040
```
4141

4242
> **Requirements**
43-
>
43+
>
4444
> - ESLint v6.0.0 and above
4545
> - Node.js v12.22.x, v14.17.x, v16.x and above
4646
@@ -49,8 +49,32 @@ npm install --save-dev eslint eslint-plugin-vue-scoped-css vue-eslint-parser
4949
## Usage
5050

5151
<!--USAGE_SECTION_START-->
52+
<!--USAGE_GUIDE_START-->
5253

53-
Create `.eslintrc.*` file to configure rules. See also: [http://eslint.org/docs/user-guide/configuring](http://eslint.org/docs/user-guide/configuring).
54+
### New (ESLint>=v9) Config (Flat Config)
55+
56+
Use `eslint.config.js` file to configure rules. See also: <https://eslint.org/docs/latest/use/configure/configuration-files-new>.
57+
58+
Example **eslint.config.js**:
59+
60+
```mjs
61+
import eslintPluginVueScopedCSS from 'eslint-plugin-vue-scoped-css';
62+
export default [
63+
// add more generic rule sets here, such as:
64+
// js.configs.recommended,
65+
...eslintPluginVueScopedCSS.configs['flat/recommended'],
66+
{
67+
rules: {
68+
// override/add rules settings here, such as:
69+
// 'vue-scoped-css/no-unused-selector': 'error'
70+
}
71+
}
72+
];
73+
```
74+
75+
### Legacy Config (ESLint<v9)
76+
77+
Use `.eslintrc.*` file to configure rules. See also: <https://eslint.org/docs/latest/use/configure/>.
5478

5579
Example **.eslintrc.js**:
5680

@@ -72,11 +96,21 @@ module.exports = {
7296

7397
This plugin provides some predefined configs:
7498

99+
### New (ESLint>=v9) Config (Flat Config)
100+
101+
- `*.configs['flat/base']` - Settings and rules to enable this plugin
102+
- `*.configs['flat/recommended']` - `/base`, plus rules for better ways to help you avoid problems for Vue.js 3.x
103+
- `*.configs['flat/vue2-recommended']` - `/base`, plus rules for better ways to help you avoid problems for Vue.js 2.x
104+
- `*.configs['flat/all']` - All rules of this plugin are included
105+
106+
### Legacy Config (ESLint<v9)
107+
75108
- `plugin:vue-scoped-css/base` - Settings and rules to enable this plugin
76109
- `plugin:vue-scoped-css/recommended` - `/base`, plus rules for better ways to help you avoid problems for Vue.js 2.x
77110
- `plugin:vue-scoped-css/vue3-recommended` - `/base`, plus rules for better ways to help you avoid problems for Vue.js 3.x
78111
- `plugin:vue-scoped-css/all` - All rules of this plugin are included
79112

113+
<!--USAGE_GUIDE_END-->
80114
<!--USAGE_SECTION_END-->
81115

82116
## Rules
@@ -91,9 +125,17 @@ The `--fix` option on the [command line](https://eslint.org/docs/user-guide/comm
91125

92126
Enforce all the rules in this category with:
93127

128+
```js
129+
export default [
130+
...eslintPluginVueScopedCSS.configs['flat/recommended'],
131+
]
132+
```
133+
134+
or
135+
94136
```json
95137
{
96-
"extends": "plugin:vue-scoped-css/vue3-recommended"
138+
"extends": ["plugin:vue-scoped-css/vue3-recommended"]
97139
}
98140
```
99141

@@ -113,9 +155,17 @@ Enforce all the rules in this category with:
113155

114156
Enforce all the rules in this category with:
115157

158+
```js
159+
export default [
160+
...eslintPluginVueScopedCSS.configs['flat/vue2-recommended'],
161+
]
162+
```
163+
164+
or
165+
116166
```json
117167
{
118-
"extends": "plugin:vue-scoped-css/recommended"
168+
"extends": ["plugin:vue-scoped-css/recommended"]
119169
}
120170
```
121171

docs/.vuepress/categories.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ const isCategoryTest = {
1414
recommended: ({ deprecated, docs: { categories } }) =>
1515
!deprecated &&
1616
categories.length &&
17-
categories.some((cat) => cat === "recommended") &&
17+
categories.some((cat) => cat === "vue2-recommended") &&
1818
categories.some((cat) => cat === "vue3-recommended"),
1919
"vue2-recommended": ({ deprecated, docs: { categories } }) =>
2020
!deprecated &&
2121
categories.length &&
22-
categories.some((cat) => cat === "recommended") &&
22+
categories.some((cat) => cat === "vue2-recommended") &&
2323
categories.every((cat) => cat !== "vue3-recommended"),
2424
"vue3-recommended": ({ deprecated, docs: { categories } }) =>
2525
!deprecated &&
2626
categories.length &&
2727
categories.some((cat) => cat === "vue3-recommended") &&
28-
categories.every((cat) => cat !== "recommended"),
28+
categories.every((cat) => cat !== "vue2-recommended"),
2929
uncategorized: ({ deprecated, docs: { categories } }) =>
3030
!deprecated && !categories.length,
3131
deprecated: ({ deprecated }) => deprecated,

docs/.vuepress/components/rules/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function getCategory({ deprecated, docs: { categories } }) {
4242
if (deprecated) {
4343
return "deprecated";
4444
}
45-
const v2 = categories.some((cat) => cat === "recommended");
45+
const v2 = categories.some((cat) => cat === "vue2-recommended");
4646
const v3 = categories.some((cat) => cat === "vue3-recommended");
4747
if (v2) {
4848
return v3 ? "recommended" : "vue2-recommended";

docs/rules/README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,17 @@ sidebarDepth: 0
1010

1111
Enforce all the rules in this category with:
1212

13+
```js
14+
export default [
15+
...eslintPluginVueScopedCSS.configs['flat/recommended'],
16+
]
17+
```
18+
19+
or
20+
1321
```json
1422
{
15-
"extends": "plugin:vue-scoped-css/vue3-recommended"
23+
"extends": ["plugin:vue-scoped-css/vue3-recommended"]
1624
}
1725
```
1826

@@ -32,9 +40,17 @@ Enforce all the rules in this category with:
3240

3341
Enforce all the rules in this category with:
3442

43+
```js
44+
export default [
45+
...eslintPluginVueScopedCSS.configs['flat/vue2-recommended'],
46+
]
47+
```
48+
49+
or
50+
3551
```json
3652
{
37-
"extends": "plugin:vue-scoped-css/recommended"
53+
"extends": ["plugin:vue-scoped-css/recommended"]
3854
}
3955
```
4056

docs/rules/enforce-style-type.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ description: "enforce the `<style>` tags to be plain or have the `scoped` or `mo
88

99
> enforce the `<style>` tags to be plain or have the `scoped` or `module` attribute
1010
11-
- :gear: This rule is included in all of `"plugin:vue-scoped-css/recommended"`, `"plugin:vue-scoped-css/vue3-recommended"` and `"plugin:vue-scoped-css/all"`.
11+
- :gear: This rule is included in all of `"plugin:vue-scoped-css/all"`, `"plugin:vue-scoped-css/recommended"` and `"plugin:vue-scoped-css/vue3-recommended"`.
1212

1313
## :book: Rule Details
1414

docs/rules/no-deprecated-deep-combinator.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ description: "disallow using deprecated deep combinators"
88

99
> disallow using deprecated deep combinators
1010
11-
- :gear: This rule is included in `"plugin:vue-scoped-css/vue3-recommended"` and `"plugin:vue-scoped-css/all"`.
11+
- :gear: This rule is included in `"plugin:vue-scoped-css/all"` and `"plugin:vue-scoped-css/vue3-recommended"`.
1212
- :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule.
1313

1414
## :book: Rule Details

docs/rules/no-parent-of-v-global.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ description: "disallow parent selector for `::v-global` pseudo-element"
88

99
> disallow parent selector for `::v-global` pseudo-element
1010
11-
- :gear: This rule is included in `"plugin:vue-scoped-css/vue3-recommended"` and `"plugin:vue-scoped-css/all"`.
11+
- :gear: This rule is included in `"plugin:vue-scoped-css/all"` and `"plugin:vue-scoped-css/vue3-recommended"`.
1212

1313
## :book: Rule Details
1414

docs/rules/no-parsing-error.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ description: "disallow parsing errors in `<style>`"
88

99
> disallow parsing errors in `<style>`
1010
11-
- :gear: This rule is included in all of `"plugin:vue-scoped-css/recommended"`, `"plugin:vue-scoped-css/vue3-recommended"` and `"plugin:vue-scoped-css/all"`.
11+
- :gear: This rule is included in all of `"plugin:vue-scoped-css/all"`, `"plugin:vue-scoped-css/recommended"` and `"plugin:vue-scoped-css/vue3-recommended"`.
1212

1313
## :book: Rule Details
1414

docs/rules/no-unused-keyframes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ description: "disallow `@keyframes` which don't use in Scoped CSS"
88

99
> disallow `@keyframes` which don't use in Scoped CSS
1010
11-
- :gear: This rule is included in all of `"plugin:vue-scoped-css/recommended"`, `"plugin:vue-scoped-css/vue3-recommended"` and `"plugin:vue-scoped-css/all"`.
11+
- :gear: This rule is included in all of `"plugin:vue-scoped-css/all"`, `"plugin:vue-scoped-css/recommended"` and `"plugin:vue-scoped-css/vue3-recommended"`.
1212

1313
## :book: Rule Details
1414

0 commit comments

Comments
 (0)