Skip to content

Commit 7990ea3

Browse files
update lint rule to accept %-notation in operation headers (#595)
1 parent a30e405 commit 7990ea3

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

src/lint/collect-header-diagnostics.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,24 @@ export function collectHeaderDiagnostics(
4949

5050
// CreateForInIterator
5151
// Object.fromEntries
52-
// _NativeError_ [ @@whatever ]
53-
// Array.prototype [ @@iterator ]
52+
// _NativeError_ [ %whatever% ]
53+
// Array.prototype [ %Symbol.iterator% ]
5454
// %ForInIteratorPrototype%.next
5555
// Object.prototype.__defineGetter__
56-
/^([%_]?)[A-Za-z][A-Za-z0-9/]*\1(\.[A-Za-z][A-Za-z0-9]*|\.__[a-z][A-Za-z0-9]*__| \[ @@[a-z][a-zA-Z]+ \])*\s*$/,
56+
/^([%_]?)[A-Za-z][A-Za-z0-9/]*\1(\.[A-Za-z][A-Za-z0-9]*|\.__[a-z][A-Za-z0-9]*__| \[ %[a-zA-Z0-9_$.]+% \])*\s*$/,
5757
].some(r => r.test(name));
5858

5959
if (!nameMatches) {
6060
const { line, column } = offsetToLineAndColumn(contents, 0);
61+
let message = `expected operation to have a name like 'Example', 'Runtime Semantics: Foo', 'Example.prop', etc, but found ${JSON.stringify(name)}`;
62+
const oldSymbolMatch = name.match(/@@([a-z][a-zA-Z]+)/);
63+
if (oldSymbolMatch != null) {
64+
message = `found use of unsupported legacy well-known Symbol notation ${oldSymbolMatch[0]}; use %Symbol.${oldSymbolMatch[1]}% instead`;
65+
}
6166
report({
6267
type: 'contents',
6368
ruleId,
64-
message: `expected operation to have a name like 'Example', 'Runtime Semantics: Foo', 'Example.prop', etc, but found ${JSON.stringify(
65-
name,
66-
)}`,
69+
message,
6770
node: element,
6871
nodeRelativeLine: line,
6972
nodeRelativeColumn: column,

test/lint.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,19 @@ describe('linting whole program', () => {
289289
"expected operation to have a name like 'Example', 'Runtime Semantics: Foo', 'Example.prop', etc, but found \"something: \"",
290290
},
291291
);
292+
await assertLint(
293+
positioned`
294+
<emu-clause id="foo">
295+
<h1>${M}Example [ @@baz ] ( )</h1>
296+
</emu-clause>
297+
`,
298+
{
299+
ruleId: 'header-format',
300+
nodeType: 'h1',
301+
message:
302+
'found use of unsupported legacy well-known Symbol notation @@baz; use %Symbol.baz% instead',
303+
},
304+
);
292305
});
293306

294307
it('spacing', async () => {
@@ -356,7 +369,7 @@ describe('linting whole program', () => {
356369
<h1>_Example_ ( )</h1>
357370
</emu-clause>
358371
<emu-clause id="i7">
359-
<h1>%Foo%.bar [ @@iterator ] ( )</h1>
372+
<h1>%Foo%.bar [ %Symbol.iterator% ] ( )</h1>
360373
</emu-clause>
361374
<emu-clause id="i8">
362375
<h1>ForIn/OfHeadEvaluation ( )</h1>
@@ -365,7 +378,7 @@ describe('linting whole program', () => {
365378
<h1>Object.prototype.__defineGetter__ ( )</h1>
366379
</emu-clause>
367380
<emu-clause id="i10">
368-
<h1>_NativeError_ [ @@baz ] ( )</h1>
381+
<h1>_NativeError_ [ %baz% ] ( )</h1>
369382
</emu-clause>
370383
`);
371384
});

0 commit comments

Comments
 (0)