2024-04-05 18:08:32 +00:00
|
|
|
// @ts-check
|
|
|
|
import { createConfigForNuxt } from '@nuxt/eslint-config/flat'
|
|
|
|
// @ts-expect-error missing types
|
2024-04-03 20:46:58 +00:00
|
|
|
import noOnlyTests from 'eslint-plugin-no-only-tests'
|
2024-04-05 18:08:32 +00:00
|
|
|
import typegen from 'eslint-typegen'
|
|
|
|
import perfectionist from 'eslint-plugin-perfectionist'
|
2024-04-03 20:46:58 +00:00
|
|
|
|
2024-04-05 18:08:32 +00:00
|
|
|
export default createConfigForNuxt({
|
|
|
|
features: {
|
|
|
|
stylistic: {
|
|
|
|
commaDangle: 'always-multiline',
|
|
|
|
},
|
|
|
|
tooling: true,
|
2024-04-03 20:46:58 +00:00
|
|
|
},
|
2024-04-05 18:08:32 +00:00
|
|
|
})
|
|
|
|
.prepend(
|
|
|
|
{
|
|
|
|
// Ignores have to be a separate object to be treated as global ignores
|
|
|
|
// Don't add other attributes to this object
|
|
|
|
ignores: [
|
|
|
|
'packages/schema/schema/**',
|
2024-05-01 13:10:33 +00:00
|
|
|
'packages/nuxt/src/app/components/welcome.vue',
|
|
|
|
'packages/nuxt/src/app/components/error-*.vue',
|
|
|
|
'packages/nuxt/src/core/runtime/nitro/error-*',
|
2024-04-05 18:08:32 +00:00
|
|
|
],
|
2024-04-03 20:46:58 +00:00
|
|
|
},
|
2024-04-05 18:08:32 +00:00
|
|
|
{
|
|
|
|
languageOptions: {
|
|
|
|
globals: {
|
|
|
|
$fetch: 'readonly',
|
|
|
|
NodeJS: 'readonly',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
name: 'local/settings',
|
|
|
|
settings: {
|
|
|
|
jsdoc: {
|
|
|
|
ignoreInternal: true,
|
|
|
|
tagNamePreference: {
|
|
|
|
note: 'note',
|
|
|
|
warning: 'warning',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-04-03 20:46:58 +00:00
|
|
|
},
|
2024-04-05 18:08:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
.override('nuxt/javascript', {
|
2024-04-03 20:46:58 +00:00
|
|
|
rules: {
|
2024-04-05 18:08:32 +00:00
|
|
|
'curly': ['error', 'all'], // Including if blocks with a single statement
|
2024-04-03 20:46:58 +00:00
|
|
|
'dot-notation': 'error',
|
|
|
|
'no-console': ['warn', { allow: ['warn', 'error', 'debug'] }],
|
2024-04-05 18:08:32 +00:00
|
|
|
'no-lonely-if': 'error', // No single if in an "else" block
|
|
|
|
'no-useless-rename': 'error',
|
|
|
|
'object-shorthand': 'error',
|
|
|
|
'prefer-const': ['error', { destructuring: 'any', ignoreReadBeforeAssign: false }],
|
|
|
|
'require-await': 'error',
|
|
|
|
'sort-imports': ['error', { ignoreDeclarationSort: true }],
|
|
|
|
},
|
|
|
|
})
|
2024-04-03 20:46:58 +00:00
|
|
|
|
2024-04-05 18:08:32 +00:00
|
|
|
.override('nuxt/typescript/rules', {
|
|
|
|
rules: {
|
2024-04-03 20:46:58 +00:00
|
|
|
'@typescript-eslint/ban-ts-comment': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
'ts-expect-error': 'allow-with-description',
|
2024-04-05 18:08:32 +00:00
|
|
|
'ts-ignore': true,
|
|
|
|
},
|
2024-04-03 20:46:58 +00:00
|
|
|
],
|
2024-04-05 18:08:32 +00:00
|
|
|
'@typescript-eslint/no-dynamic-delete': 'off',
|
2024-04-03 20:46:58 +00:00
|
|
|
'@typescript-eslint/no-unused-vars': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
argsIgnorePattern: '^_',
|
2024-11-12 17:13:44 +00:00
|
|
|
destructuredArrayIgnorePattern: '^_',
|
2024-04-05 18:08:32 +00:00
|
|
|
ignoreRestSiblings: true,
|
2024-11-12 17:13:44 +00:00
|
|
|
varsIgnorePattern: '',
|
2024-04-05 18:08:32 +00:00
|
|
|
},
|
2024-04-03 20:46:58 +00:00
|
|
|
],
|
2024-04-05 18:08:32 +00:00
|
|
|
'@typescript-eslint/triple-slash-reference': 'off',
|
|
|
|
'@typescript-eslint/unified-signatures': 'off',
|
|
|
|
...{
|
|
|
|
// TODO: Discuss if we want to enable this
|
|
|
|
'@typescript-eslint/ban-types': 'off',
|
|
|
|
// TODO: Discuss if we want to enable this
|
|
|
|
'@typescript-eslint/no-explicit-any': 'off',
|
|
|
|
// TODO: Discuss if we want to enable this
|
|
|
|
'@typescript-eslint/no-invalid-void-type': 'off',
|
|
|
|
},
|
2024-04-03 20:46:58 +00:00
|
|
|
},
|
2024-04-05 18:08:32 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
.override('nuxt/tooling/unicorn', {
|
2024-04-03 20:46:58 +00:00
|
|
|
rules: {
|
2024-04-05 18:08:32 +00:00
|
|
|
'unicorn/no-new-array': 'off',
|
|
|
|
'unicorn/prefer-dom-node-text-content': 'off',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
.override('nuxt/vue/rules', {
|
2024-04-03 20:46:58 +00:00
|
|
|
rules: {
|
2024-04-05 18:08:32 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
// Stylistic rules
|
|
|
|
.override('nuxt/stylistic', {
|
2024-04-03 20:46:58 +00:00
|
|
|
rules: {
|
2024-04-05 18:08:32 +00:00
|
|
|
'@stylistic/brace-style': ['error', '1tbs', { allowSingleLine: true }],
|
|
|
|
'@stylistic/indent-binary-ops': 'off',
|
|
|
|
'@stylistic/max-statements-per-line': 'off',
|
|
|
|
'@stylistic/operator-linebreak': 'off',
|
|
|
|
'@stylistic/quote-props': ['error', 'consistent'],
|
|
|
|
'@stylistic/space-before-function-paren': ['error', 'always'],
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
// Append local rules
|
|
|
|
.append(
|
|
|
|
{
|
|
|
|
files: ['**/*.vue', '**/*.ts', '**/*.mts', '**/*.js', '**/*.cjs', '**/*.mjs'],
|
|
|
|
name: 'local/rules',
|
|
|
|
rules: {
|
|
|
|
'import/no-restricted-paths': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
zones: [
|
|
|
|
{
|
|
|
|
from: 'packages/nuxt/src/!(core)/**/*',
|
|
|
|
message: 'core should not directly import from modules.',
|
|
|
|
target: 'packages/nuxt/src/core',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
from: 'packages/nuxt/src/!(app)/**/*',
|
|
|
|
message: 'app should not directly import from modules.',
|
|
|
|
target: 'packages/nuxt/src/app',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
from: 'packages/nuxt/src/app/**/index.ts',
|
|
|
|
message: 'should not import from barrel/index files',
|
|
|
|
target: 'packages/nuxt/src',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
from: 'packages/nitro',
|
|
|
|
message: 'nitro should not directly import other packages.',
|
|
|
|
target: 'packages/!(nitro)/**/*',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
'jsdoc/check-tag-names': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
definedTags: [
|
|
|
|
'experimental',
|
|
|
|
'__NO_SIDE_EFFECTS__',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
files: ['packages/nuxt/src/app/**', 'test/**', '**/runtime/**', '**/*.test.ts'],
|
|
|
|
name: 'local/disables/client-console',
|
|
|
|
rules: {
|
|
|
|
'no-console': 'off',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
files: ['**/fixtures/**', '**/fixture/**'],
|
|
|
|
name: 'local/disables/fixtures',
|
|
|
|
rules: {
|
|
|
|
'@typescript-eslint/no-unused-vars': 'off',
|
|
|
|
'@typescript-eslint/triple-slash-reference': 'off',
|
|
|
|
'vue/multi-word-component-names': 'off',
|
|
|
|
'vue/valid-v-for': 'off',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
files: ['test/**', '**/*.test.ts'],
|
|
|
|
name: 'local/disables/tests',
|
|
|
|
plugins: {
|
|
|
|
'no-only-tests': noOnlyTests,
|
|
|
|
},
|
|
|
|
rules: {
|
|
|
|
'@typescript-eslint/no-explicit-any': 'off',
|
|
|
|
'no-console': 'off',
|
|
|
|
'no-only-tests/no-only-tests': 'error',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// Sort rule keys in eslint config
|
2024-08-06 14:16:20 +00:00
|
|
|
// @ts-expect-error incorrect types 🤔
|
2024-04-05 18:08:32 +00:00
|
|
|
{
|
|
|
|
files: ['**/eslint.config.mjs'],
|
|
|
|
name: 'local/sort-eslint-config',
|
|
|
|
plugins: {
|
|
|
|
perfectionist,
|
|
|
|
},
|
|
|
|
rules: {
|
|
|
|
'perfectionist/sort-objects': 'error',
|
|
|
|
},
|
|
|
|
},
|
2024-05-01 13:10:33 +00:00
|
|
|
{
|
|
|
|
files: ['packages/nuxt/src/app/components/welcome.vue'],
|
|
|
|
rules: {
|
|
|
|
'vue/multi-word-component-names': 'off',
|
|
|
|
},
|
|
|
|
},
|
2024-04-05 18:08:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Generate type definitions for the eslint config
|
|
|
|
.onResolved((configs) => {
|
|
|
|
return typegen(configs)
|
|
|
|
})
|