Skip to content

Commit a2795d8

Browse files
committed
feat: generate new error-based configs
1 parent 2929ceb commit a2795d8

File tree

6 files changed

+188
-12
lines changed

6 files changed

+188
-12
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* IMPORTANT!
3+
* This file has been automatically generated,
4+
* in order to update its content execute "npm run update"
5+
*/
6+
'use strict'
7+
const config = require('./vue2-strongly-recommended-error.js')
8+
9+
module.exports = [
10+
...config,
11+
{
12+
name: 'vue/vue2-recommended/rules',
13+
rules: {
14+
'vue/attributes-order': 'error',
15+
'vue/block-order': 'error',
16+
'vue/no-lone-template': 'error',
17+
'vue/no-multiple-slot-args': 'error',
18+
'vue/no-required-prop-with-default': 'error',
19+
'vue/no-v-html': 'error',
20+
'vue/order-in-components': 'error',
21+
'vue/this-in-template': 'error'
22+
}
23+
}
24+
]
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* IMPORTANT!
3+
* This file has been automatically generated,
4+
* in order to update its content execute "npm run update"
5+
*/
6+
'use strict'
7+
const config = require('./vue2-essential.js')
8+
9+
module.exports = [
10+
...config,
11+
{
12+
name: 'vue/vue2-strongly-recommended/rules',
13+
rules: {
14+
'vue/attribute-hyphenation': 'error',
15+
'vue/component-definition-name-casing': 'error',
16+
'vue/first-attribute-linebreak': 'error',
17+
'vue/html-closing-bracket-newline': 'error',
18+
'vue/html-closing-bracket-spacing': 'error',
19+
'vue/html-end-tags': 'error',
20+
'vue/html-indent': 'error',
21+
'vue/html-quotes': 'error',
22+
'vue/html-self-closing': 'error',
23+
'vue/max-attributes-per-line': 'error',
24+
'vue/multiline-html-element-content-newline': 'error',
25+
'vue/mustache-interpolation-spacing': 'error',
26+
'vue/no-multi-spaces': 'error',
27+
'vue/no-spaces-around-equal-signs-in-attribute': 'error',
28+
'vue/no-template-shadow': 'error',
29+
'vue/one-component-per-file': 'error',
30+
'vue/prop-name-casing': 'error',
31+
'vue/require-default-prop': 'error',
32+
'vue/require-prop-types': 'error',
33+
'vue/singleline-html-element-content-newline': 'error',
34+
'vue/v-bind-style': 'error',
35+
'vue/v-on-style': 'error',
36+
'vue/v-slot-style': 'error'
37+
}
38+
}
39+
]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* IMPORTANT!
3+
* This file has been automatically generated,
4+
* in order to update its content execute "npm run update"
5+
*/
6+
'use strict'
7+
const config = require('./vue3-strongly-recommended-error.js')
8+
9+
module.exports = [
10+
...config,
11+
{
12+
name: 'vue/recommended/rules',
13+
rules: {
14+
'vue/attributes-order': 'error',
15+
'vue/block-order': 'error',
16+
'vue/no-lone-template': 'error',
17+
'vue/no-multiple-slot-args': 'error',
18+
'vue/no-required-prop-with-default': 'error',
19+
'vue/no-v-html': 'error',
20+
'vue/order-in-components': 'error',
21+
'vue/this-in-template': 'error'
22+
}
23+
}
24+
]
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* IMPORTANT!
3+
* This file has been automatically generated,
4+
* in order to update its content execute "npm run update"
5+
*/
6+
'use strict'
7+
const config = require('./vue3-essential.js')
8+
9+
module.exports = [
10+
...config,
11+
{
12+
name: 'vue/strongly-recommended/rules',
13+
rules: {
14+
'vue/attribute-hyphenation': 'error',
15+
'vue/component-definition-name-casing': 'error',
16+
'vue/first-attribute-linebreak': 'error',
17+
'vue/html-closing-bracket-newline': 'error',
18+
'vue/html-closing-bracket-spacing': 'error',
19+
'vue/html-end-tags': 'error',
20+
'vue/html-indent': 'error',
21+
'vue/html-quotes': 'error',
22+
'vue/html-self-closing': 'error',
23+
'vue/max-attributes-per-line': 'error',
24+
'vue/multiline-html-element-content-newline': 'error',
25+
'vue/mustache-interpolation-spacing': 'error',
26+
'vue/no-multi-spaces': 'error',
27+
'vue/no-spaces-around-equal-signs-in-attribute': 'error',
28+
'vue/no-template-shadow': 'error',
29+
'vue/one-component-per-file': 'error',
30+
'vue/prop-name-casing': 'error',
31+
'vue/require-default-prop': 'error',
32+
'vue/require-explicit-emits': 'error',
33+
'vue/require-prop-types': 'error',
34+
'vue/singleline-html-element-content-newline': 'error',
35+
'vue/v-bind-style': 'error',
36+
'vue/v-on-event-hyphenation': [
37+
'error',
38+
'always',
39+
{
40+
autofix: true
41+
}
42+
],
43+
'vue/v-on-style': 'error',
44+
'vue/v-slot-style': 'error'
45+
}
46+
}
47+
]

tools/update-lib-configs.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ const extendsCategories = {
2828
'vue3-use-with-caution': 'vue3-recommended'
2929
}
3030

