Skip to content

Won't transform class with actions hash #536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
DArrigoni opened this issue Jun 20, 2023 · 4 comments
Open

Won't transform class with actions hash #536

DArrigoni opened this issue Jun 20, 2023 · 4 comments

Comments

@DArrigoni
Copy link

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
Copy link
Author

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

@patocallaghan
Copy link
Contributor

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
Copy link
Contributor

patocallaghan commented Jul 17, 2023

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

@gitKrystan
Copy link
Collaborator

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants