From 1d6aa83f208d90f2a673817fe77e8496e24f16ff Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Wed, 24 Jan 2024 23:04:56 +0100 Subject: [PATCH 1/2] A failing test for no-deprecated-router-transition-methods (legacy class, decorators) This rule incorrectly fails on the following code, where a legacy `.extend` class uses decorators: ```js import Route from '@ember/routing/route'; import { action } from '@ember/object'; export default Route.extend({ @action foo() { this.transitionTo('login'); } }); ``` --- ...no-deprecated-router-transition-methods.js | 35 +++++++++++++++++++ 1 file changed, 35 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..286cd8881b 100644 --- a/tests/lib/rules/no-deprecated-router-transition-methods.js +++ b/tests/lib/rules/no-deprecated-router-transition-methods.js @@ -16,6 +16,7 @@ const ruleTester = new RuleTester({ sourceType: 'module', babelOptions: { configFile: require.resolve('../../../.babelrc'), + plugins: [['@babel/plugin-proposal-decorators', { legacy: true }]], }, }, }); @@ -873,5 +874,39 @@ import Controller from '@ember/controller'; }, ], }, + + // Legacy .extend Route with decorators + { + filename: 'routes/index.js', + code: ` + import Route from '@ember/routing/route'; + import { action } from '@ember/object'; + + export default Route.extend({ + @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 default Route.extend({ + router: service('router'), +@action + foo() { + this.router.transitionTo('login'); + } + });`, + errors: [ + { + messageId: 'main', + data: { methodUsed: 'transitionTo', desiredMethod: 'transitionTo', moduleType: 'Route' }, + type: 'MemberExpression', + }, + ], + }, ], }); From b30b1baadce83941bca8b01715b8688beb801a4c Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Wed, 24 Jan 2024 23:16:27 +0100 Subject: [PATCH 2/2] no-implicit-injections --- tests/lib/rules/no-implicit-injections.js | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/lib/rules/no-implicit-injections.js b/tests/lib/rules/no-implicit-injections.js index bf85d8e3d4..3fdc4d0bfd 100644 --- a/tests/lib/rules/no-implicit-injections.js +++ b/tests/lib/rules/no-implicit-injections.js @@ -16,6 +16,7 @@ const ruleTester = new RuleTester({ sourceType: 'module', babelOptions: { configFile: require.resolve('../../../.babelrc'), + plugins: [['@babel/plugin-proposal-decorators', { legacy: true }]], }, }, }); @@ -879,5 +880,33 @@ actions: { { messageId: 'main', data: { serviceName: 'flash-messages' }, type: 'MemberExpression' }, ], }, + + // Legacy .extend class with decorators + { + filename: 'routes/index.js', + code: ` + import Route from '@ember/routing/route'; + import { action } from '@ember/object'; + + export default Route.extend({ + @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 default Route.extend({ + store: service('store'), +@action + foo() { + this.store.find('test'); + } + });`, + errors: [{ messageId: 'main', data: { serviceName: 'store' }, type: 'MemberExpression' }], + }, ], });