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

The camelcase rule does not allow leading/trailing underscores for variable names #9700

Closed
KylePDavis opened this issue Dec 8, 2017 · 7 comments · May be fixed by ali8889/emerald-wallet#4, DmytroSkrypnyk/test_bootstrap#6 or ali8889/emerald-wallet#17
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 bug ESLint is working incorrectly patch candidate This issue may necessitate a patch release in the next few days rule Relates to ESLint's core rules

Comments

@KylePDavis
Copy link

Tell us about your environment

  • ESLint Version: v4.13.0
  • Node Version: v8.9.3
  • npm Version: v5.5.1

What parser (default, Babel-ESLint, etc.) are you using?
default

Please show your full configuration:

Configuration
{
    "parserOptions": {
        "ecmaVersion": 8,
        "sourceType": "module",
        "ecmaFeatures": {}
    },
    "rules": {
        "camelcase": 2
    },
    "env": {}
}

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

Contents of test.js:

function shouldAllowUndercoreVars() {
	let { _value } = this;
	return _value;
}
shouldAllowUndercoreVars()

Shell command used:

eslint test.js

This is currently reproducible on the eslint demo site:
https://eslint.org/demo/#eyJ0ZXh0IjoiZnVuY3Rpb24gc2hvdWxkQWxsb3dVbmRlcmNvcmVWYXJzKCkge1xuXHRsZXQgeyBfdmFsdWUgfSA9IHRoaXM7XG5cdHJldHVybiBfdmFsdWU7XG59XG5zaG91bGRBbGxvd1VuZGVyY29yZVZhcnMoKSIsIm9wdGlvbnMiOnsicGFyc2VyT3B0aW9ucyI6eyJlY21hVmVyc2lvbiI6OCwic291cmNlVHlwZSI6Im1vZHVsZSIsImVjbWFGZWF0dXJlcyI6e319LCJydWxlcyI6eyJjYW1lbGNhc2UiOjJ9LCJlbnYiOnt9fX0=

What did you expect to happen?
I would have expected it to allow the variable name based on the camelcase docs docs quoted below:

It ignores leading and trailing underscores and only checks those in the middle of a variable name.

What actually happened? Please include the actual, raw output from ESLint.

/Users/kyle/tmp/test.js
  2:8  error  Identifier '_value' is not in camel case  camelcase

✖ 1 problem (1 error, 0 warnings)
@platinumazure
Copy link
Member

Agreed, this seems to only apply to destructuring however.

No lint errors:

const _value = true;

Has lint errors (incorrectly):

const { _value } = obj;

@KylePDavis Does this occur in 4.12.x for you? Wondering if this was a side-effect of #9468.

@platinumazure platinumazure added accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Dec 9, 2017
@platinumazure platinumazure added the patch candidate This issue may necessitate a patch release in the next few days label Dec 9, 2017
@platinumazure
Copy link
Member

Applying "patch candidate" label because the original change intentionally added more warnings, but the change actually added even more warnings than anticipated.

@guyellis
Copy link
Contributor

guyellis commented Dec 9, 2017

@platinumazure I think you've got this but if you need more info this is a greenkeeper/travis combo showing the fail from 4.12.1 to 4.13.0:
https://travis-ci.org/guyellis/plant/builds/313796790

Your PR LGTM. Is there an easy way for me to test your branch/PR against my repo?

@platinumazure
Copy link
Member

platinumazure commented Dec 9, 2017 via email

@guyellis
Copy link
Contributor

guyellis commented Dec 9, 2017

Thanks @platinumazure
I referenced this in package.json:

"eslint": "git@github.com:eslint/eslint.git#camelcase-destructuring-leading-trailing",

And that fixes the linting in my project. Thanks.

@platinumazure
Copy link
Member

I'm hoping the team agrees that this should justify a patch release; if so, that patch release will probably occur sometime on Monday. Thanks for your patience and thank you also for testing the change!

@KylePDavis
Copy link
Author

Thanks for the speedy response. The fix works great!

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Jun 10, 2018
@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 Jun 10, 2018
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 bug ESLint is working incorrectly patch candidate This issue may necessitate a patch release in the next few days rule Relates to ESLint's core rules
Projects
None yet
3 participants