1 | const fs = require('fs')
|
2 | const path = require('path')
|
3 |
|
4 | const { identity, isMonorepo } = require('./_util')
|
5 |
|
6 | const BABEL_CONFIG = path.resolve('babel.config.js')
|
7 | const BABEL_RC_CONFIG = path.resolve('.babelrc.js')
|
8 |
|
9 | let configFile
|
10 |
|
11 | try {
|
12 | configFile = fs.existsSync(BABEL_CONFIG)
|
13 | ? BABEL_CONFIG
|
14 | : fs.existsSync(BABEL_RC_CONFIG)
|
15 | ? BABEL_RC_CONFIG
|
16 | : require.resolve('@1stg/babel-preset/config')
|
17 | } catch (e) {}
|
18 |
|
19 | exports.js = {
|
20 | files: '*.{mjs,js,jsx}',
|
21 | parser: 'babel-eslint',
|
22 | parserOptions: configFile && {
|
23 | babelOptions: {
|
24 | configFile,
|
25 | },
|
26 | },
|
27 | plugins: ['babel'],
|
28 | rules: {
|
29 | 'babel/new-cap': 2,
|
30 | 'babel/camelcase': 2,
|
31 | 'babel/no-invalid-this': 2,
|
32 | 'babel/no-unused-expressions': 2,
|
33 | 'babel/valid-typeof': 2,
|
34 | 'node/no-unsupported-features/es-syntax': 0,
|
35 | },
|
36 | }
|
37 |
|
38 | const BASE_TSCONFIG = path.resolve('tsconfig.base.json')
|
39 | const DEFAULT_TSCONFIG = path.resolve('tsconfig.json')
|
40 |
|
41 | const PROJECT_TSCONFIG = fs.existsSync(BASE_TSCONFIG)
|
42 | ? BASE_TSCONFIG
|
43 | : fs.existsSync(DEFAULT_TSCONFIG)
|
44 | ? DEFAULT_TSCONFIG
|
45 | : undefined
|
46 |
|
47 | let project
|
48 |
|
49 | try {
|
50 | project = PROJECT_TSCONFIG || require.resolve('@1stg/tsconfig')
|
51 | } catch (e) {}
|
52 |
|
53 | const resolveSettings = {
|
54 | 'import/resolver': {
|
55 | ts: {
|
56 | alwaysTryTypes: true,
|
57 | directory: [
|
58 | PROJECT_TSCONFIG,
|
59 | isMonorepo && 'packages/**/tsconfig.json',
|
60 | ].filter(identity),
|
61 | },
|
62 | },
|
63 | node: {
|
64 | resolvePaths: [path.resolve('node_modules/@types')],
|
65 | tryExtensions: [
|
66 | '.ts',
|
67 | '.tsx',
|
68 | '.d.ts',
|
69 | '.vue',
|
70 | '.mjs',
|
71 | '.js',
|
72 | '.jsx',
|
73 | '.json',
|
74 | '.node',
|
75 | '.mdx',
|
76 | ],
|
77 | },
|
78 | }
|
79 |
|
80 | exports.ts = [
|
81 | {
|
82 | files: '*.{ts,tsx}',
|
83 | parser: '@typescript-eslint/parser',
|
84 | extends: [
|
85 | 'plugin:@typescript-eslint/eslint-recommended',
|
86 | 'plugin:@typescript-eslint/recommended',
|
87 | 'plugin:import/typescript',
|
88 | 'prettier/@typescript-eslint',
|
89 | ],
|
90 | plugins: ['@typescript-eslint'],
|
91 | settings: resolveSettings,
|
92 | rules: {
|
93 | '@typescript-eslint/adjacent-overload-signatures': 2,
|
94 | '@typescript-eslint/array-type': [
|
95 | 2,
|
96 | {
|
97 | default: 'array-simple',
|
98 | },
|
99 | ],
|
100 | '@typescript-eslint/consistent-type-definitions': [2, 'interface'],
|
101 | '@typescript-eslint/explicit-function-return-type': 0,
|
102 | '@typescript-eslint/explicit-member-accessibility': [
|
103 | 2,
|
104 | {
|
105 | accessibility: 'no-public',
|
106 | overrides: {
|
107 | parameterProperties: 'off',
|
108 | },
|
109 | },
|
110 | ],
|
111 | '@typescript-eslint/member-naming': [
|
112 | 2,
|
113 | {
|
114 | private: '^_',
|
115 | },
|
116 | ],
|
117 | '@typescript-eslint/member-ordering': 2,
|
118 | '@typescript-eslint/no-empty-function': 2,
|
119 | '@typescript-eslint/no-extraneous-class': 2,
|
120 | '@typescript-eslint/no-for-in-array': 2,
|
121 | '@typescript-eslint/no-non-null-assertion': 0,
|
122 | '@typescript-eslint/no-parameter-properties': 0,
|
123 | '@typescript-eslint/no-require-imports': 2,
|
124 | '@typescript-eslint/no-this-alias': [
|
125 | 2,
|
126 | {
|
127 | allowDestructuring: true,
|
128 | allowedNames: ['self'],
|
129 | },
|
130 | ],
|
131 | '@typescript-eslint/no-type-alias': [
|
132 | 2,
|
133 | {
|
134 | allowAliases: 'in-unions-and-intersections',
|
135 | allowCallbacks: 'always',
|
136 | allowLiterals: 'in-unions-and-intersections',
|
137 | allowMappedTypes: 'always',
|
138 | },
|
139 | ],
|
140 | '@typescript-eslint/no-useless-constructor': 2,
|
141 | '@typescript-eslint/no-unused-vars': [
|
142 | 2,
|
143 | {
|
144 | argsIgnorePattern: '^_',
|
145 | },
|
146 | ],
|
147 | '@typescript-eslint/prefer-for-of': 2,
|
148 | '@typescript-eslint/prefer-function-type': 2,
|
149 | '@typescript-eslint/triple-slash-reference': [
|
150 | 2,
|
151 | { types: 'prefer-import' },
|
152 | ],
|
153 | '@typescript-eslint/unified-signatures': 2,
|
154 | 'import/default': 0,
|
155 | 'import/named': 0,
|
156 | 'import/no-duplicates': 2,
|
157 | 'import/no-named-as-default': 0,
|
158 | 'import/no-named-as-default-member': 0,
|
159 | 'no-empty-function': 0,
|
160 | 'no-useless-constructor': 0,
|
161 | 'node/no-unsupported-features/es-syntax': 0,
|
162 |
|
163 | 'promise/catch-or-return': 0,
|
164 | },
|
165 | },
|
166 | {
|
167 | files: '*.{ts,tsx}',
|
168 | excludedFiles: '*.d.ts',
|
169 | parserOptions: {
|
170 | project,
|
171 | },
|
172 | extends: ['plugin:@typescript-eslint/recommended-requiring-type-checking'],
|
173 | rules: {
|
174 | '@typescript-eslint/no-floating-promises': 2,
|
175 | '@typescript-eslint/no-misused-promises': 2,
|
176 | '@typescript-eslint/no-unnecessary-qualifier': 2,
|
177 | '@typescript-eslint/no-unnecessary-type-arguments': 2,
|
178 | '@typescript-eslint/prefer-readonly': 2,
|
179 | '@typescript-eslint/restrict-plus-operands': 2,
|
180 | '@typescript-eslint/unbound-method': 2,
|
181 | },
|
182 | },
|
183 | ]
|
184 |
|
185 | exports.dTs = {
|
186 | files: '*.d.ts',
|
187 | rules: {
|
188 | 'import/no-duplicates': 0,
|
189 | 'import/order': 0,
|
190 | },
|
191 | }
|
192 |
|
193 | let tslint = false
|
194 |
|
195 | try {
|
196 | require.resolve('tslint')
|
197 | tslint = true
|
198 | } catch (e) {}
|
199 |
|
200 | const TSLINT_CONFIG = path.resolve('tslint.json')
|
201 |
|
202 | let lintFile
|
203 |
|
204 | try {
|
205 | lintFile = fs.existsSync(TSLINT_CONFIG)
|
206 | ? TSLINT_CONFIG
|
207 | : require.resolve('@1stg/tslint-config')
|
208 | } catch (e) {}
|
209 |
|
210 | exports.tslint = {
|
211 | files: '*.{ts,tsx}',
|
212 | excludedFiles: '*.d.ts',
|
213 | plugins: ['@typescript-eslint/tslint'],
|
214 | rules: {
|
215 | '@typescript-eslint/tslint/config': [
|
216 | 2,
|
217 | {
|
218 | lintFile,
|
219 | },
|
220 | ],
|
221 |
|
222 | 'import/order': 0,
|
223 | },
|
224 | }
|
225 |
|
226 | exports.react = {
|
227 | files: '*.{js,jsx,tsx}',
|
228 | extends: [
|
229 | 'standard-jsx',
|
230 | 'standard-react',
|
231 | 'plugin:react/recommended',
|
232 | 'prettier',
|
233 | 'prettier/react',
|
234 | ],
|
235 | settings: {
|
236 | react: {
|
237 | version: 'detect',
|
238 | },
|
239 | },
|
240 | }
|
241 |
|
242 | exports.reactHooks = {
|
243 | files: '*.{js,jsx,ts,tsx}',
|
244 | plugins: ['react-hooks'],
|
245 | rules: {
|
246 | 'react-hooks/rules-of-hooks': 2,
|
247 | 'react-hooks/exhaustive-deps': 2,
|
248 | },
|
249 | }
|
250 |
|
251 | exports.reactTs = {
|
252 | files: '*.{ts,tsx}',
|
253 | rules: {
|
254 | 'no-restricted-imports': [2, 'prop-types'],
|
255 | 'react/prop-types': 0,
|
256 | },
|
257 | }
|
258 |
|
259 | exports.vue = {
|
260 | files: ['*.vue'],
|
261 | parser: 'vue-eslint-parser',
|
262 | parserOptions: {
|
263 | parser: '@typescript-eslint/parser',
|
264 | extraFileExtensions: ['.vue'],
|
265 | },
|
266 | settings: resolveSettings,
|
267 | extends: [
|
268 | 'plugin:@typescript-eslint/eslint-recommended',
|
269 | 'plugin:@typescript-eslint/recommended',
|
270 | 'plugin:import/typescript',
|
271 | 'prettier/@typescript-eslint',
|
272 | 'plugin:vue/recommended',
|
273 | 'prettier/vue',
|
274 | ],
|
275 | plugins: ['@typescript-eslint', 'vue'],
|
276 | rules: {
|
277 | '@typescript-eslint/explicit-function-return-type': 0,
|
278 | 'node/no-unsupported-features/es-syntax': 0,
|
279 | 'promise/catch-or-return': 0,
|
280 | },
|
281 | }
|
282 |
|
283 | exports.mdx = Object.assign({}, exports.react, {
|
284 | files: '*.{md,mdx}',
|
285 | extends: exports.react.extends.concat(['plugin:mdx/recommended']),
|
286 | settings: Object.assign({}, exports.react.settings, resolveSettings),
|
287 | rules: {
|
288 | 'node/no-unsupported-features/es-syntax': 0,
|
289 | },
|
290 | })
|
291 |
|
292 | exports.jest = {
|
293 | files: '*.{spec,test}.{js,jsx,ts,tsx}',
|
294 | extends: ['plugin:jest/recommended'],
|
295 | }
|
296 |
|
297 | exports.test = {
|
298 | files: '**/{test,tests}/**/*.{js,jsx,mdx,ts,tsx,vue}',
|
299 | rules: {
|
300 | 'node/no-extraneous-import': 0,
|
301 | },
|
302 | }
|
303 |
|
304 | exports.overrides = exports.ts
|
305 | .concat([
|
306 | exports.js,
|
307 | exports.dTs,
|
308 | tslint && lintFile && exports.tslint,
|
309 | exports.react,
|
310 | exports.reactHooks,
|
311 | exports.reactTs,
|
312 | exports.vue,
|
313 | exports.mdx,
|
314 | exports.jest,
|
315 | exports.test,
|
316 | ])
|
317 | .filter(identity)
|