forked from PrairieLearn/PrairieLearn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eslintrc.cjs
143 lines (134 loc) · 4.11 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
const NO_RESTRICTED_SYNTAX = [
{
selector:
'CallExpression[callee.type="MemberExpression"][callee.object.name="MathJax"][callee.property.name=/^(typeset|tex2chtml|tex2svg)$/]',
message: "Don't use the synchronous MathJax API; use a function like typesetPromise() instead.",
},
{
selector: 'MemberExpression[object.name="MathJax"][property.name="Hub"]',
message: 'Use MathJax.typesetPromise() instead of MathJax.Hub',
},
{
selector: 'ImportDeclaration[source.value="fs-extra"]:has(ImportNamespaceSpecifier)',
message: 'Use a default import instead of a namespace import for fs-extra',
},
];
module.exports = {
env: {
node: true,
es2021: true,
},
extends: [
'eslint:recommended',
'plugin:import/recommended',
'plugin:import/typescript',
'plugin:@typescript-eslint/stylistic',
'plugin:@typescript-eslint/strict',
'prettier',
],
plugins: ['@typescript-eslint', 'no-floating-promise', 'no-only-tests', 'mocha', '@prairielearn'],
parserOptions: {
ecmaVersion: 13,
},
settings: {
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.js'],
},
'import/resolver': {
typescript: true,
node: true,
},
},
reportUnusedDisableDirectives: true,
rules: {
curly: ['error', 'multi-line', 'consistent'],
eqeqeq: ['error', 'smart'],
'no-floating-promise/no-floating-promise': 'error',
'no-only-tests/no-only-tests': 'error',
'handle-callback-err': 'error',
'no-template-curly-in-string': 'error',
'no-restricted-globals': [
'error',
// These are not available in ES modules.
'__filename',
'__dirname',
],
'no-restricted-syntax': ['error', ...NO_RESTRICTED_SYNTAX],
'object-shorthand': 'error',
// This isn't super useful to use because we're using TypeScript.
'import/no-named-as-default-member': 'off',
'import/order': [
'error',
{
'newlines-between': 'always',
alphabetize: {
order: 'asc',
},
pathGroups: [
{
pattern: '@prairielearn/**',
group: 'external',
position: 'after',
},
],
pathGroupsExcludedImportTypes: ['builtin'],
},
],
// The recommended Mocha rules are too strict for us; we'll only enable
// these two rules.
'mocha/no-exclusive-tests': 'error',
'mocha/no-skipped-tests': 'error',
// These rules are implemented in `packages/eslint-plugin-prairielearn`.
'@prairielearn/aws-client-mandatory-config': 'error',
'@prairielearn/aws-client-shared-config': 'error',
// Replaces the standard `no-unused-vars` rule.
'@typescript-eslint/no-unused-vars': [
'error',
{
args: 'after-used',
argsIgnorePattern: '^_',
},
],
// We use empty functions in quite a few places, so we'll disable this rule.
'@typescript-eslint/no-empty-function': 'off',
// Look, sometimes we just want to use `any`.
'@typescript-eslint/no-explicit-any': 'off',
// This was enabled when we upgraded to `@typescript-eslint/*` v6.
// TODO: fix the violations so we can enable this rule.
'@typescript-eslint/no-dynamic-delete': 'off',
},
overrides: [
{
files: ['*.ts'],
rules: {
// TypeScript performs similar checks, so we disable these for TS files.
// https://typescript-eslint.io/linting/troubleshooting/performance-troubleshooting/#eslint-plugin-import
'import/named': 'off',
'import/namespace': 'off',
'import/default': 'off',
'import/no-named-as-default-member': 'off',
'no-restricted-syntax': [
'error',
...NO_RESTRICTED_SYNTAX,
{
selector: 'MemberExpression[object.name="module"][property.name="exports"]',
message: 'module.exports should not be used in TypeScript files',
},
],
},
},
{
files: ['*.test.{js,ts,mjs}'],
env: {
mocha: true,
},
},
{
files: ['apps/prairielearn/assets/scripts/**/*'],
env: {
browser: true,
jquery: true,
},
},
],
};