Skip to content

Commit 2c3e49d

Browse files
committed
feat: only define variable if it is needed
1 parent b6570ca commit 2c3e49d

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

tools/update-lib-configs.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,18 @@ function formatRules(rules, categoryId) {
5151

5252
function formatCategory(category) {
5353
const extendsCategoryId = extendsCategories[category.categoryId]
54+
const formattedRules = formatRules(category.rules, category.categoryId)
55+
const ruleLevelVariable = formattedRules.includes('ruleLevel')
56+
? "const ruleLevel = process.env.VUE_ESLINT_ALWAYS_ERROR === 'true' ? 'error' : 'warn'"
57+
: ''
58+
5459
if (extendsCategoryId == null) {
5560
return `/*
5661
* IMPORTANT!
5762
* This file has been automatically generated,
5863
* in order to update its content execute "npm run update"
5964
*/
60-
const ruleLevel = process.env.VUE_ESLINT_ALWAYS_ERROR === 'true' ? 'error' : 'warn'
65+
${ruleLevelVariable}
6166
6267
module.exports = {
6368
parserOptions: {
@@ -67,7 +72,7 @@ module.exports = {
6772
plugins: [
6873
'vue'
6974
],
70-
rules: ${formatRules(category.rules, category.categoryId)},
75+
rules: ${formattedRules},
7176
overrides: [
7277
{
7378
files: '*.vue',
@@ -82,11 +87,11 @@ module.exports = {
8287
* This file has been automatically generated,
8388
* in order to update its content execute "npm run update"
8489
*/
85-
const ruleLevel = process.env.VUE_ESLINT_ALWAYS_ERROR === 'true' ? 'error' : 'warn'
90+
${ruleLevelVariable}
8691
8792
module.exports = {
8893
extends: require.resolve('./${extendsCategoryId}'),
89-
rules: ${formatRules(category.rules, category.categoryId)}
94+
rules: ${formattedRules}
9095
}
9196
`
9297
}

tools/update-lib-flat-configs.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,18 @@ function formatRules(rules, categoryId) {
5151

5252
function formatCategory(category) {
5353
const extendsCategoryId = extendsCategories[category.categoryId]
54+
const formattedRules = formatRules(category.rules, category.categoryId)
55+
const ruleLevelVariable = formattedRules.includes('ruleLevel')
56+
? "const ruleLevel = process.env.VUE_ESLINT_ALWAYS_ERROR === 'true' ? 'error' : 'warn'"
57+
: ''
58+
5459
if (category.categoryId === 'base') {
5560
return `/*
5661
* IMPORTANT!
5762
* This file has been automatically generated,
5863
* in order to update its content execute "npm run update"
5964
*/
60-
const ruleLevel = process.env.VUE_ESLINT_ALWAYS_ERROR === 'true' ? 'error' : 'warn'
65+
${ruleLevelVariable}
6166
6267
module.exports = [
6368
{
@@ -83,7 +88,7 @@ module.exports = [
8388
parser: require('vue-eslint-parser'),
8489
sourceType: 'module',
8590
},
86-
rules: ${formatRules(category.rules, category.categoryId)},
91+
rules: ${formattedRules},
8792
processor: 'vue/vue'
8893
}
8994
]
@@ -97,13 +102,13 @@ module.exports = [
97102
'use strict'
98103
const config = require('./${extendsCategoryId}.js')
99104
100-
const ruleLevel = process.env.VUE_ESLINT_ALWAYS_ERROR === 'true' ? 'error' : 'warn'
105+
${ruleLevelVariable}
101106
102107
module.exports = [
103108
...config,
104109
{
105110
name: 'vue/${category.categoryId.replace(/^vue3-/u, '')}/rules',
106-
rules: ${formatRules(category.rules, category.categoryId)},
111+
rules: ${formattedRules},
107112
}
108113
]
109114
`

0 commit comments

Comments
 (0)