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

Allow exceptions to be added to camelcase #10503

Closed
smably opened this issue Jun 22, 2018 · 10 comments
Closed

Allow exceptions to be added to camelcase #10503

smably opened this issue Jun 22, 2018 · 10 comments
Assignees
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules

Comments

@smably
Copy link
Contributor

smably commented Jun 22, 2018

What rule do you want to change?
camelcase

Does this change cause the rule to produce more or fewer warnings?
Fewer (if the exceptions option is used).

How will the change be implemented? (New option, new default behavior, etc.)?
New option, something like:

"camelcase": ['error', {
  "exceptions": [
    "UNSAFE_componentDidMount",
    "UNSAFE_componentWillReceiveProps",
    "UNSAFE_componentWillUpdate"
  ]
}]

Please provide some example code that this change will affect:

import React from 'react';

class UnsafeComponent extends React.Component {
  UNSAFE_componentWillMount() {
    // deprecated lifecycle code
  }
  render() {
    return <div>FIXME</div>;
  }
}

Demo link

What does the rule currently do for this code?
Errors on UNSAFE_componentWillMount.

What will the rule do after it's changed?
Ignore UNSAFE_componentWillMount even though it's not camelCase.


As React deprecates its legacy lifecycle methods, we're going to see a proliferation of the new UNSAFE_-prefixed lifecycle methods. There's currently no good way to ignore these while enforcing camelCase elsewhere.

id-match is one possible workaround, but it results in an ugly and verbose rule that doesn't clearly describe its intent. Compare the proposed camelcase option above to the equivalent id-match rule:

'id-match': [
  'error',
  '^(UNSAFE_componentDidMount|UNSAFE_componentWillReceiveProps|UNSAFE_componentWillUpdate|[a-z]+([A-Z][a-z]+)*)$'
]

This proposal was previously discussed in #9233 but didn't achieve consensus. I think the new option is worth revisiting in the context of React's new lifecycle methods, as it will be a much more frequent pain point for developers.

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Jun 22, 2018
@platinumazure platinumazure added enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels Jun 22, 2018
@platinumazure
Copy link
Member

Hi @smably, thanks for creating a new issue.

I could get behind either a list of identifiers or a regular expression. (Maybe we could convert an identifier list into a regex behind the scenes?)

@sindresorhus
Copy link
Contributor

I think it should support Array<string|RegExp>. Strings for the common-case, and RegExp for maximum power. In this case, [/UNSAFE_component.*/] would be much easier.

@AlicanC
Copy link

AlicanC commented Jul 13, 2018

Can't "eslint-plugin-react" solve this issue by disabling camelcase for these, just like "eslint-plugin-prettier" disables style rules?

Also disabling camelcase for all usage doesn't solve this issue correctly. These should still be errors:

const UNSAFE_componentDidMount = 13;

function UNSAFE_componentDidMount() {}

class MySomething extends NotReactComponent {
  UNSAFE_componentDidMount() {}
}

@platinumazure
Copy link
Member

I'll champion this.

@eslint/eslint-team Can we review this one? It's pretty popular among the community, allowing the convenience of camelcase while also allowing users to list a small number of exceptions. Hopefully minimal implementation cost.

@platinumazure platinumazure self-assigned this Sep 15, 2018
@nzakas
Copy link
Member

nzakas commented Sep 17, 2018

I think it's a good idea. I would suggest changing exceptions to allow for better clarity, but otherwise, 👍 .

@ilyavolodin ilyavolodin added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Sep 18, 2018
@hjylewis
Copy link

Is someone working on this? I would be happy to take a crack at it.

@platinumazure
Copy link
Member

Hi @hjylewis, thanks for reaching out!

It looks like PR #10783 was independently created before this issue and is not quite following the proposal we eventually accepted here. I think I'll ping in that PR and see if they're willing to make the changes to match this issue; if they're busy/don't reply, then you could take a shot.

@hjylewis
Copy link

@platinumazure Sounds good!

@platinumazure
Copy link
Member

Is this issue resolved with #10783?

@platinumazure
Copy link
Member

I'm going to close this as it seems it should be resolved with #10783. Please feel free to leave a comment if that's not the case. Thanks!

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Apr 12, 2019
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Apr 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests

7 participants