Skip to content

Commit 6e6037e

Browse files
committed
fix: sourceCode fallback + name-based scope-ref compare + soften size assertion (Copilot review)
1 parent 2faeef5 commit 6e6037e

4 files changed

Lines changed: 17 additions & 6 deletions

File tree

lib/rules/template-no-empty-headings.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ module.exports = {
9797
},
9898
},
9999
create(context) {
100-
const sourceCode = context.sourceCode;
100+
// `context.sourceCode` is the ESLint >= 8.40 shape; `context.getSourceCode()`
101+
// covers older versions. Keep both for cross-version compatibility.
102+
const sourceCode = context.sourceCode || context.getSourceCode();
101103
return {
102104
GlimmerElementNode(node) {
103105
if (isHeadingElement(node)) {

lib/rules/template-no-invalid-interactive.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ module.exports = {
6767
},
6868

6969
create(context) {
70-
const sourceCode = context.sourceCode;
70+
// `context.sourceCode` is the ESLint >= 8.40 shape; `context.getSourceCode()`
71+
// covers older versions. Keep both for cross-version compatibility.
72+
const sourceCode = context.sourceCode || context.getSourceCode();
7173
const options = context.options[0] || {};
7274
const additionalInteractiveTags = new Set(options.additionalInteractiveTags || []);
7375
const ignoredTags = new Set(options.ignoredTags || []);

lib/utils/is-native-element.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ function isNativeElement(node, sourceCode) {
6060
}
6161
const scope = sourceCode.getScope(node.parent);
6262
const firstPart = node.parts && node.parts[0];
63-
if (firstPart && scope.references.some((ref) => ref.identifier === firstPart)) {
63+
// Compare by identifier name rather than AST node object identity — object
64+
// identity isn't guaranteed across parser versions (ember-eslint-parser can
65+
// produce distinct node objects for the same token depending on how the
66+
// scope manager walks the tree), but the resolved `.name` is stable.
67+
if (firstPart && scope.references.some((ref) => ref.identifier?.name === firstPart?.name)) {
6468
return false;
6569
}
6670
return true;

tests/lib/utils/is-native-element-test.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,12 @@ describe('isNativeElement — list-only behavior (no sourceCode)', () => {
8181

8282
describe('ELEMENT_TAGS', () => {
8383
it('includes all HTML, SVG, and MathML tag names', () => {
84-
// Sanity check — if this ever drops below a reasonable size, one of the
85-
// underlying packages has changed contract.
86-
expect(ELEMENT_TAGS.size).toBeGreaterThan(200);
84+
// Contract check — the set must be non-empty and must contain at least
85+
// one representative tag from each of the three source packages. An exact
86+
// size assertion would be brittle (the underlying packages add/remove tags
87+
// across minor releases without changing their contract), so we assert the
88+
// shape instead.
89+
expect(ELEMENT_TAGS.size).toBeGreaterThan(0);
8790
expect(ELEMENT_TAGS.has('div')).toBe(true);
8891
expect(ELEMENT_TAGS.has('circle')).toBe(true);
8992
expect(ELEMENT_TAGS.has('mfrac')).toBe(true);

0 commit comments

Comments
 (0)