-
Notifications
You must be signed in to change notification settings - Fork 5
/
.eslintrc.cjs
220 lines (214 loc) · 5.7 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// @ts-check
const baseConfig = require('@seedcompany/eslint-plugin').configs.base;
const oldRestrictedImports = [
{
name: '@nestjs/common',
importNames: [
'BadRequestException',
'HttpException',
'UnauthorizedException',
'MethodNotAllowedException',
'NotFoundException',
'ForbiddenException',
'NotAcceptableException',
'RequestTimeoutException',
'ConflictException',
'GoneException',
'PayloadTooLargeException',
'UnsupportedMediaTypeException',
'UnprocessableEntityException',
'InternalServerErrorException',
'NotImplementedException',
'HttpVersionNotSupportedException',
'BadGatewayException',
'ServiceUnavailableException',
'GatewayTimeoutException',
],
message: 'Use our exceptions in common folder instead',
},
{
name: 'lodash',
importNames: ['Dictionary', 'NumericDictionary', 'AnyKindOfDictionary'],
message: 'Use a type with strict keys instead',
},
{
name: 'ts-essentials',
importNames: ['Dictionary', 'SafeDictionary'],
message: 'Use a type with strict keys instead',
},
];
/** @type {import('@seedcompany/eslint-plugin').ImportRestriction[]} */
const restrictedImports = [
// Guard against ts hints trying to insert "src/" paths.
// It does that with basePath configured which is required for path aliases, even though it's never what we want.
{
path: 'src/common',
replacement: { path: '~/common' },
},
{
pattern: 'src/common/*',
replacement: { path: '~/common/{path}' },
},
{
path: 'src/core',
replacement: { path: '~/core' },
},
{
pattern: 'src/core/*',
replacement: { path: '~/core/{path}' },
},
{
pattern: 'src/*',
message: 'Use relative import instead',
},
{
path: ['..', '../..', '../../..'],
message: 'Not specific enough',
},
{
importNames: 'IntersectionType',
path: '@nestjs/graphql',
replacement: { importName: 'IntersectTypes', path: '~/common' },
message: 'Use our wrapper that allows for varargs & provides members array',
},
{
importNames: 'HttpAdapterHost',
path: '@nestjs/core',
replacement: { path: '~/core/http' },
},
{
importNames: ['NestMiddleware', 'NestModule'],
path: '@nestjs/common',
message: 'Do not use express/connect middleware',
},
{
importNames: ['RouteConfig', 'RouteConstraints'],
path: '@nestjs/platform-fastify',
replacement: { path: '~/core/http' },
},
];
const namingConvention = [
{
selector: 'typeLike',
format: ['PascalCase'],
},
// Forbid I prefixed type names
{
selector: 'interface',
format: ['PascalCase'],
custom: { regex: '^I[A-Z].+$', match: false },
},
{
selector: 'memberLike',
format: ['camelCase'],
leadingUnderscore: 'forbid',
},
{
selector: 'memberLike',
modifiers: ['readonly', 'static'],
format: ['camelCase', 'PascalCase'],
leadingUnderscore: 'forbid',
},
// allow `__typename` exception since it's a GQL standard.
{
selector: 'property',
filter: '__typename',
format: null,
},
// allow exceptions for edgedb query builder
{
selector: 'objectLiteralProperty',
filter: 'filter_single',
format: null,
},
{
selector: 'objectLiteralProperty',
filter: 'order_by',
format: null,
},
// Allow object literal keys to be anything if they are in quotes
// Used mainly by cypher query builder
{
selector: 'objectLiteralProperty',
modifiers: ['requiresQuotes'],
format: null,
},
{
selector: 'property',
format: ['camelCase', 'PascalCase'],
leadingUnderscore: 'forbid',
},
{
selector: 'enumMember',
format: ['PascalCase', 'UPPER_CASE'],
leadingUnderscore: 'forbid',
},
{
selector: 'parameter',
format: ['camelCase'],
leadingUnderscore: 'allow',
},
{
selector: 'parameter',
modifiers: ['destructured'],
format: ['camelCase', 'UPPER_CASE'],
},
];
/** @type {import('@typescript-eslint/utils').TSESLint.Linter.Config} */
const config = {
root: true,
plugins: [
'@seedcompany',
'typescript-sort-keys',
'no-only-tests',
],
extends: ['plugin:@seedcompany/nestjs'],
rules: {
'no-console': 'error',
'no-only-tests/no-only-tests': 'error',
'@typescript-eslint/naming-convention': ['warn', ...namingConvention],
'no-restricted-imports': ['error', { 'paths': oldRestrictedImports }],
'@seedcompany/no-restricted-imports': ['error', ...restrictedImports],
'no-restricted-syntax': [
'error',
...baseConfig.rules['no-restricted-syntax']?.slice(1),
{
selector: 'NewExpression[callee.name="Logger"]',
'message': `
Inject a logger instead
constructor(
@Logger('name') private logger: ILogger
) {}
`,
},
],
// TODO Enable this and fix errors (both types & logic changes will be needed)
'@typescript-eslint/no-unnecessary-condition': 'off',
},
overrides: [
{
files: './src/core/database/query-augmentation/*.ts',
rules: {
// This is enforced to treat functions arguments as contravariant instead of bivariant.
// This doesn't matter here as this class won't be overridden.
// Declaring them as methods keeps their color the same as the rest of the query methods.
'@typescript-eslint/method-signature-style': 'off',
},
},
{
files: './src/core/edgedb/generator/*.ts',
rules: {
// Scripts can use the console for logging
'no-console': 'off',
},
},
{
files: './dbschema/seeds/*.ts',
rules: {
'import/no-default-export': 'off',
// 'import/no-named-export': 'error',
},
},
],
};
module.exports = config;