-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
.eslintrc.cjs
155 lines (155 loc) · 6.28 KB
/
.eslintrc.cjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
module.exports = {
root: true,
env: {
browser: true,
node: true,
},
extends: [
'@nuxtjs/eslint-config-typescript',
'plugin:nuxt/recommended',
// Turns off all rules that are unnecessary or might conflict with Prettier (needs to be last)
'prettier',
// Disable rules covered by oxlint
'plugin:oxlint/recommended',
],
plugins: ['unused-imports'],
rules: {
// Workaround for bug https://github.com/nuxt/eslint-config/issues/147
'no-useless-constructor': 'off',
'@typescript-eslint/no-useless-constructor': 'error',
// Don't report unused imports (this is handled by prettier)
'unused-imports/no-unused-imports': 'off',
// Report unused variables (except the ones prefixed with an underscore)
'unused-imports/no-unused-vars': [
'warn',
{
vars: 'all',
varsIgnorePattern: '^_',
args: 'after-used',
argsIgnorePattern: '^_',
},
],
// Ensure void operator is not used, except for variable assignment or function return (might be handy for promises)
'no-void': ['error', { allowAsStatement: true }],
// Demote this to warning as long as we are still using cjs modules
'import/named': 'warn',
// Import order is handled by prettier (which is incompatible with this rule: https://github.com/simonhaenisch/prettier-plugin-organize-imports/issues/65)
'import/order': 'off',
},
overrides: [
{
files: ['server/**/*.graphql'],
extends: ['plugin:@graphql-eslint/schema-recommended'],
rules: {
// Having an id for a type makes sense (for caching), but the rule is too strict in some cases
'@graphql-eslint/strict-id-in-types': 'warn',
// Make sure that mutations returns not a scalar type (best practice: have special return type for each mutation)
'@graphql-eslint/no-scalar-result-type-on-mutation': 'error',
// Enforces descriptions in your type definitions (reduce to warn since there are too many issues right now)
'@graphql-eslint/require-description': [
'warn',
{
types: true,
FieldDefinition: true,
ObjectTypeDefinition: true,
DirectiveDefinition: true,
},
],
// Checks for duplicate fields in selection set, variables in operation definition, or in arguments set of a field.
'@graphql-eslint/no-duplicate-fields': ['error'],
// Requires mutation argument to be always called "input" and input type to be called Mutation name + "Input".
'@graphql-eslint/input-name': [
'error',
{
checkInputType: true,
// Types name should be pascal case, but mutation names be camel case
caseSensitiveInputType: false,
},
],
// Spaced-comment rule only works for JS-style comments using /* or // but not for GraphQL comments using #
'spaced-comment': 'off',
},
},
{
files: ['*.ts', '*.vue'],
// Parser supporting vue files
parser: 'vue-eslint-parser',
// Extract graphql tags
processor: '@graphql-eslint/graphql',
parserOptions: {
// Use ts parser for ts files and for the script tag in vue files
parser: '@typescript-eslint/parser',
// Correct root
tsconfigRootDir: __dirname,
// Enable rules that require type information
project: true,
// Correctly handle vue files
extraFileExtensions: ['.vue'],
},
extends: [
// Enable typescript-specific stylistic rules
'plugin:@typescript-eslint/stylistic-type-checked',
// Enable strict rules for typescript that use typing information (may be CPU intensive)
'plugin:@typescript-eslint/strict-type-checked',
],
rules: {
// The graphql processor disables the vue processor, so some rules need to be disenabled
// TODO: Remove this once https://github.com/eslint/eslint/issues/14745 is fixed and we can use multiple processors
'vue/comment-directive': 'off',
// Allow any type (for now)
'@typescript-eslint/no-explicit-any': 'warn',
// TODO: Remove this once all errors are fixed
'@typescript-eslint/no-unsafe-call': 'warn',
// TODO: Remove this once all errors are fixed
'@typescript-eslint/no-unsafe-member-access': 'warn',
// TODO: Remove this once all errors are fixed
'@typescript-eslint/no-unsafe-argument': 'warn',
// TODO: Remove this once all errors are fixed
'@typescript-eslint/no-unsafe-return': 'warn',
// TODO: Remove this once all errors are fixed
'@typescript-eslint/no-unsafe-assignment': 'warn',
// TODO: Remove this once all errors are fixed
'@typescript-eslint/no-redundant-type-constituents': 'warn',
// Allow numbers in templates without explicit casting
'@typescript-eslint/restrict-template-expressions': [
'error',
{ allowNumber: true },
],
},
},
{
files: ['layouts/**/*.vue', 'pages/**/*.vue'],
rules: {
// Layouts and pages cannot be confused with HTML components as they are used differently, so no need to worry about single-word names
'vue/multi-word-component-names': 'off',
},
},
{
// Configure rules for "virtual" operation files
files: ['**/*.{ts,vue}/*.graphql'],
parser: '@graphql-eslint/eslint-plugin',
extends: 'plugin:@graphql-eslint/operations-recommended',
rules: {
// Enforces unique fragment name.
'@graphql-eslint/unique-fragment-name': 'error',
// Enforces unique operation names.
'@graphql-eslint/unique-operation-name': 'error',
},
},
{
// Special treatment for test files
files: ['**/*.test.ts', '**/*.spec.ts'],
plugins: ['vitest'],
rules: {
// Disable typescript rule for unbound methods (false positives in spies/mocks)
// TODO: Should enable special rule for vitest once this is implemented
// https://github.com/veritem/eslint-plugin-vitest/issues/2
'@typescript-eslint/unbound-method': 'off',
// Test title must be unique
'vitest/no-identical-title': 'error',
// Test title must be lowercase
'vitest/prefer-lowercase-title': 'error',
},
},
],
}