1 | // Apply the style rules in standard to expressions in `<template>` too.
|
2 |
|
3 | import upstream from './upstream.js'
|
4 | import pluginVue from 'eslint-plugin-vue'
|
5 |
|
6 | // Most extension rules in `eslint-plugin-vue` are only wrapped core ESLint rules
|
7 | // Except for `max-len` and `no-irregular-whitespace`, which are replacements.
|
8 | const ruleNamesToReplace = ['max-len', 'no-irregular-whitespace']
|
9 |
|
10 | // `no-unused-vars` share the same name as the core ESLint rule,
|
11 | // but it actually serves a different purpose.
|
12 | // So it can't be replaced or extended, but should be configured separately.
|
13 | const ruleNamesToIgnore = ['no-unused-vars']
|
14 |
|
15 | const ruleNamesToExtend = Object.keys(upstream.rules)
|
16 | .filter((ruleName) => !!pluginVue.rules[ruleName])
|
17 | .filter((ruleName) => !ruleNamesToReplace.includes(ruleName))
|
18 | .filter((ruleName) => !ruleNamesToIgnore.includes(ruleName))
|
19 |
|
20 | const rules = {}
|
21 | ruleNamesToExtend.forEach((ruleName) => {
|
22 | rules[`vue/${ruleName}`] = upstream.rules[ruleName]
|
23 | })
|
24 | ruleNamesToReplace.forEach((ruleName) => {
|
25 | if (upstream.rules[ruleName]) {
|
26 | // disable the original rule
|
27 | rules[ruleName] = 'off'
|
28 | // disable the stylistic verison of the rule
|
29 | rules[`@stylistic/${ruleName}`] = 'off'
|
30 |
|
31 | // enable the Vue version
|
32 | rules[`vue/${ruleName}`] = upstream.rules[ruleName]
|
33 | }
|
34 | })
|
35 |
|
36 | // `plugins: { vue: pluginVue }` isn't configured here,
|
37 | // Because in `pluginVue.configs['flat/base']`, the `vue` plugin is already defined
|
38 | // as a getter.
|
39 | // The getter doesn't have object equality with the actual plugin object.
|
40 | // Therefore, redefining it here would result in `Cannot redefine plugin` error.
|
41 | // So, here we introduced an implicit dependency on `pluginVue.configs['flat/base']`.
|
42 | export default { rules }
|