forked from Agoric/agoric-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eslintrc.cjs
144 lines (138 loc) · 4.29 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
/* eslint-disable no-restricted-syntax */
/* eslint-env node */
const process = require('process');
const lintTypes = !!process.env.AGORIC_ESLINT_TYPES;
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: lintTypes
? {
sourceType: 'module',
project: [
'./packages/*/jsconfig.json',
'./packages/*/tsconfig.json',
'./packages/wallet/*/jsconfig.json',
'./tsconfig.json',
],
tsconfigRootDir: __dirname,
extraFileExtensions: ['.cjs'],
}
: undefined,
plugins: ['@typescript-eslint', 'prettier'],
extends: ['@agoric'],
rules: {
'@typescript-eslint/prefer-ts-expect-error': 'warn',
'@typescript-eslint/no-floating-promises': lintTypes ? 'warn' : 'off',
// so that floating-promises can be explicitly permitted with void operator
'no-void': ['error', { allowAsStatement: true }],
// 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: {
// 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',
},
},
{
// 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,
},
},
],
};