Add no-test-this-set-get rule for gjs/gts tests#2816
Add no-test-this-set-get rule for gjs/gts tests#2816NullVoxPopuli with Copilot wants to merge 4 commits into
no-test-this-set-get rule for gjs/gts tests#2816Conversation
no-test-this-set-get rule for gjs/gts tests
🏎️ Benchmark Comparison
Full mitata output |
| filename: TEST_FILE_NAME_GJS, | ||
| code: 'test("x", function () { this.owner.lookup("foo"); });', | ||
| }, | ||
| // Not flagged for free `set`/`get`/`setProperties`/`getProperties` calls. |
There was a problem hiding this comment.
@copilot we should also flag these if they are imported
There was a problem hiding this comment.
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.
| // Not flagged for computed `this[...]`. | ||
| { | ||
| filename: TEST_FILE_NAME_GJS, | ||
| code: 'test("x", function () { this["set"]("foo", 1); });', |
There was a problem hiding this comment.
@copilot do not change the existing configs.... that's a breaking / major change
There was a problem hiding this comment.
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.
Per the issue,
this.set/this.get/this.setProperties/this.getPropertiesshould be linted against in.gjs/.gtstests, where template-tag scope makes the test context unnecessary.Changes
ember/no-test-this-set-get(lib/rules/no-test-this-set-get.js) — in.gjs/.gtstest files (emberUtils.isTestFile+ extension check), flags:this.{set,get,setProperties,getProperties}(...)— both the dot-access form and the computedthis["set"](...)form.set/get/setProperties/getPropertieswhen imported from@ember/object, including aliased imports (e.g.import { set as emberSet } from '@ember/object').recommended,recommended-gjs, orrecommended-gts), since enabling it would be a breaking/major change. Consumers must opt in explicitly.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.jstest files, non-test files, freeset(obj, …)calls without an@ember/objectimport, imports from other modules, unrelated@ember/objectimports, and unrelatedfoo.set(…).docs/rules/no-test-this-set-get.mdand README rule-table entry.Example
In a
*-test.gjsfile:The same code in a
*-test.jsfile is not flagged.