Skip to content

Add no-test-this-set-get rule for gjs/gts tests#2816

Open
NullVoxPopuli with Copilot wants to merge 4 commits into
masterfrom
copilot/add-lint-for-this-set-and-get
Open

Add no-test-this-set-get rule for gjs/gts tests#2816
NullVoxPopuli with Copilot wants to merge 4 commits into
masterfrom
copilot/add-lint-for-this-set-and-get

Conversation

Copilot AI commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Per the issue, this.set / this.get / this.setProperties / this.getProperties should be linted against in .gjs/.gts tests, where template-tag scope makes the test context unnecessary.

Changes

  • New rule ember/no-test-this-set-get (lib/rules/no-test-this-set-get.js) — in .gjs/.gts test files (emberUtils.isTestFile + extension check), flags:
    • this.{set,get,setProperties,getProperties}(...) — both the dot-access form and the computed this["set"](...) form.
    • Calls to set / get / setProperties / getProperties when imported from @ember/object, including aliased imports (e.g. import { set as emberSet } from '@ember/object').
  • Opt-in only — the rule is not enabled in any existing config (recommended, recommended-gjs, or recommended-gts), since enabling it would be a breaking/major change. Consumers must opt in explicitly.
  • Tests (tests/lib/rules/no-test-this-set-get.js) — 24 cases covering each method × gjs/gts for the dot-access and computed-access forms, the four imported functions plus an aliased import, and negative cases for .js test files, non-test files, free set(obj, …) calls without an @ember/object import, imports from other modules, unrelated @ember/object imports, and unrelated foo.set(…).
  • Docs — new docs/rules/no-test-this-set-get.md and README rule-table entry.

Example

In a *-test.gjs file:

import { set } from '@ember/object';

// ❌ flagged — `this.set`
test('it renders', async function (assert) {
  this.set('name', 'Zoey');
  await render(<template>{{this.name}}</template>);
});

// ❌ flagged — computed `this["set"]`
test('it renders', function (assert) {
  this['set']('name', 'Zoey');
});

// ❌ flagged — imported `set` from `@ember/object`
test('it sets', function (assert) {
  set(obj, 'name', 'Zoey');
});

// ✅ ok — use template-tag scope
test('it renders', async function (assert) {
  const name = 'Zoey';
  await render(<template>{{name}}</template>);
});

The same code in a *-test.js file is not flagged.

Copilot AI changed the title [WIP] Add new lint for this.set, this, get, this.setProperties Add no-test-this-set-get rule for gjs/gts tests Jun 29, 2026
Copilot AI requested a review from NullVoxPopuli June 29, 2026 15:25
@github-actions

github-actions Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

🏎️ Benchmark Comparison

Benchmark Control (p50) Experiment (p50) Δ
🟢 js small 14.57 ms 14.02 ms -3.8%
🟢 js medium 7.02 ms 6.88 ms -2.1%
🟢 js large 2.84 ms 2.74 ms -3.5%
gjs small 1.10 ms 1.09 ms -1.2%
gjs medium 544.78 µs 545.76 µs +0.2%
gjs large 216.47 µs 216.23 µs -0.1%
gts small 1.09 ms 1.09 ms -0.4%
gts medium 546.76 µs 546.28 µs -0.1%
gts large 217.52 µs 216.10 µs -0.7%

🟢 faster · 🔴 slower · 🟠 slightly slower · ⚪ within 2%

Full mitata output
clk: ~2.75 GHz
cpu: AMD EPYC 9V74 80-Core Processor
runtime: node 24.16.0 (x64-linux)

benchmark                   avg (min … max) p75 / p99    (min … top 1%)
------------------------------------------- -------------------------------
js small (control)            17.14 ms/iter  18.10 ms █ ▅                  
                      (12.23 ms … 31.47 ms)  30.78 ms █ █ ▂▂               
                    (  5.48 mb …  10.58 mb)   7.32 mb █▇█▇██▇▁▇▁▄▁▄▁▄▁▁▄▄▁▄

js small (experiment)         14.69 ms/iter  15.28 ms   █                  
                      (12.67 ms … 20.85 ms)  20.12 ms ▇ █▇▅▂ ▂   ▂         
                    (  6.47 mb …   8.36 mb)   6.91 mb █▇████▇█▁▇▁█▁▁▁▄▁▄▁▁▄

                             ┌                                            ┐
                             ╷ ┌─────────┬─┐                              ╷
          js small (control) ├─┤         │ ├──────────────────────────────┤
                             ╵ └─────────┴─┘                              ╵
                              ╷ ┌──┬┐           ╷
       js small (experiment)  ├─┤  │├───────────┤
                              ╵ └──┴┘           ╵
                             └                                            ┘
                             12.23 ms           21.50 ms           30.78 ms

summary
  js small (experiment)
   1.17x faster than js small (control)