31-
function formatRules(rules, categoryId) {
31+
function formatRules(rules, categoryId, alwaysError) {
3232
const obj = Object.fromEntries(
3333
rules.map((rule) => {
34-
let options = errorCategories.has(categoryId) ? 'error' : 'warn'
34+
let options =
35+
alwaysError || errorCategories.has(categoryId) ? 'error' : 'warn'
3536
const defaultOptions =
3637
rule.meta && rule.meta.docs && rule.meta.docs.defaultOptions
3738
if (defaultOptions) {
@@ -47,8 +48,16 @@ function formatRules(rules, categoryId) {
4748
return JSON.stringify(obj, null, 2)
4849
}
4950

50-
function formatCategory(category) {
51-
const extendsCategoryId = extendsCategories[category.categoryId]
51+
function hasWarningRules(categoryId) {
52+
return (
53+
categoryId !== 'base' &&
54+
categoryId !== 'vue3-essential' &&
55+
categoryId !== 'vue2-essential'
56+
)
57+
}
58+
59+
function formatCategory(category, alwaysError = false) {
60+
let extendsCategoryId = extendsCategories[category.categoryId]
5261
if (extendsCategoryId == null) {
5362
return `/*
5463
* IMPORTANT!
@@ -63,7 +72,7 @@ module.exports = {
6372
plugins: [
6473
'vue'
6574
],
66-
rules: ${formatRules(category.rules, category.categoryId)},
75+
rules: ${formatRules(category.rules, category.categoryId, alwaysError)},
6776
overrides: [
6877
{
6978
files: '*.vue',
@@ -73,14 +82,18 @@ module.exports = {
7382
}
7483
`
7584
}
85+
if (alwaysError && hasWarningRules(extendsCategoryId)) {
86+
extendsCategoryId += '-error'
87+
}
88+
7689
return `/*
7790
* IMPORTANT!
7891
* This file has been automatically generated,
7992
* in order to update its content execute "npm run update"
8093
*/
8194
module.exports = {
8295
extends: require.resolve('./${extendsCategoryId}'),
83-
rules: ${formatRules(category.rules, category.categoryId)}
96+
rules: ${formatRules(category.rules, category.categoryId, alwaysError)}
8497
}
8598
`
8699
}
@@ -92,6 +105,13 @@ for (const category of categories) {
92105
const content = formatCategory(category)
93106

94107
fs.writeFileSync(filePath, content)
108+
109+
if (hasWarningRules(category.categoryId)) {
110+
fs.writeFileSync(
111+
path.join(ROOT, `${category.categoryId}-error.js`),
112+
formatCategory(category, true)
113+
)
114+
}
95115
}
96116

97117
// Format files.

tools/update-lib-flat-configs.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ const extendsCategories = {
2828
'vue3-use-with-caution': 'vue3-recommended'
2929
}
3030

31-
function formatRules(rules, categoryId) {
31+
function formatRules(rules, categoryId, alwaysError) {
3232
const obj = Object.fromEntries(
3333
rules.map((rule) => {
34-
let options = errorCategories.has(categoryId) ? 'error' : 'warn'
34+
let options =
35+
alwaysError || errorCategories.has(categoryId) ? 'error' : 'warn'
3536
const defaultOptions =
3637
rule.meta && rule.meta.docs && rule.meta.docs.defaultOptions
3738
if (defaultOptions) {
@@ -47,8 +48,17 @@ function formatRules(rules, categoryId) {
4748
return JSON.stringify(obj, null, 2)
4849
}
4950

50-
function formatCategory(category) {
51-
const extendsCategoryId = extendsCategories[category.categoryId]
51+
function hasWarningRules(categoryId) {
52+
return (
53+
categoryId !== 'base' &&
54+
categoryId !== 'vue3-essential' &&
55+
categoryId !== 'vue2-essential'
56+
)
57+
}
58+
59+
function formatCategory(category, alwaysError = false) {
60+
let extendsCategoryId = extendsCategories[category.categoryId]
61+
5262
if (category.categoryId === 'base') {
5363
return `/*
5464
* IMPORTANT!
@@ -79,12 +89,17 @@ module.exports = [
7989
parser: require('vue-eslint-parser'),
8090
sourceType: 'module',
8191
},
82-
rules: ${formatRules(category.rules, category.categoryId)},
92+
rules: ${formatRules(category.rules, category.categoryId, alwaysError)},
8393
processor: 'vue/vue'
8494
}
8595
]
8696
`
8797
}
98+
99+
if (alwaysError && hasWarningRules(extendsCategoryId)) {
100+
extendsCategoryId += '-error'
101+
}
102+
88103
return `/*
89104
* IMPORTANT!
90105
* This file has been automatically generated,
@@ -97,7 +112,7 @@ module.exports = [
97112
...config,
98113
{
99114
name: 'vue/${category.categoryId.replace(/^vue3-/u, '')}/rules',
100-
rules: ${formatRules(category.rules, category.categoryId)},
115+
rules: ${formatRules(category.rules, category.categoryId, alwaysError)},
101116
}
102117
]
103118
`
@@ -110,6 +125,13 @@ for (const category of categories) {
110125
const content = formatCategory(category)
111126

112127
fs.writeFileSync(filePath, content)
128+
129+
if (hasWarningRules(category.categoryId)) {
130+
fs.writeFileSync(
131+
path.join(ROOT, `${category.categoryId}-error.js`),
132+
formatCategory(category, true)
133+
)
134+
}
113135
}
114136

115137
// Format files.

0 commit comments

Comments
 (0)