Repository navigation
Closed
Description
Several autofixers produce unparseable output, fail to converge, or change runtime semantics when eslint --fix runs:
ember/no-get(enabled inrecommended):convertLiteralTypePathinlib/rules/no-get.jsrewritesfirstObjectandlastObjectwith substring/prefix replacements (replaceAll('.firstObject', ...),replaceAll('lastObject', 'at(-1)'),/\??\.lastObject/) instead of matching whole path segments, so valid identifier segments likefirstObjectId,lastObjectId, orx_lastObjectare corrupted into syntax errors or method calls (this.x_at(-1)). Leading-zero numeric segments also emit octal literals (this.a[01]), and tagged template receivers with optional chaining lose required parentheses (this.a?.btpl``).ember/no-array-prototype-extensions:invoke(name, ...args)invokes the method with each item asthis(see the Ember deprecation guide), whereas the fixer emitsmap(item => get(item, name)?.(...args)), calling the extracted function withthis === undefined.ember/template-attribute-order:...attributesis parsed as aGlimmerAttrNodewhoserangeincludes trailing whitespace, and is not excluded from sorting. Swapping moves...attributesto the end (changing Ember attribute override precedence) and drops separating whitespace (<div class={{this.cls}}...attributes >, a Glimmer parse error).ember/template-require-button-type(enabled intemplate-lint-migration):/^<button\s*\/>/only matches attribute-less<button/>; on self-closing buttons with attributes (<button class="a" />),/^<button[^>]*/includes/and insertstypeafter it (<button class="a" / type="button">).ember/template-link-rel-noopener(enabled intemplate-lint-migration): whenrelhas a dynamic value (rel={{this.rel}}),relAttr.value.typeis notGlimmerTextNode, so theelsebranch inserts anotherrel="noopener noreferrer"on each of ESLint's 10 fix passes instead of skipping autofix likeember-template-lint'sisFixable. On self-closing<a href="x" target="_blank" />,/^<a[^>]*/also inserts after/.
Reproduction
repro.mjs:
import { Linter } from "eslint";
import ember from "eslint-plugin-ember";
import * as hbsParser from "ember-eslint-parser/hbs";
const linter = new Linter({ configType: "flat" });
function fixJs(rule, code, options = []) {
const res = linter.verifyAndFix(code, [
{
plugins: { ember },
rules: { [rule]: ["error", ...options] },
languageOptions: { ecmaVersion: "latest", sourceType: "module" },
},
]);
return { output: res.output, errors: res.messages.map((m) => m.message) };
}
function fixHbs(rule, code) {
const res = linter.verifyAndFix(
code,
[
{
files: ["**/*.hbs"],
plugins: { ember },
languageOptions: { parser: hbsParser },
rules: { [rule]: "error" },
},
],
{ filename: "test.hbs" }
);
return {
output: res.output,
errors: res.messages.map((m) => m.message.split("\n")[0]),
};
}
console.log("1:", fixJs("ember/no-array-prototype-extensions", `people.invoke("greet", "Hi");`));
console.log("2a:", fixJs("ember/no-get", `this.get("items.firstObjectId").x;`));
console.log("2b:", fixJs("ember/no-get", `this.get("items.lastObjectId").x;`));
console.log("2c:", fixJs("ember/no-get", `this.get("items.lastObjectId");`, [{ useOptionalChaining: true }]));
console.log("2d:", fixJs("ember/no-get", `this.get("x_lastObject");`, [{ useOptionalChaining: true }]));
console.log("2e:", fixJs("ember/no-get", `this.get("a.01").x;`));
console.log("2f:", fixJs("ember/no-get", "this.get(\"a.b\")`tpl`;", [{ useOptionalChaining: true }]));
console.log("3a:", fixHbs("ember/template-attribute-order", `<div ...attributes class={{this.cls}}>x</div>`));
console.log("3b:", fixHbs("ember/template-attribute-order", `<input ...attributes type="text" />`));
console.log("4:", fixHbs("ember/template-require-button-type", `<button class="a" />`));
console.log("5a:", fixHbs("ember/template-link-rel-noopener", `<a href="x" target="_blank" rel={{this.rel}}>l</a>`));
console.log("5b:", fixHbs("ember/template-link-rel-noopener", `<a href="x" target="_blank" />`));Run:
npm i eslint@10.15.0 eslint-plugin-ember@13.10.1 ember-eslint-parser@0.16.1
node repro.mjsActual
1: {
output: "import { get } from '@ember/object';\n" +
'people.map(item => get(item, "greet")?.("Hi"));',
errors: []
}
2a: {
output: 'this.items[0]Id.x;',
errors: [ 'Parsing error: Unexpected token Id' ]
}
2b: {
output: 'this.items[this.items.length - 1]Id.x;',
errors: [ 'Parsing error: Unexpected token Id' ]
}
2c: {
output: 'this.items?.at(-1)Id;',
errors: [ 'Parsing error: Unexpected token Id' ]
}
2d: { output: 'this.x_at(-1);', errors: [] }
2e: {
output: 'this.a[01].x;',
errors: [ 'Parsing error: Invalid number' ]
}
2f: {
output: 'this.a?.b`tpl`;',
errors: [
'Parsing error: Optional chaining cannot appear in the tag of tagged template expressions'
]
}
3a: {
output: '<div class={{this.cls}}...attributes >x</div>',
errors: [
"Parsing error: An unquoted attribute value must be a string or a mustache, preceded by whitespace or a '=' character, and followed by whitespace, a '>' character, or '/>': "
]
}
3b: { output: '<input type="text"...attributes />', errors: [] }
4: {
output: '<button class="a" / type="button">',
errors: [ 'Parsing error: Unclosed element `button`: ' ]
}
5a: {
output: '<a href="x" target="_blank" rel={{this.rel}} rel="noopener noreferrer" rel="noopener noreferrer" rel="noopener noreferrer" rel="noopener noreferrer" rel="noopener noreferrer" rel="noopener noreferrer" rel="noopener noreferrer" rel="noopener noreferrer" rel="noopener noreferrer" rel="noopener noreferrer">l</a>',
errors: [ 'links with target="_blank" must have rel="noopener noreferrer"' ]
}
5b: {
output: '<a href="x" target="_blank" / rel="noopener noreferrer">',
errors: [ 'Parsing error: Unclosed element `a`: ' ]
}
(Cases 3a through 5b produce the same template output in .gjs/.gts files with ember-eslint-parser.)
Expected
1: preserve the method receiver, e.g.people.map(item => item.greet?.("Hi"))(orget(item, "greet")?.call(item, "Hi")), instead of callingget(item, "greet")unbound (TypeErrorwhenevergreetaccessesthis).2a-2f: matchfirstObjectandlastObjectonly as full dot-separated segments (this.items.firstObjectId.x,this.items?.lastObjectId,this.x_lastObject), use['01']for leading-zero digit segments, and parenthesize(this.a?.b)before a template literal tag.3a-3b: do not reorder attributes across...attributes, and preserve separating whitespace when swapping attributes.4,5b: insert the new attribute before/>on self-closing elements (<button class="a" type="button" />,<a href="x" target="_blank" rel="noopener noreferrer" />).5a: report without autofixing whenrelis dynamic.
Versions
eslint-plugin-ember:13.10.1andmaster(b94681e)ember-eslint-parser:0.16.1eslint:10.15.0- Node.js:
v26.13.0
Credit: https://ucsbplse.github.io/
Metadata
Metadata
Assignees
Labels
No labels
Activity
NullVoxPopuli commentedon Nov 16, 2026
want to have a go at a fix? <3
jjohnnystwsss commentedon Nov 19, 2026
Hi @NullVoxPopuli, since there hasn't been a reply from the reporter, I'd like to take items 4 and 5 (
template-require-button-typeandtemplate-link-rel-noopener): insert the attribute before/>on self-closing elements, and skip the autofix whenrelhas a dynamic value, likeember-template-lint'sisFixable. I noticed #2770 also touchestemplate-link-rel-noopener, so I'll keep the change small to stay out of its way. I'll open a PR for those two shortly.Fix self-closing and dynamic `rel` autofixes in `template-require-but…
jjohnnystwsss commentedon Nov 19, 2026
Thanks for merging #2895 (items 4 and 5)! I'll pick up items 1–3 next (
no-get,no-array-prototype-extensionsinvoke,template-attribute-order), one small PR per rule, unless someone else is already on them.Keep `...attributes` in place and keep whitespace in `template-attrib…
Call the method on each item in the `invoke` autofix of `no-array-pro…
Fix `no-get` autofixes for `firstObject`/`lastObject`-like names, lea…
jjohnnystwsss commentedon Nov 20, 2026
Thanks @NullVoxPopuli for the quick reviews! All five items from this issue are now fixed: 4 and 5 in #2895, and 1, 2 and 3 in #2897, #2898 and #2899. I think this can be closed.