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

Add wildcard support to new-cap: capIsNewExceptions #5187

Closed
SimonSchick opened this issue Feb 8, 2016 · 27 comments
Closed

Add wildcard support to new-cap: capIsNewExceptions #5187

SimonSchick opened this issue Feb 8, 2016 · 27 comments
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 good first issue Good for people who haven't worked on ESLint before help wanted The team would welcome a contribution from the community for this issue rule Relates to ESLint's core rules

Comments

@SimonSchick
Copy link
Contributor

In some cases it would be nice to be able to specify to ignore a whole library for instance.

I ran into this problem when using sequelize types.

eg.

        type: {
            type: Sequelize.ENUM('something'), // <- error here
            allowNull: false,
        },
@eslintbot
Copy link

@SimonSchick 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 Feb 8, 2016
@nzakas
Copy link
Member

nzakas commented Feb 8, 2016

There's not enough information here to know how to respond. Please either add more details to the problem you're reporting or more details to the proposal you're making.

@btmills btmills added the needs info Not enough information has been provided to triage this issue label Feb 15, 2016
@eslintbot
Copy link

Hi @SimonSchick, thanks for the issue. It looks like there's not enough information for us to know how to help you. 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.

If it's something else, please just provide as much additional information as possible. Thanks!

@SimonSchick
Copy link
Contributor Author

Sorry, I wrote this in a hurry.

What I want to request is something like this:

/*eslint new-cap: [2, {"capIsNewExceptions": ["someLibraryWithUppercaseFunctions.*"]}]*/

So you don't have to whitelist all function separately.

@thedark1337
Copy link

I also run into this issue whilst using Sequelize with the rule.

In my .eslintrc.json I have to list specifically the items I want to whitelist. Such as

        "new-cap": [2, {
            "capIsNewExceptions": [
                "dataTypes.ENUM",
                "dataTypes.INTEGER",
                "dataTypes.ARRAY",
                "dataTypes.STRING"
            ]
        }]

I think it would be much better if wildcard support was added so it could turn into something like:

        "new-cap": [2, {
            "capIsNewExceptions": [
                "dataTypes.*"
            ]
        }]

@ilyavolodin ilyavolodin 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 needs info Not enough information has been provided to triage this issue triage An ESLint team member will look at this issue soon labels Feb 15, 2016
@nzakas
Copy link
Member

nzakas commented Feb 16, 2016

Seems reasonable. We would need to stick to just * representing a wildcard, but that's feasible. @SimonSchick @thedark1337 can one of you submit a pull request?

@nzakas nzakas added good first issue Good for people who haven't worked on ESLint before accepted There is consensus among the team that this change meets the criteria for inclusion help wanted The team would welcome a contribution from the community for this issue and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Feb 16, 2016
@SimonSchick
Copy link
Contributor Author

I might, just a little low on time right now.

Is there any simple pattern matching utility included in the code base?

@thedark1337
Copy link

I might be able to. I think using glob would help with this (which is included in ESLint) , I'll take a look and see

@SimonSchick
Copy link
Contributor Author

I think minimatch is ok since it's already a sub dependency via glob.

@thedark1337
Copy link

imo using a dependency is better than relying on its sub. I'll start working on it as soon as I get the time 👍 , actually wait, does glob even work for this case? Maybe just using a regex would work better?

@nzakas
Copy link
Member

nzakas commented Feb 17, 2016

You just need to create a regex. Replace * with .* and escape the rest.

@thedark1337
Copy link

Sorry, @SimonSchick are you able to work on this? I haven't started yet on adding it in.

@diki
Copy link
Contributor

diki commented Mar 6, 2016

I sent a pull request

#5484

diki added a commit to diki/eslint that referenced this issue Mar 6, 2016
diki added a commit to diki/eslint that referenced this issue Mar 6, 2016
diki added a commit to diki/eslint that referenced this issue Mar 7, 2016
@nzakas
Copy link
Member

nzakas commented Mar 9, 2016

On the PR, a proposal was made for having full regular expression support and using a different option newIsCapWildcardExceptions.

I'm not sure I like the additional complexity, wheras the initial proposal was fairly simple. What do others think?

@ljharb
Copy link
Sponsor Contributor

ljharb commented Mar 9, 2016

My concern is overloading "a string property name" with "also maybe a wildcard" - it feels very much like repeating some of the language mistakes where it takes both a string and a regex.

Note that Foo.* alone would be not so bad, since that couldn't conflict with any property name, but if Foo* is allowed, I think it'd need to be a separate option.

@BYK
Copy link
Member

BYK commented Mar 9, 2016

I'm +1 for a separate name with RegEx support. We support regexes for identifier names in other places too.

@diki
Copy link
Contributor

diki commented Mar 9, 2016

I think adding "Immutable.*" to existing options kind of violates plugin schema as it looks like regex, also that may create an impression like i can put any regex here.

@nzakas
Copy link
Member

nzakas commented Mar 10, 2016

So what are we proposing here? capIsNewExceptionPatterns and newIsCapExceptionPatterns that are both arrays of regular expressions?

@BYK
Copy link
Member

BYK commented Mar 10, 2016

So what are we proposing here? capIsNewExceptionPatterns and newIsCapExceptionPatterns that are both arrays of regular expressions?

Almost that but not sure if they should be array. I think we can cover all cases with a single RegExp. If we have multiple patterns, we can always combine them using | right?

@ljharb
Copy link
Sponsor Contributor

ljharb commented Mar 10, 2016

I think either an array or a single pattern would work well - an array has the advantage that it's harder to cause a bug in the regex when adding or removing a pattern tho.

@BYK
Copy link
Member

BYK commented Mar 10, 2016

@ljharb supporting an array of regexes would be harder and less performant I think, that's why I resist a bit.

@ljharb
Copy link
Sponsor Contributor

ljharb commented Mar 10, 2016

Why would an array of strings that's .forEach'd be any harder than a single string?

@ljharb
Copy link
Sponsor Contributor

ljharb commented Mar 10, 2016

As for performance, certainly internally it could be concat'd to a single pipe-delimited string in the array case.

@BYK
Copy link
Member

BYK commented Mar 10, 2016

That would work. Still unsure. Gonna defer to @eslint/eslint-team

@nzakas
Copy link
Member

nzakas commented Mar 10, 2016

Looks like we use one string for the id-match rule, so we should probably follow that convention.

@ljharb
Copy link
Sponsor Contributor

ljharb commented Mar 10, 2016

consistency wins, fair enough

@annie
Copy link
Contributor

annie commented Jul 25, 2016

i can continue work on this since that PR was never merged!

annie added a commit to annie/eslint that referenced this issue Aug 11, 2016
annie added a commit to annie/eslint that referenced this issue Aug 11, 2016
annie added a commit to annie/eslint that referenced this issue Aug 11, 2016
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 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 6, 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 enhancement This change enhances an existing feature of ESLint good first issue Good for people who haven't worked on ESLint before help wanted The team would welcome a contribution from the community for this issue rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests

10 participants