question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow exceptions to be added to camelcase

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:24
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
nzakascommented, Sep 17, 2018

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

2reactions
AlicanCcommented, 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() {}
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

camelcase - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Disable check of camel case rule in eslint - Stack Overflow
I have a large JavaScript file with multiple eslint rule violations. I am trying to disable them and address them one at a...
Read more >
Pascal case vs. camel case: What's the difference?
Camel case and Pascal case are similar. Both demand variables made from compound words and have the first letter of each appended word ......
Read more >
Pascal Case: under_scores, camelCase and PascalCase
In camel casing, names start with a lower case but each proper word in the name is capitalized and so are acronyms. For...
Read more >
PEP 8 – Style Guide for Python Code
Here, the eye has to do extra work to tell which items are added and ... Exception: when a slice parameter is omitted,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found