From 7db63bb3e8a152c5ad3952bf4b282b84571a7c4d Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Wed, 24 Jan 2024 22:34:45 +0100 Subject: [PATCH 1/2] A failing test for no-deprecated-router-transition-methods This rule incorrectly fails on the following code, where there is more than one Route class in a file: ```js import Route from '@ember/routing/route'; import { action } from '@ember/object'; export class SettingsRoute extends Route { @action foo() { this.transitionTo('login'); } } export class AnotherRoute extends Route { @action foo() { this.transitionTo('login'); } } ``` --- ...no-deprecated-router-transition-methods.js | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tests/lib/rules/no-deprecated-router-transition-methods.js b/tests/lib/rules/no-deprecated-router-transition-methods.js index ff51b524be..4dc44ae3f3 100644 --- a/tests/lib/rules/no-deprecated-router-transition-methods.js +++ b/tests/lib/rules/no-deprecated-router-transition-methods.js @@ -873,5 +873,59 @@ import Controller from '@ember/controller'; }, ], }, + + // Multiple classes in a single file + { + filename: 'routes/index.js', + code: ` + import Route from '@ember/routing/route'; + import { action } from '@ember/object'; + + export class SettingsRoute extends Route { + @action + foo() { + this.transitionTo('login'); + } + } + + export class AnotherRoute extends Route { + @action + foo() { + this.transitionTo('login'); + } + }`, + output: ` + import { inject as service } from '@ember/service'; +import Route from '@ember/routing/route'; + import { action } from '@ember/object'; + + export class SettingsRoute extends Route { + @service('router') router; +@action + foo() { + this.router.transitionTo('login'); + } + } + + export class AnotherRoute extends Route { + @service('router') router; +@action + foo() { + this.router.transitionTo('login'); + } + }`, + errors: [ + { + messageId: 'main', + data: { methodUsed: 'transitionTo', desiredMethod: 'transitionTo', moduleType: 'Route' }, + type: 'MemberExpression', + }, + { + messageId: 'main', + data: { methodUsed: 'transitionTo', desiredMethod: 'transitionTo', moduleType: 'Route' }, + type: 'MemberExpression', + }, + ], + }, ], }); From ac38eef0f5b0532e200c93d6a3e9d56036716736 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Wed, 24 Jan 2024 23:12:49 +0100 Subject: [PATCH 2/2] no-implicit-injections --- tests/lib/rules/no-implicit-injections.js | 46 +++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/lib/rules/no-implicit-injections.js b/tests/lib/rules/no-implicit-injections.js index bf85d8e3d4..86669af119 100644 --- a/tests/lib/rules/no-implicit-injections.js +++ b/tests/lib/rules/no-implicit-injections.js @@ -879,5 +879,51 @@ actions: { { messageId: 'main', data: { serviceName: 'flash-messages' }, type: 'MemberExpression' }, ], }, + + // Multiple classes in a single file + { + filename: 'routes/index.js', + code: ` + import Route from '@ember/routing/route'; + import { action } from '@ember/object'; + + export class SettingsRoute extends Route { + @action + foo() { + this.store.find('test'); + } + } + + export class AnotherRoute extends Route { + @action + foo() { + this.store.find('test'); + } + }`, + output: ` + import { inject as service } from '@ember/service'; +import Route from '@ember/routing/route'; + import { action } from '@ember/object'; + + export class SettingsRoute extends Route { + @service('store') store; +@action + foo() { + this.store.find('test'); + } + } + + export class AnotherRoute extends Route { + @service('store') store; +@action + foo() { + this.store.find('test'); + } + }`, + errors: [ + { messageId: 'main', data: { serviceName: 'store' }, type: 'MemberExpression' }, + { messageId: 'main', data: { serviceName: 'store' }, type: 'MemberExpression' }, + ], + }, ], });