forked from Agoric/agoric-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eslintrc.cjs
182 lines (175 loc) · 6.13 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
/* eslint-disable no-restricted-syntax */
/* eslint-env node */
const deprecatedForLoanContract = [
['currency', 'brand, asset or another descriptor'],
['blacklist', 'denylist'],
['whitelist', 'allowlist'],
['RUN', 'IST', '/RUN/'],
];
const allDeprecated = [...deprecatedForLoanContract, ['loan', 'debt']];
const deprecatedTerminology = Object.fromEntries(
Object.entries({
all: allDeprecated,
loanContract: deprecatedForLoanContract,
}).map(([category, deprecated]) => [
category,
deprecated.flatMap(([bad, good, badRgx = `/${bad}/i`]) =>
[
['Literal', 'value'],
['TemplateElement', 'value.raw'],
['Identifier', 'name'],
].map(([selectorType, field]) => ({
selector: `${selectorType}[${field}=${badRgx}]`,
message: `Use '${good}' instead of deprecated '${bad}'`,
})),
),
]),
);
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
parserOptions: {
// Works for us!
EXPERIMENTAL_useProjectService: true,
sourceType: 'module',
project: [
'./packages/*/tsconfig.json',
'./packages/*/tsconfig.json',
'./packages/wallet/*/tsconfig.json',
'./tsconfig.json',
],
tsconfigRootDir: __dirname,
extraFileExtensions: ['.cjs'],
},
plugins: ['@typescript-eslint', 'prettier'],
extends: ['@agoric', 'plugin:ava/recommended'],
rules: {
'@typescript-eslint/prefer-ts-expect-error': 'warn',
'@typescript-eslint/no-floating-promises': 'error',
// so that floating-promises can be explicitly permitted with void operator
'no-void': ['error', { allowAsStatement: true }],
// We allow disabled tests in master
'ava/no-skip-test': 'off',
// Contrary to recommendation https://github.com/avajs/ava/blob/main/docs/recipes/typescript.md#typing-tcontext
'ava/use-test': 'off',
// The rule is “safe await separator" which implements the architectural
// goal of “clearly separate an async function's synchronous prelude from
// the part that runs in a future turn”. That is our architectural rule. It
// can be trivially satisfied by inserting a non-nested `await null` in an
// appropriate place to ensure the rest of the async function runs in a
// future turn. “sometimes synchronous" is a bug farm for particularly
// pernicious bugs in which you can combine two correct pieces of code to
// have emergent incorrect behavior. It’s absolutely critical for shared
// service code. That means contracts, but it also means kernel components
// that are used by multiple clients. So we enable it throughout the repo
// and aim for no exceptions.
//
// The default is 'warn', but we want to enforce 'error'.
'@jessie.js/safe-await-separator': 'error',
// CI has a separate format check but keep this warn to maintain that "eslint --fix" prettifies
// UNTIL https://github.com/Agoric/agoric-sdk/issues/4339
'prettier/prettier': 'warn',
},
settings: {
jsdoc: {
mode: 'typescript',
},
},
ignorePatterns: [
'coverage/**',
'**/output/**',
'bundles/**',
'bundle-*',
'dist/**',
'examples/**',
'test262/**',
'*.html',
'ava*.config.js',
],
overrides: [
{
// Tighten rules for exported code.
files: [
'packages/*/src/**/*.js',
'packages/*/tools/**/*.js',
'packages/*/*.js',
'packages/wallet/api/src/**/*.js',
],
rules: {
'no-restricted-syntax': ['error', ...deprecatedTerminology.all],
},
},
{
files: [
'packages/**/demo/**/*.js',
'packages/*/test/**/*.js',
'packages/*/test/**/*.test.js',
'packages/wallet/api/test/**/*.js',
],
rules: {
// sometimes used for organizing logic
'no-lone-blocks': 'off',
// NOTE: This rule is enabled for the repository in general. We turn it
// off for test code for now.
'@jessie.js/safe-await-separator': 'off',
},
},
{
// These tests use EV() instead of E(), which are easy to confuse.
// Help by erroring when E() packages are imported.
files: ['packages/boot/test/**/test-*'],
rules: {
'no-restricted-imports': [
'error',
{ paths: ['@endo/eventual-send', '@endo/far'] },
],
},
},
{
// Allow "loan" contracts to mention the word "loan".
files: ['packages/zoe/src/contracts/loan/*.js'],
rules: {
'no-restricted-syntax': [
'error',
...deprecatedTerminology.loanContract,
],
},
},
{
files: ['*.ts'],
rules: {
// TS has this covered and eslint gets it wrong
'no-undef': 'off',
},
},
{
// disable type-aware linting in HTML
files: ['*.html'],
parserOptions: {
project: false,
},
},
{
files: ['packages/**/upgrade-test-scripts/**/*.*js'],
rules: {
// NOTE: This rule is enabled for the repository in general. We turn it
// off for test code for now.
'@jessie.js/safe-await-separator': 'off',
},
},
{
// Types files have no promises to lint and that linter chokes on the .d.ts twin.
// Maybe due to https://github.com/typescript-eslint/typescript-eslint/issues/7435
files: ['types*.js'],
rules: {
// Disabled to prevent:
// Error: Error while loading rule '@typescript-eslint/no-floating-promises': You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser.
// Occurred while linting ~agoric-sdk/packages/vats/src/core/types.js
// at Object.getParserServices (~agoric-sdk/node_modules/@typescript-eslint/utils/dist/eslint-utils/getParserServices.js:24:15)
// at create (~agoric-sdk/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-floating-promises.js:77:31)
// at Object.create (~agoric-sdk/node_modules/@typescript-eslint/utils/dist/eslint-utils/RuleCreator.js:38:20)
'@typescript-eslint/no-floating-promises': 'off',
},
},
],
};