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

id-match bug incorrectly errors on NewExpression #4042

Closed
nickInMN opened this issue Oct 5, 2015 · 9 comments
Closed

id-match bug incorrectly errors on NewExpression #4042

nickInMN opened this issue Oct 5, 2015 · 9 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 bug ESLint is working incorrectly rule Relates to ESLint's core rules

Comments

@nickInMN
Copy link

nickInMN commented Oct 5, 2015

Am I misunderstanding what this rule is supposed to do? Version 1.1.0 of ESLint.

I have the following line:
var startDate = new Date();

The rule is configured as:
"id-match": [ 2, "^[a-z$]+([A-Z][a-z]+)*$", { "properties": false } ]

The error I am getting is:
32:25 error Identifier 'Date' does not match the pattern '^[a-z$]+([A-Z][a-z]+)*$' id-match

I thought the idea of this rule is define naming conventions for variables and functions. I get the same error if I try: (yes, I know use [] but was simply a test)
var myArray = new Array();

@eslintbot
Copy link

Thanks for the issue! If you're reporting a bug, please be sure to include:

  1. The version of ESLint you are using (run eslint -v)
  2. What you did (the source code and ESLint configuration)
  3. The actual ESLint output complete with numbers
  4. What you expected to happen instead

Requesting a new rule? Please see Proposing a New Rule for instructions.

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Oct 5, 2015
@alberto
Copy link
Member

alberto commented Oct 5, 2015

I think your RegExp is wrong. You should remove the first $

@nickInMN
Copy link
Author

nickInMN commented Oct 5, 2015

I want to allow for $ to start a variable name in the case that it is a jQuery variable.

@BYK
Copy link
Member

BYK commented Oct 5, 2015

Array and Date are identifiers even if they are predefined globals. Your RegEx's first part only allows lower-case letters, that's why the rule is giving you a warning. Are you suggesting the rule should simply ignore globals?

@nickInMN
Copy link
Author

nickInMN commented Oct 5, 2015

I was under the impression that it would only flag the name of the variable I created, I wasn't expecting to to validate the right hand side.

I suppose ignoring globals would be one way, but even then you may run into this issue if using a third party component. I guess I misunderstood the rule in that I was only expecting it to validate the name of the variable I crated. More specifically, I was expecting it to only validate the left hand side.

@BYK
Copy link
Member

BYK commented Oct 5, 2015

@nickInMN - hmm, what you say also makes sense. That's how I constructed my id-length rule. I'd say worth a look.

@BYK BYK added 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 Oct 5, 2015
@BYK
Copy link
Member

BYK commented Oct 5, 2015

Okay, looks like this only happens if you use new since NewExpression is different than CallExpression which the code checks against. can you confirm this and this is what you want? If so I'll mark this as accepted.

@nickInMN
Copy link
Author

nickInMN commented Oct 5, 2015

@BYK - Yes, you are correct. If I remove new from that line ESLint behaves as I would expect and there are no errors.

@BYK
Copy link
Member

BYK commented Oct 6, 2015

@nickInMN - Alright, I'm gonna update the title of your issue then and try to submit a patch soon :)

@BYK BYK added the accepted There is consensus among the team that this change meets the criteria for inclusion label Oct 6, 2015
@BYK BYK changed the title id-match bug? id-match bug incorrectly errors on NewExpression Oct 6, 2015
@BYK BYK self-assigned this Oct 6, 2015
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 7, 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 Feb 7, 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 rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests

4 participants