------------------------------------------- -------------------------------
js medium (control)            7.82 ms/iter   8.05 ms █                    
                       (6.67 ms … 13.91 ms)  13.81 ms ██                   
                    (  3.15 mb …   4.37 mb)   3.59 mb ██▆▇▄▃▃▃▂▂▂▂▁▂▂▁▁▂▁▂▂

js medium (experiment)         7.54 ms/iter   7.82 ms █                    
                       (6.46 ms … 14.41 ms)  13.68 ms ██                   
                    (  2.30 mb …   4.75 mb)   3.55 mb ██▆█▇▄▃▃▁▁▁▂▃▂▁▁▁▂▁▁▂

                             ┌                                            ┐
                              ╷┌─────┬─┐                                  ╷
         js medium (control)  ├┤     │ ├──────────────────────────────────┤
                              ╵└─────┴─┘                                  ╵
                             ╷┌─────┬┐                                   ╷
      js medium (experiment) ├┤     │├───────────────────────────────────┤
                             ╵└─────┴┘                                   ╵
                             └                                            ┘
                             6.46 ms           10.13 ms            13.81 ms

summary
  js medium (experiment)
   1.04x faster than js medium (control)

------------------------------------------- -------------------------------
js large (control)             3.37 ms/iter   3.30 ms  █                   
                       (2.39 ms … 10.57 ms)   8.63 ms  █                   
                    (658.09 kb …   3.41 mb)   1.47 mb ▃██▃▃▂▃▁▁▁▁▂▁▁▁▁▁▁▁▂▁

js large (experiment)          3.05 ms/iter   2.87 ms  █                   
                        (2.51 ms … 7.43 ms)   6.08 ms  █                   
                    ( 55.65 kb …   3.05 mb)   1.45 mb ▆█▇▂▃▂▂▂▂▂▁▁▂▁▁▁▁▁▂▁▁

                             ┌                                            ┐
                             ╷  ┌───┬                                     ╷
          js large (control) ├──┤   │─────────────────────────────────────┤
                             ╵  └───┴                                     ╵
                              ╷┌──┬                     ╷
       js large (experiment)  ├┤  │─────────────────────┤
                              ╵└──┴                     ╵
                             └                                            ┘
                             2.39 ms            5.51 ms             8.63 ms

summary
  js large (experiment)
   1.1x faster than js large (control)

------------------------------------------- -------------------------------
gjs small (control)            1.21 ms/iter   1.13 ms █                    
                        (1.07 ms … 5.94 ms)   5.07 ms █                    
                    (244.76 kb …   1.63 mb)   1.06 mb █▃▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁

gjs small (experiment)         1.19 ms/iter   1.10 ms █                    
                        (1.06 ms … 5.64 ms)   4.82 ms █                    
                    (231.98 kb …   1.79 mb)   1.06 mb █▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁

                             ┌                                            ┐
                             ┌─┬                                          ╷
         gjs small (control) │ │──────────────────────────────────────────┤
                             └─┴                                          ╵
                             ┌┬                                        ╷
      gjs small (experiment) ││────────────────────────────────────────┤
                             └┴                                        ╵
                             └                                            ┘
                             1.06 ms            3.07 ms             5.07 ms

summary
  gjs small (experiment)
   1.02x faster than gjs small (control)

------------------------------------------- -------------------------------
gjs medium (control)         592.28 µs/iter 552.01 µs █                    
                      (527.55 µs … 5.00 ms)   2.71 ms █                    
                    (  8.00 kb …   1.17 mb) 541.57 kb █▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁

gjs medium (experiment)      655.21 µs/iter 558.91 µs █                    
                      (527.25 µs … 6.43 ms)   3.32 ms █                    
                    ( 98.68 kb …   1.10 mb) 541.72 kb █▁▁▂▃▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁

                             ┌                                            ┐
                             ┌┬                                 ╷
        gjs medium (control) ││─────────────────────────────────┤
                             └┴                                 ╵
                             ┌─┬                                          ╷
     gjs medium (experiment) │ │──────────────────────────────────────────┤
                             └─┴                                          ╵
                             └                                            ┘
                             527.25 µs           1.93 ms            3.32 ms

summary
  gjs medium (control)
   1.11x faster than gjs medium (experiment)

------------------------------------------- -------------------------------
gjs large (control)          238.29 µs/iter 224.01 µs  █                   
                      (210.11 µs … 4.67 ms) 351.92 µs  █                   
                    (136.05 kb …   1.07 mb) 217.17 kb ███▅▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁

