-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.mjs
152 lines (141 loc) · 5.2 KB
/
index.mjs
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
/**
* Package @hug/eslint-config <https://github.com/DSI-HUG/eslint-config>
* Released under GNU General Public License v3.0 only <https://github.com/DSI-HUG/eslint-config/blob/main/LICENSE>
* SPDX-License-Identifier: GPL-3.0-only
* Copyright (C) 2022 HUG
* @license GPL-3.0-only
*/
import globals from 'globals';
import angular from './configs/angular.mjs';
import cypress from './configs/cypress.mjs';
import eslint from './configs/eslint.mjs';
import jsdoc from './configs/jsdoc.mjs';
import jsonc from './configs/jsonc.mjs';
import noLoops from './configs/no-loops.mjs';
import noSecrets from './configs/no-secrets.mjs';
import preferArrow from './configs/prefer-arrow.mjs';
import prettier from './configs/prettier.mjs';
import rxjs from './configs/rxjs.mjs';
import simpleImportSort from './configs/simple-import-sort.mjs';
import typescript from './configs/typescript.mjs';
import unusedImports from './configs/unused-imports.mjs';
/** @type {Record<string, string>} */
const DEFAULT_FILES = {
TS: '**/*.ts',
TS_MJS: '**/*.{ts,mjs}',
JS_MJS_CJS: '**/*.{js,mjs,cjs}',
TS_JS_MJS_CJS: '**/*.{ts,js,mjs,cjs}',
HTML: '**/*.html',
JSON: '**/*.json',
JSONC: '**/*.jsonc',
JSON5: '**/*.json5',
E2E: 'e2e/**/*.ts'
};
/** @type {(name: string) => Promise<boolean>} */
const isPackageInstalled = async name => {
try {
await import(name);
return true;
} catch {
return false;
}
};
/** @type { (level: 'moderate' | 'recommended') => Promise<import('eslint').Linter.Config[]> } */
const getConfig = async level => [
eslint([DEFAULT_FILES.TS_JS_MJS_CJS]),
...((await isPackageInstalled('typescript')) ? typescript([DEFAULT_FILES.TS]) : []),
(await isPackageInstalled('rxjs')) ? rxjs[level].ts([DEFAULT_FILES.TS]) : {},
...((await isPackageInstalled('@angular/core')) ? [
...angular[level].ts([DEFAULT_FILES.TS]),
...angular[level].html([DEFAULT_FILES.HTML]),
rxjs[level].angular([DEFAULT_FILES.TS])
] : []),
(await isPackageInstalled('cypress')) ? cypress([DEFAULT_FILES.E2E]) : {},
noSecrets(),
jsonc.json([DEFAULT_FILES.JSON]),
jsonc.jsonc([DEFAULT_FILES.JSONC]),
jsonc.json5([DEFAULT_FILES.JSON5]),
jsdoc.js([DEFAULT_FILES.JS_MJS_CJS]),
jsdoc.ts([DEFAULT_FILES.TS]),
noLoops([DEFAULT_FILES.TS_JS_MJS_CJS]),
preferArrow([DEFAULT_FILES.TS_JS_MJS_CJS]),
simpleImportSort([DEFAULT_FILES.TS_MJS]),
unusedImports([DEFAULT_FILES.TS_MJS]),
prettier(),
{
name: 'hug/defaults/global',
languageOptions: {
globals: {
...globals.browser,
...globals.node,
...globals.jasmine
}
},
linterOptions: {
reportUnusedDisableDirectives: 'error'
}
},
{
name: 'hug/defaults/ignores',
ignores: [
// Compiled output
'**/dist/',
'**/tmp/',
// Node
'**/node_modules/',
'**/package-lock.json',
'**/yarn.lock',
'**/npm-debug.log',
'**/yarn-error.log',
// IDEs and editors
'**/.vscode/',
'**/.idea/',
'**/.project/',
'**/.classpath/',
'**/.settings/',
'**/*.launch',
'**/.c9/',
'**/*.sublime-workspace',
// Miscellaneous
'**/.git/',
'**/.angular/',
'**/.sass-cache/',
'**/.nx',
'**/.docusaurus',
// System files
'**/.DS_Store',
'**/Thumbs.db',
// Capacitor/Cordova
'**/android/',
'**/ios/'
]
}
];
/** @type { import('./index').HugConfig } */
export default {
configs: {
recommended: getConfig('recommended'),
moderate: getConfig('moderate')
},
overrides: {
eslint: (rules, files = [DEFAULT_FILES.TS_JS_MJS_CJS]) => eslint(files, rules),
typescript: (rules, files = [DEFAULT_FILES.TS]) => typescript(files, rules),
rxjs: {
ts: (rules, files = [DEFAULT_FILES.TS]) => rxjs.ts(files, rules),
angular: (rules, files = [DEFAULT_FILES.TS]) => rxjs.angular(files, rules)
},
angular: {
ts: (rules, files = [DEFAULT_FILES.TS]) => angular.ts(files, rules),
html: (rules, files = [DEFAULT_FILES.HTML]) => angular.html(files, rules)
},
cypress: (rules, files = [DEFAULT_FILES.E2E]) => cypress(files, rules),
noSecrets: (rules, files = []) => noSecrets(files, rules),
json: (rules, files = [DEFAULT_FILES.JSON]) => jsonc.json(files, rules),
jsonc: (rules, files = [DEFAULT_FILES.JSONC]) => jsonc.jsonc(files, rules),
json5: (rules, files = [DEFAULT_FILES.JSON5]) => jsonc.json5(files, rules),
noLoops: (rules, files = [DEFAULT_FILES.TS_JS_MJS_CJS]) => noLoops(files, rules),
preferArrow: (rules, files = [DEFAULT_FILES.TS_JS_MJS_CJS]) => preferArrow(files, rules),
simpleImportSort: (rules, files = [DEFAULT_FILES.TS_MJS]) => simpleImportSort(files, rules),
unusedImports: (rules, files = [DEFAULT_FILES.TS_MJS]) => unusedImports(files, rules)
}
};