ember-no-implicit-this-codemod icon indicating copy to clipboard operation
ember-no-implicit-this-codemod copied to clipboard

Add support for prefixing `this` only for owned properties

Open suchitadoshi1987 opened this issue 5 years ago • 8 comments

Currently, the no-implicit-this-codemodprefixes the local, as well as the passed in args with this. While the resulting output of the codemod is guaranteed to be valid runable code, this approach would result in extra churn in the template by changing all paths to this.* paths and subsequently require additional cleanup to change any this.* paths to leverage named arguments such as @foo whenever the backing class does not modify the specific property locally.

Instead of always prefixing ambiguous paths with this. the codemod should only modify the paths that are guaranteed to be local properties of the component. Since the lint rule will complain about all the places in the template where there are still occurrences of implicit-this, it would be easier for the developer to manually inspect all unchanged properties and determine if they need to be prefixed with @.

This PR depends on https://github.com/ember-codemods/ember-codemods-telemetry-helpers/pull/28 PR to be merged

Note: this is an optional feature, to enable it, add the prefix-component-properties-only=true flag to your codemod command

suchitadoshi1987 avatar Feb 24 '20 05:02 suchitadoshi1987

The telemetry helpers PR has been merged and released as v1.2.0.

rwjblue avatar Apr 24 '20 16:04 rwjblue

Any update on this PR? This is something we are also running into.

joukevandermaas avatar Jun 30 '20 08:06 joukevandermaas

@rwjblue , could you review the PR whenever you get some time? I ll resolve the merge conflicts until then

suchitadoshi1987 avatar Jun 30 '20 18:06 suchitadoshi1987

@suchitadoshi1987 Can you please fix the conflicts 😄

Alonski avatar Aug 09 '20 06:08 Alonski

Ping @suchitadoshi1987 😸

rwjblue avatar Sep 22 '20 16:09 rwjblue

I installed from this branch, then ran it and got this error;

npx ember-no-implicit-this-codemod http://localhost:4200 .
Cannot find module 'find-package-json'
Require stack:
- /home/user/my-app/node_modules/ember-no-implicit-this-codemod/bin/cli.js

Had to add find-package-json to my dependencies to get it to work. Also tried installing this branch globally with the same problem.

Then I could run it successfully.

At that point I noticed it was prefixing this. to components, exactly as per my comment here https://github.com/ember-codemods/ember-no-implicit-this-codemod/issues/101#issuecomment-820817914

I get that problem with the main branch too so it might just be my use of pods. But I was hoping this branch would avoid that problem because it is supposed to be only prefixing this for owned properties.

Techn1x avatar Apr 16 '21 00:04 Techn1x

Ping! Is this still something we could move forward?

snewcomer avatar Oct 30 '21 03:10 snewcomer

Ping 😢, did you find a way of doing this @snewcomer ?

kexposito avatar Apr 01 '24 17:04 kexposito