gjs large (experiment)       235.90 µs/iter 221.79 µs  █                   
                      (209.82 µs … 4.60 ms) 289.15 µs  ██                  
                    (125.56 kb … 965.98 kb) 216.50 kb ▅██▄▆▅▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁

                             ┌                                            ┐
                             ╷┌───────┬                                   ╷
         gjs large (control) ├┤       │───────────────────────────────────┤
                             ╵└───────┴                                   ╵
                             ╷┌──────┬                ╷
      gjs large (experiment) ├┤      │────────────────┤
                             ╵└──────┴                ╵
                             └                                            ┘
                             209.82 µs         280.87 µs          351.92 µs

summary
  gjs large (experiment)
   1.01x faster than gjs large (control)

------------------------------------------- -------------------------------
gts small (control)            1.18 ms/iter   1.10 ms █                    
                        (1.07 ms … 6.34 ms)   5.23 ms █                    
                    (222.60 kb …   1.78 mb)   1.06 mb █▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁

gts small (experiment)         1.18 ms/iter   1.10 ms █                    
                        (1.07 ms … 6.05 ms)   5.10 ms █                    
                    (244.33 kb …   1.60 mb)   1.05 mb █▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁

                             ┌                                            ┐
                             ┌┬                                           ╷
         gts small (control) ││───────────────────────────────────────────┤
                             └┴                                           ╵
                             ┌┬                                          ╷
      gts small (experiment) ││──────────────────────────────────────────┤
                             └┴                                          ╵
                             └                                            ┘
                             1.07 ms            3.15 ms             5.23 ms

summary
  gts small (experiment)
   1x faster than gts small (control)

------------------------------------------- -------------------------------
gts medium (control)         588.83 µs/iter 553.54 µs █                    
                      (530.03 µs … 4.97 ms)   1.66 ms █                    
                    ( 98.66 kb …   1.04 mb) 541.24 kb █▄▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁

gts medium (experiment)      595.37 µs/iter 553.87 µs █                    
                      (529.50 µs … 4.73 ms)   1.48 ms █                    
                    ( 61.12 kb …   1.20 mb) 540.89 kb ██▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁

                             ┌                                            ┐
                             ┌─┬                                          ╷
        gts medium (control) │ │──────────────────────────────────────────┤
                             └─┴                                          ╵
                             ┌──┬                                  ╷
     gts medium (experiment) │  │──────────────────────────────────┤
                             └──┴                                  ╵
                             └                                            ┘
                             529.50 µs           1.09 ms            1.66 ms

summary
  gts medium (control)
   1.01x faster than gts medium (experiment)

------------------------------------------- -------------------------------
gts large (control)          237.31 µs/iter 224.18 µs  █▂                  
                      (211.37 µs … 4.72 ms) 274.16 µs  ██                  
                    (216.09 kb … 802.33 kb) 216.73 kb ▄███▅█▅▃▁▁▁▁▁▁▁▁▁▁▁▁▁

gts large (experiment)       239.15 µs/iter 222.71 µs  █▄                  
                      (209.69 µs … 5.40 ms) 275.70 µs  ██▂                 
                    (183.80 kb …   1.10 mb) 216.97 kb ▃███▅█▅▃▁▂▁▁▁▁▁▁▁▁▁▁▁

                             ┌                                            ┐
                              ╷  ┌──────────────┬                        ╷
         gts large (control)  ├──┤              │────────────────────────┤
                              ╵  └──────────────┴                        ╵
                             ╷  ┌────────────────┬                        ╷
      gts large (experiment) ├──┤                │────────────────────────┤
                             ╵  └────────────────┴                        ╵
                             └                                            ┘
                             209.69 µs         242.70 µs          275.70 µs

summary
  gts large (control)
   1.01x faster than gts large (experiment)

Comment thread tests/lib/rules/no-test-this-set-get.js Outdated
filename: TEST_FILE_NAME_GJS,
code: 'test("x", function () { this.owner.lookup("foo"); });',
},
// Not flagged for free `set`/`get`/`setProperties`/`getProperties` calls.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot we should also flag these if they are imported

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call — done in 1bbeec1. The rule now tracks imports of set/get/setProperties/getProperties from @ember/object (including aliased imports like import { set as emberSet } from '@ember/object') and flags calls to the local name.

Comment thread tests/lib/rules/no-test-this-set-get.js Outdated
// Not flagged for computed `this[...]`.
{
filename: TEST_FILE_NAME_GJS,
code: 'test("x", function () { this["set"]("foo", 1); });',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot we should also flag this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 1bbeec1 — the computed this["set"](...) form (and the other three method names) is now flagged alongside the dot-access form.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot do not change the existing configs.... that's a breaking / major change

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted in 94ba169 — flipped recommendedGjs/recommendedGts to false, regenerated recommended-rules-{gjs,gts}.js, README, doc header, and the recommended-config snapshot. The new rule is now opt-in only and the existing configs are unchanged.

Copilot AI requested a review from NullVoxPopuli June 30, 2026 04:16
@NullVoxPopuli NullVoxPopuli marked this pull request as ready for review July 2, 2026 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants