Skip to content

Commit fd1c24a

Browse files
committed
feat: upgrade use-jessie eslint, and honour '// @jessie-check'
1 parent fa68a8a commit fd1c24a

File tree

2 files changed

+61
-36
lines changed

2 files changed

+61
-36
lines changed

packages/ERTP/src/issuer.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// @ts-check
2+
// @jessie-check
23
/* global makeWeakStore */
34

4-
// Let's hold off on this until agoric-sdk/issues/2704 is addressed.
5-
// 'use jessie';
6-
75
import { assert, details as X } from '@agoric/assert';
86
import { makeExternalStore } from '@agoric/store';
97
import { E } from '@agoric/eventual-send';

packages/eslint-plugin/lib/processors/use-jessie.js

+60-33
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
'use strict';
22

3+
const USE_JESSIE_BEFORE_FIRST_STATEMENT_REGEXP = /^\s*\/\/\s*@jessie-check\s*$/m;
4+
const USE_JESSIE_FIRST_STATEMENT_REGEXP = /^('use\s+jessie'|"use\s+jessie"|import\s+('@jessie.js\/transform-this-module'|"jessie.js\/transform-this-module"))/;
5+
36
// This is all one line so that we don't mess up
47
// eslint's error locations.
58
//
@@ -9,80 +12,90 @@ const jessieRulesOneLine = `\
912
curly: ['error', 'all']\
1013
,eqeqeq: ['error', 'always']\
1114
,no-bitwise: ['error']\
12-
,no-fallthrough: ['error', { commentPattern: 'fallthrough is not allowed' }]\
13-
,no-plusplus: ['error']\
15+
,no-fallthrough: ['error', { commentPattern: 'fallthrough is not allowed in Jessie' }]\
1416
,no-restricted-globals: ['error', 'RegExp', 'Date']\
1517
,no-restricted-syntax: ['error', \
1618
{\
1719
selector: "BinaryExpression[operator='in']",\
18-
message: "'in' is not allowed.",\
20+
message: "'in' is not allowed in Jessie",\
21+
},\
22+
{\
23+
selector: "UpdateExpression[operator='++'][prefix=false]",\
24+
message: "postfix '++' is not allowed in Jessie",\
25+
},\
26+
{\
27+
selector: "UpdateExpression[operator='--'][prefix=false]",\
28+
message: "postfix '--' is not allowed in Jessie",\
1929
},\
2030
{\
2131
selector: "BinaryExpression[operator='instanceof']",\
22-
message: "'instanceof' is not allowed.",\
32+
message: "'instanceof' is not allowed in Jessie",\
2333
},\
2434
{\
2535
selector: 'NewExpression',\
26-
message: "'new' is not allowed.",\
36+
message: "'new' is not allowed in Jessie",\
2737
},\
2838
{\
2939
selector: 'FunctionDeclaration[generator=true]',\
30-
message: 'generators are not allowed.',\
40+
message: 'generators are not allowed in Jessie',\
3141
},\
3242
{\
3343
selector: 'FunctionDeclaration[async=true]',\
34-
message: 'async functions are not allowed.',\
44+
message: 'async functions are not allowed in Jessie',\
3545
},\
3646
{\
3747
selector: 'FunctionExpression[async=true]',\
38-
message: 'async functions are not allowed.',\
48+
message: 'async functions are not allowed in Jessie',\
3949
},\
4050
{\
4151
selector: 'ArrowFunctionExpression[async=true]',\
42-
message: 'async functions are not allowed.',\
52+
message: 'async functions are not allowed in Jessie',\
4353
},\
4454
{\
4555
selector: 'DoWhileStatement',\
46-
message: 'do/while statements are not allowed.',\
56+
message: 'do/while statements are not allowed in Jessie',\
4757
},\
4858
{\
4959
selector: 'ThisExpression',\
50-
message: "'this' not allowed.",\
60+
message: "'this' not allowed in Jessie",\
5161
},\
5262
{\
5363
selector: "UnaryExpression[operator='delete']",\
54-
message: "'delete' not allowed.",\
64+
message: "'delete' not allowed in Jessie",\
5565
},\
5666
{\
5767
selector: 'ForInStatement',\
58-
message: 'for/in statements are not allowed; use for/of Object.keys(val).',\
68+
message: 'for/in statements are not allowed in Jessie; use for/of Object.keys(val).',\
69+
},\
70+
{\
71+
selector: 'MemberExpression[computed=true][property.type!="Literal"][property.type!="UnaryExpression"]',\
72+
message: "computed property names are not allowed in Jessie (except with leading '+')",\
5973
},\
6074
{\
61-
selector: 'MemberExpression[computed=true]',\
62-
message: 'computed property names are not allowed.',\
75+
selector: 'MemberExpression[computed=true][property.type="UnaryExpression"][property.operator!="+"]',\
76+
message: 'computed property names are not allowed in Jessie (except with leading '+')',\
6377
},\
6478
{\
6579
selector: 'Super',\
66-
message: "'super' is not allowed.",\
80+
message: "'super' is not allowed in Jessie",\
6781
},\
6882
{\
6983
selector: 'MetaProperty',\
70-
message: "'MetaProperty' is not allowed.",\
84+
message: "'MetaProperty' is not allowed in Jessie",\
7185
},\
7286
{\
7387
selector: 'ClassExpression',\
74-
message: "'ClassExpression' is not allowed.",\
88+
message: "'ClassExpression' is not allowed in Jessie",\
7589
},\
7690
{\
7791
selector: "CallExpression[callee.name='eval']",\
78-
message: "'eval' is not allowed.",\
92+
message: "'eval' is not allowed in Jessie",\
7993
},\
8094
{\
8195
selector: 'Literal[regex]',\
82-
message: 'regexp literal syntax is not allowed.',\
96+
message: 'regexp literal syntax is not allowed in Jessie',\
8397
}\
8498
]\
85-
,no-ternary: ['error']\
8699
,no-var: ['error']\
87100
,guard-for-in: 'off'\
88101
,semi: ['error', 'always']\
@@ -130,36 +143,50 @@ function indexOfFirstStatement(text) {
130143

131144
function isJessie(text) {
132145
const pos = indexOfFirstStatement(text);
146+
if (text.substr(0, pos).match(USE_JESSIE_BEFORE_FIRST_STATEMENT_REGEXP)) {
147+
return true;
148+
}
133149
if (pos >= 0) {
134-
for (const jessieToken of ['"use jessie";', "'use jessie';"]) {
135-
if (text.substr(pos, jessieToken.length) === jessieToken) {
136-
return true;
137-
}
150+
if (USE_JESSIE_FIRST_STATEMENT_REGEXP.test(text.substr(pos))) {
151+
return true;
138152
}
139153
}
140154
return false;
141155
}
142156

143-
const filenameIsJessie = new Set();
157+
const prependedText = text => {
158+
if (!isJessie(text)) {
159+
return '';
160+
}
161+
let prepend = jessieRulesOneLine;
162+
if (text.startsWith('#!')) {
163+
prepend += '// ';
164+
}
165+
return prepend;
166+
}
167+
168+
const filenameToPrepend = new Map();
144169
module.exports = {
145170
preprocess(text, filename) {
146-
if (isJessie(text)) {
147-
filenameIsJessie.add(filename);
171+
const prepend = prependedText(text);
172+
if (prepend) {
173+
filenameToPrepend.set(filename, prepend);
148174
return [
149-
`${jessieRulesOneLine}${text}`
175+
`${prepend}${text}`
150176
];
151177
}
152-
filenameIsJessie.delete(filename);
178+
filenameToPrepend.delete(filename);
153179
return [text];
154180
},
155181
postprocess(messages, filename) {
156-
if (!filenameIsJessie.has(filename)) {
182+
if (!filenameToPrepend.has(filename)) {
157183
return [].concat(...messages);
158184
}
185+
const prepend = filenameToPrepend.get(filename);
159186
const rewritten = messages.flatMap(errors => errors.map(err => {
160187
if ('fix' in err) {
161-
// Remove the bytes we inserted.
162-
const range = err.fix.range.map(offset => offset > jessieRulesOneLine.length ? offset - jessieRulesOneLine.length : offset);
188+
// Remove the prepension we inserted.
189+
const range = err.fix.range.map(offset => Math.max(offset - prepend.length, 0));
163190
return { ...err, fix: { ...err.fix, range }};
164191
}
165192
return err;

0 commit comments

Comments
 (0)