Skip to content

Commit 9659780

Browse files
committed
feat: add support for flat config
1 parent 8988d3d commit 9659780

37 files changed

+367
-68
lines changed

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

docs/rules/no-unused-selector.md

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

99
> disallow selectors defined in Scoped CSS that don't use in `<template>`
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/require-v-deep-argument.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ description: "require selector argument to be passed to `::v-deep()`"
88

99
> require selector argument to be passed to `::v-deep()`
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/require-v-global-argument.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ description: "require selector argument to be passed to `::v-global()`"
88

99
> require selector argument to be passed to `::v-global()`
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/require-v-slotted-argument.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ description: "require selector argument to be passed to `::v-slotted()`"
88

99
> require selector argument to be passed to `::v-slotted()`
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/user-guide/README.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,32 @@ npm install --save-dev eslint eslint-plugin-vue-scoped-css vue-eslint-parser
1313

1414
## Usage
1515

16-
### Configuration
16+
<!--USAGE_GUIDE_START-->
1717

18-
Use `.eslintrc.*` file to configure rules. See also: [https://eslint.org/docs/user-guide/configuring](https://eslint.org/docs/user-guide/configuring).
18+
### New (ESLint>=v9) Config (Flat Config)
19+
20+
Use `eslint.config.js` file to configure rules. See also: <https://eslint.org/docs/latest/use/configure/configuration-files-new>.
21+
22+
Example **eslint.config.js**:
23+
24+
```mjs
25+
import eslintPluginVueScopedCSS from 'eslint-plugin-vue-scoped-css';
26+
export default [
27+
// add more generic rule sets here, such as:
28+
// js.configs.recommended,
29+
...eslintPluginVueScopedCSS.configs['flat/recommended'],
30+
{
31+
rules: {
32+
// override/add rules settings here, such as:
33+
// 'vue-scoped-css/no-unused-selector': 'error'
34+
}
35+
}
36+
];
37+
```
38+
39+
### Legacy Config (ESLint<v9)
40+
41+
Use `.eslintrc.*` file to configure rules. See also: <https://eslint.org/docs/latest/use/configure/>.
1942

2043
Example **.eslintrc.js**:
2144

@@ -33,13 +56,26 @@ module.exports = {
3356
}
3457
```
3558

59+
## Configs
60+
3661
This plugin provides some predefined configs:
3762

63+
### New (ESLint>=v9) Config (Flat Config)
64+
65+
- `*.configs['flat/base']` - Settings and rules to enable this plugin
66+
- `*.configs['flat/recommended']` - `/base`, plus rules for better ways to help you avoid problems for Vue.js 3.x
67+
- `*.configs['flat/vue2-recommended']` - `/base`, plus rules for better ways to help you avoid problems for Vue.js 2.x
68+
- `*.configs['flat/all']` - All rules of this plugin are included
69+
70+
### Legacy Config (ESLint<v9)
71+
3872
- `plugin:vue-scoped-css/base` - Settings and rules to enable this plugin
3973
- `plugin:vue-scoped-css/recommended` - `/base`, plus rules for better ways to help you avoid problems for Vue.js 2.x
4074
- `plugin:vue-scoped-css/vue3-recommended` - `/base`, plus rules for better ways to help you avoid problems for Vue.js 3.x
4175
- `plugin:vue-scoped-css/all` - All rules of this plugin are included
4276

77+
<!--USAGE_GUIDE_END-->
78+
4379
See [the rule list](../rules/README.md) to get the `rules` that this plugin provides.
4480

4581
### Running ESLint from command line

lib/configs/flat/all.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { collectRules } from "../../utils/rules";
2+
import base from "./base";
3+
4+
export default [
5+
...base,
6+
{
7+
rules: collectRules(),
8+
},
9+
];

lib/configs/flat/base.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { ESLint } from "eslint";
2+
import * as vueParser from "vue-eslint-parser";
3+
export default [
4+
{
5+
plugins: {
6+
// eslint-disable-next-line @typescript-eslint/naming-convention -- plugin name
7+
get "vue-scoped-css"(): ESLint.Plugin {
8+
return require("../../index");
9+
},
10+
},
11+
},
12+
{
13+
files: ["*.vue", "**/*.vue"],
14+
languageOptions: {
15+
parser: vueParser,
16+
},
17+
},
18+
];

lib/configs/flat/recommended.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { collectRules } from "../../utils/rules";
2+
import base from "./base";
3+
4+
export default [
5+
...base,
6+
{
7+
rules: collectRules("vue3-recommended"),
8+
},
9+
];

lib/configs/flat/vue2-recommended.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { collectRules } from "../../utils/rules";
2+
import base from "./base";
3+
4+
export default [
5+
...base,
6+
{
7+
rules: collectRules("vue2-recommended"),
8+
},
9+
];

lib/configs/recommended.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import { collectRules } from "../utils/rules";
22

33
export = {
44
extends: require.resolve("./base"),
5-
rules: collectRules("recommended"),
5+
rules: collectRules("vue2-recommended"),
66
};

lib/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
import { rules as ruleList } from "./utils/rules";
22
import type { Rule } from "./types";
3+
import flatBase from "./configs/flat/base";
4+
import flatRecommended from "./configs/flat/recommended";
5+
import flatVue2Recommended from "./configs/flat/vue2-recommended";
6+
import flatAll from "./configs/flat/all";
37

48
const configs = {
59
base: require("./configs/base"),
610
recommended: require("./configs/recommended"),
711
"vue3-recommended": require("./configs/vue3-recommended"),
812
all: require("./configs/all"),
13+
"flat/base": flatBase,
14+
"flat/recommended": flatRecommended,
15+
"flat/vue2-recommended": flatVue2Recommended,
16+
"flat/all": flatAll,
917
};
1018

1119
const rules = ruleList.reduce(

lib/rules/enforce-style-type.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export = {
2222
docs: {
2323
description:
2424
"enforce the `<style>` tags to be plain or have the `scoped` or `module` attribute",
25-
categories: ["recommended", "vue3-recommended"],
25+
categories: ["vue2-recommended", "vue3-recommended"],
2626
default: "warn",
2727
url: "https://future-architect.github.io/eslint-plugin-vue-scoped-css/rules/enforce-style-type.html",
2828
suggestion: true,

0 commit comments

Comments
 (0)