ember-native-class-codemod icon indicating copy to clipboard operation
ember-native-class-codemod copied to clipboard

Won't transform class with `actions` hash

Open DArrigoni opened this issue 2 years ago • 4 comments

Ember Objects with objects or arrays as direct properties (actions and queryParams are the exception). See eslint-plugin-ember/avoid-leaking-state-in-ember-objects for more details.

I have a file with an actions hash that is kicking out this error:

2023-06-20T15:50:48.604Z ERROR: [app/controllers/authenticated/customers/index.js]
	RuntimeDataError: Could not find runtime data
2023-06-20T15:50:48.613Z ERROR: [app/controllers/authenticated/customers/index.js]
	ValidationError: Validation errors for class 'Index':
		[actions]: Transform not supported - value is of type object. For more details: eslint-plugin-ember/avoid-leaking-state-in-ember-objects

I'm assuming that the issue is something that fixing the "Could not find runtime data" error would resolve, although it works fine if I remove the actions hash and run it without it.

I'm invoking it with: npx ember-native-class-codemod http://localhost:4202/partner/ app/controllers/authenticated/customers/index.js

And I can verify the app is loaded at http://localhost:4202/partner/

Build successful (2925ms) – Serving on http://localhost:4202/partner/

Slowest Nodes (totalTime >= 5%)                               | Total (avg)
--------------------------------------------------------------+----------------
AssetRewrite (2)                                              | 1376ms (688 ms)
SassCompiler (1)                                              | 699ms
Packaged Application Javascript (1)                           | 147ms

Any assistance would be greatly appreciated.

DArrigoni avatar Jun 20 '23 15:06 DArrigoni

After some more playing around with it I'm getting inconsistent results with this. Some times it works fine, sometimes it does not.

DArrigoni avatar Jun 20 '23 22:06 DArrigoni

I've just come across the same issue. It seems this is because of the ignoreLeakingState option in the config. This looks like it only supports queryParams by default even though in the README it calls out queryParams and actions.

Ember Objects with objects or arrays as direct properties (actions and queryParams are the exception). See eslint-plugin-ember/avoid-leaking-state-in-ember-objects for more details.

Adding actions to ignoreLeakingState options does go a step further and do a migration but in my testing it looks like it translates to actions = { ... }

@gitKrystan should actions be added as a default option in ignoreLeakingState?

patocallaghan avatar Jul 17 '23 14:07 patocallaghan

Did a bit more digging and it seems the codemod supports actions using ObjectMethod notation but not FunctionExpression.

Works

actions: {
  foo() {}
}

Doesn't work

actions: {
  foo: function() {}
}

I'll see about putting together a PR

Edit: hmm weirdly i can't replicate this behaviour in the tests

patocallaghan avatar Jul 17 '23 15:07 patocallaghan

IIRC adding something to ignoreLeakingState means it won't be transformed from an object literal. The actions hash is special-cased, as you found.

Are you seeing anything about this file in codemods.log?

gitKrystan avatar Jul 20 '23 17:07 gitKrystan