airbnb / airbnb/javascript

Question about new `new-cap` rule

Open
#1,106 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
148k
Forks
26.6k
PR merge metrics
No merged PRs in 30d

Description

- Original discussion: https://github.com/airbnb/javascript/issues/1089#issuecomment-249409943
- Patch: https://github.com/airbnb/javascript/pull/1090

---

I don't want to bikeshed on this, but I do have some concerns about this rule change I'd like to bring up.

My biggest concern is that it will lead to more people overriding the `new-cap` rule than in the past because this new rule is so limited in scope. This would be the opposite of the intended outcome of #1089.
- This rule creates exceptions for `Immutable.{Map,Set,List}`
- The Immutable API contains _many_ more types (Record, Seq, Collection, OrderedMap, etc)

The result is that eslint will tell people to use `new` for `new Immutable.Record()` AND to NOT use `new` for `Immutable.Map()`. The only way to make this consistent is to override the rule in your local environment, and this will be incredibly common.

My suggestion is to either:
- revert the rule change
- re-implement the rule to use [`capIsNewExceptionPattern`](http://eslint.org/docs/rules/new-cap#capisnewexceptionpattern) instead of `capIsNewExceptions` in order to target the entire Immutable.js API with a regular expression.

If this interests you I'm happy to submit a patch for either choice.

Contributor guide

No contributing guide indexed for this repository

Research direction

Read the original discussion and linked patch first, then review ESLint's new-cap documentation for capIsNewExceptionPattern and capIsNewExceptions. Decide whether the change should be reverted or generalized to cover the Immutable.js API consistently; done means the chosen behavior is clear for Map, Set, List, Record, Seq, Collection, and related types.

Written by the indexing model from the issue text.

Assessment

Tech stack
eslint, javascript
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.