Skip to content

Autofix bugs in no-get, no-array-prototype-extensions (invoke), template-attribute-order, template-require-button-type, and template-link-rel-noopener #2889

Closed

Description

@trackoor

Several autofixers produce unparseable output, fail to converge, or change runtime semantics when eslint --fix runs:

  1. ember/no-get (enabled in recommended): convertLiteralTypePath in lib/rules/no-get.js rewrites firstObject and lastObject with substring/prefix replacements (replaceAll('.firstObject', ...), replaceAll('lastObject', 'at(-1)'), /\??\.lastObject/) instead of matching whole path segments, so valid identifier segments like firstObjectId, lastObjectId, or x_lastObject are 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``).
  2. ember/no-array-prototype-extensions: invoke(name, ...args) invokes the method with each item as this (see the Ember deprecation guide), whereas the fixer emits map(item => get(item, name)?.(...args)), calling the extracted function with this === undefined.
  3. ember/template-attribute-order: ...attributes is parsed as a GlimmerAttrNode whose range includes trailing whitespace, and is not excluded from sorting. Swapping moves ...attributes to the end (changing Ember attribute override precedence) and drops separating whitespace (<div class={{this.cls}}...attributes >, a Glimmer parse error).
  4. ember/template-require-button-type (enabled in template-lint-migration): /^<button\s*\/>/ only matches attribute-less <button/>; on self-closing buttons with attributes (<button class="a" />), /^<button[^>]*/ includes / and inserts type after it (<button class="a" / type="button">).
  5. ember/template-link-rel-noopener (enabled in template-lint-migration): when rel has a dynamic value (rel={{this.rel}}), relAttr.value.type is not GlimmerTextNode, so the else branch inserts another rel="noopener noreferrer" on each of ESLint's 10 fix passes instead of skipping autofix like ember-template-lint's isFixable. 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.mjs

Actual

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")) (or get(item, "greet")?.call(item, "Hi")), instead of calling get(item, "greet") unbound (TypeError whenever greet accesses this).
  • 2a-2f: match firstObject and lastObject only 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 when rel is dynamic.

Versions

  • eslint-plugin-ember: 13.10.1 and master (b94681e)
  • ember-eslint-parser: 0.16.1
  • eslint: 10.15.0
  • Node.js: v26.13.0

Credit: https://ucsbplse.github.io/

Activity

  1. NullVoxPopuli commented on Nov 16, 2026

    @NullVoxPopuli
    Contributor

    want to have a go at a fix? <3

  2. jjohnnystwsss commented on Nov 19, 2026

    @jjohnnystwsss
    Contributor

    Hi @NullVoxPopuli, since there hasn't been a reply from the reporter, I'd like to take items 4 and 5 (template-require-button-type and template-link-rel-noopener): insert the attribute before /> on self-closing elements, and skip the autofix when rel has a dynamic value, like ember-template-lint's isFixable. I noticed #2770 also touches template-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.

  3. jjohnnystwsss commented on Nov 19, 2026

    @jjohnnystwsss
    Contributor

    Thanks for merging #2895 (items 4 and 5)! I'll pick up items 1–3 next (no-get, no-array-prototype-extensions invoke, template-attribute-order), one small PR per rule, unless someone else is already on them.

  4. jjohnnystwsss commented on Nov 20, 2026

    @jjohnnystwsss
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions