Skip to content

Commit ab6bca7

Browse files
committedMar 20, 2024·
fix(eslint-config): disable vue stylistic rules by default, close #342
1 parent 9c9f8f3 commit ab6bca7

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed
 

‎packages/eslint-config/src/flat/configs/vue.ts

+21-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import * as parserTs from '@typescript-eslint/parser'
33

44
// @ts-expect-error missing types
55
import pluginVue from 'eslint-plugin-vue'
6-
import { FlatConfig } from '../types'
6+
import { FlatConfig, NuxtESLintConfigOptions } from '../types'
7+
import { removeUndefined } from '../utils'
78

8-
export default function vue(): FlatConfig[] {
9+
export default function vue(options: NuxtESLintConfigOptions): FlatConfig[] {
910
return [
1011
{
1112
name: 'nuxt:setup-vue',
@@ -56,12 +57,16 @@ export default function vue(): FlatConfig[] {
5657
},
5758
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5859
processor: pluginVue.processors['.vue'] as any,
59-
rules: {
60+
rules: removeUndefined({
6061
...pluginVue.configs.base.rules,
6162
...pluginVue.configs['vue3-essential'].rules,
6263
...pluginVue.configs['vue3-strongly-recommended'].rules,
6364
...pluginVue.configs['vue3-recommended'].rules,
6465

66+
// Deprecated in favor of 'vue/block-order'
67+
'vue/component-tags-order': undefined,
68+
'vue/block-order': 'warn',
69+
6570
// Include typescript eslint rules in *.vue files
6671
// https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/eslint-recommended.ts
6772
'constructor-super': 'off', // ts(2335) & ts(2377)
@@ -85,7 +90,19 @@ export default function vue(): FlatConfig[] {
8590
'prefer-rest-params': 'error', // ts provides better types with rest args over arguments
8691
'prefer-spread': 'error', // ts transpiles spread to apply, so no need for manual apply
8792
'valid-typeof': 'off', // ts(2367)
88-
},
93+
94+
...(options.features?.stylistic
95+
? {}
96+
: {
97+
// Disable Vue's default stylistic rules when stylistic is not enabled
98+
'vue/max-attributes-per-line': undefined,
99+
'vue/no-multi-spaces': undefined,
100+
'vue/no-spaces-around-equal-signs-in-attribute': undefined,
101+
'vue/html-indent': undefined,
102+
'vue/html-quotes': undefined,
103+
'vue/multiline-html-element-content-newline': undefined,
104+
}),
105+
}),
89106
},
90107
]
91108
}

‎packages/eslint-config/src/flat/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export async function createConfigForNuxt(options: NuxtESLintConfigOptions = {})
3434
items.push(...base())
3535
items.push(...javascript())
3636
items.push(...typescript())
37-
items.push(...vue())
37+
items.push(...vue(options))
3838
}
3939

4040
if (options.features?.stylistic) {
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function removeUndefined<T extends object>(obj: T): T {
2+
return Object.fromEntries(Object.entries(obj).filter(([, value]) => value !== undefined)) as T
3+
}

0 commit comments

Comments
 (0)
Please sign in to comment.