-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheslint.ts
106 lines (91 loc) · 2.59 KB
/
eslint.ts
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
import path from 'path'
import { HydratedFuseeOptions } from '../options'
enum Level {
Off = 'off',
Warn = 'warn',
Error = 'error',
}
/* eslint-disable @typescript-eslint/no-explicit-any */
export interface ESLintConfig {
ignorePatterns: string[]
parserOptions: {
project: string
}
extends: string[]
rules: {
[rule: string]: Level | [Level, any]
}
settings: { react?: { version: string } }
}
/* eslint-enable @typescript-eslint/no-explicit-any */
let projectDirectory = process.cwd()
export const getProjectDirectory = () => projectDirectory
const setProjectDirectory = (projectDirectory_: string) =>
(projectDirectory = projectDirectory_)
export const makeConfig = (
projectPath: string,
{ react }: HydratedFuseeOptions
) => {
const config: ESLintConfig = {
ignorePatterns: ['/*.js'],
parserOptions: {
project: path.join(projectPath, 'tsconfig.json'),
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'plugin:promise/recommended',
'plugin:node/recommended-module',
'plugin:jest/recommended',
'plugin:jest/style',
'plugin:prettier/recommended',
],
rules: {
'@typescript-eslint/explicit-function-return-type': Level.Off,
'@typescript-eslint/no-parameter-properties': Level.Off,
'@typescript-eslint/no-unused-vars': [
Level.Warn,
{ argsIgnorePattern: '^_' },
],
'node/no-unsupported-features/es-syntax': Level.Off,
'node/no-missing-import': Level.Off,
'node/shebang': Level.Off,
},
settings: {},
}
if (react) {
// React
config.extends.push('plugin:react/recommended')
config.settings.react = {
version: 'detect',
}
config.rules['react/prop-types'] = Level.Off
// React hooks
config.extends.push('plugin:react-hooks/recommended')
// Accessibility
config.extends.push('plugin:jsx-a11y/recommended')
}
return config
}
export function buildGetEslintConfig(
_hydratedFuseeOptions: HydratedFuseeOptions
) {
/**
* Get the ESLint configuration object.
* Also, patch the ESLint module resolution, see https://www.npmjs.com/package/@rushstack/eslint-patch
*/
function get(projectDirectory: string) {
require('@rushstack/eslint-patch/modern-module-resolution')
setProjectDirectory(projectDirectory)
return {
root: true,
extends: [
require.resolve('@marvinroger/fusee/dist/entrypoints/eslint', {
paths: [projectDirectory],
}),
],
}
}
return get
}