Skip to content
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

no-object-mutation does not respect the prefix setting #136

Closed
karol-majewski opened this issue May 10, 2019 · 4 comments
Closed

no-object-mutation does not respect the prefix setting #136

karol-majewski opened this issue May 10, 2019 · 4 comments

Comments

@karol-majewski
Copy link

Hello and thank you for your work.

Context

In React, it's common to assign defaultProps via direct property assignment.

export const Foo: React.FunctionComponent = /* ... */

Foo.defaultProps = {
  name: "Bob",
};

Adding defaults this way make sense for two reasons:

  • Functional composition doesn't work well with generic components in TypeScript
  • TypeScript 3.0 introduced LibraryManagedAttributes that should automagically improve type inference if you assign defaultProps the traditional way

The problem

I used to use this setting:

"no-object-mutation": [true, { "ignore-prefix": ["defaultProps"] }]

And it worked fine — assignment to any property called defaultProps was allowed. However, in tslint-immutable@5.5.2 such an assignment triggers an error.

It's impractical to whitelist every possible component name in your application:

"no-object-mutation": [true, { "ignore-prefix": ["Foo.defaultProps", "Bar.defaultProps"] }]

So respecting the setting (just like it used to be) seems like the way to go.

@RebeccaStevens
Copy link
Collaborator

Thanks for the issue.
I should be able to be able to look into this issue within the next few days (but no promises).

@RebeccaStevens
Copy link
Collaborator

RebeccaStevens commented May 13, 2019

@karol-majewski

I've just had a quick look at this but I haven't been able to reproduce the old behaviour you mention. What version of tslint-immutable were you able use "no-object-mutation": [true, { "ignore-prefix": ["defaultProps"] }] on to get your desired effect?

I don't thing the "ignore-prefix" option was ever setup to allow this.

For now I'm going to remove the bug label and add the enhancement label (as there should be a way to get your desired effect).

@karol-majewski
Copy link
Author

@RebeccaStevens Thank you for taking the time to get back to me.

The bad news is, I don't have access to the original package anymore (tslint-immutable was part of a config used in the company I used to work for). The only thing I know is that assigning to defaultProps was allowed — but if you say it's been always like that, then perhaps we just had turned the rule off. If that's the case, then I apologize for misleading you into thinking it once worked differently.

I would still love to see it as an option though!

@RebeccaStevens
Copy link
Collaborator

Closed via #137

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

No branches or pull requests

2 participants