Skip to content

Commit

Permalink
update lint rule to accept %-notation in operation headers (#595)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelficarra authored Jun 27, 2024
1 parent a30e405 commit 7990ea3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
15 changes: 9 additions & 6 deletions src/lint/collect-header-diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,24 @@ export function collectHeaderDiagnostics(

// CreateForInIterator
// Object.fromEntries
// _NativeError_ [ @@whatever ]
// Array.prototype [ @@iterator ]
// _NativeError_ [ %whatever% ]
// Array.prototype [ %Symbol.iterator% ]
// %ForInIteratorPrototype%.next
// Object.prototype.__defineGetter__
/^([%_]?)[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*$/,
/^([%_]?)[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*$/,
].some(r => r.test(name));

if (!nameMatches) {
const { line, column } = offsetToLineAndColumn(contents, 0);
let message = `expected operation to have a name like 'Example', 'Runtime Semantics: Foo', 'Example.prop', etc, but found ${JSON.stringify(name)}`;
const oldSymbolMatch = name.match(/@@([a-z][a-zA-Z]+)/);
if (oldSymbolMatch != null) {
message = `found use of unsupported legacy well-known Symbol notation ${oldSymbolMatch[0]}; use %Symbol.${oldSymbolMatch[1]}% instead`;
}
report({
type: 'contents',
ruleId,
message: `expected operation to have a name like 'Example', 'Runtime Semantics: Foo', 'Example.prop', etc, but found ${JSON.stringify(
name,
)}`,
message,
node: element,
nodeRelativeLine: line,
nodeRelativeColumn: column,
Expand Down
17 changes: 15 additions & 2 deletions test/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,19 @@ describe('linting whole program', () => {
"expected operation to have a name like 'Example', 'Runtime Semantics: Foo', 'Example.prop', etc, but found \"something: \"",
},
);
await assertLint(
positioned`
<emu-clause id="foo">
<h1>${M}Example [ @@baz ] ( )</h1>
</emu-clause>
`,
{
ruleId: 'header-format',
nodeType: 'h1',
message:
'found use of unsupported legacy well-known Symbol notation @@baz; use %Symbol.baz% instead',
},
);
});

it('spacing', async () => {
Expand Down Expand Up @@ -356,7 +369,7 @@ describe('linting whole program', () => {
<h1>_Example_ ( )</h1>
</emu-clause>
<emu-clause id="i7">
<h1>%Foo%.bar [ @@iterator ] ( )</h1>
<h1>%Foo%.bar [ %Symbol.iterator% ] ( )</h1>
</emu-clause>
<emu-clause id="i8">
<h1>ForIn/OfHeadEvaluation ( )</h1>
Expand All @@ -365,7 +378,7 @@ describe('linting whole program', () => {
<h1>Object.prototype.__defineGetter__ ( )</h1>
</emu-clause>
<emu-clause id="i10">
<h1>_NativeError_ [ @@baz ] ( )</h1>
<h1>_NativeError_ [ %baz% ] ( )</h1>
</emu-clause>
`);
});
Expand Down

0 comments on commit 7990ea3

Please sign in to comment.