Allow exceptions to be added to camelcase
See original GitHub issueWhat 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>;
}
}
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.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:24
- Comments:10 (7 by maintainers)
Top GitHub Comments
I think it’s a good idea. I would suggest changing
exceptions
toallow
for better clarity, but otherwise, 👍 .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: