Skip to content

Commit

Permalink
fix(eslint-config): disable vue stylistic rules by default, close #342
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Mar 20, 2024
1 parent 9c9f8f3 commit ab6bca7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
25 changes: 21 additions & 4 deletions packages/eslint-config/src/flat/configs/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import * as parserTs from '@typescript-eslint/parser'

// @ts-expect-error missing types
import pluginVue from 'eslint-plugin-vue'
import { FlatConfig } from '../types'
import { FlatConfig, NuxtESLintConfigOptions } from '../types'
import { removeUndefined } from '../utils'

export default function vue(): FlatConfig[] {
export default function vue(options: NuxtESLintConfigOptions): FlatConfig[] {
return [
{
name: 'nuxt:setup-vue',
Expand Down Expand Up @@ -56,12 +57,16 @@ export default function vue(): FlatConfig[] {
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
processor: pluginVue.processors['.vue'] as any,
rules: {
rules: removeUndefined({
...pluginVue.configs.base.rules,
...pluginVue.configs['vue3-essential'].rules,
...pluginVue.configs['vue3-strongly-recommended'].rules,
...pluginVue.configs['vue3-recommended'].rules,

// Deprecated in favor of 'vue/block-order'
'vue/component-tags-order': undefined,
'vue/block-order': 'warn',

// Include typescript eslint rules in *.vue files
// https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/eslint-recommended.ts
'constructor-super': 'off', // ts(2335) & ts(2377)
Expand All @@ -85,7 +90,19 @@ export default function vue(): FlatConfig[] {
'prefer-rest-params': 'error', // ts provides better types with rest args over arguments
'prefer-spread': 'error', // ts transpiles spread to apply, so no need for manual apply
'valid-typeof': 'off', // ts(2367)
},

...(options.features?.stylistic
? {}
: {
// Disable Vue's default stylistic rules when stylistic is not enabled
'vue/max-attributes-per-line': undefined,
'vue/no-multi-spaces': undefined,
'vue/no-spaces-around-equal-signs-in-attribute': undefined,
'vue/html-indent': undefined,
'vue/html-quotes': undefined,
'vue/multiline-html-element-content-newline': undefined,
}),
}),
},
]
}
2 changes: 1 addition & 1 deletion packages/eslint-config/src/flat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function createConfigForNuxt(options: NuxtESLintConfigOptions = {})
items.push(...base())
items.push(...javascript())
items.push(...typescript())
items.push(...vue())
items.push(...vue(options))
}

if (options.features?.stylistic) {
Expand Down
3 changes: 3 additions & 0 deletions packages/eslint-config/src/flat/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function removeUndefined<T extends object>(obj: T): T {
return Object.fromEntries(Object.entries(obj).filter(([, value]) => value !== undefined)) as T
}

0 comments on commit ab6bca7

Please sign in to comment.