Rule request: no-useless-builtin-calls
See original GitHub issuePlease describe what the rule should do:
The rule would prevent users from creating an Object
of an object, a Number
if a number, a Boolean
of a boolean, etc.
Note that:
- no-new-object will not block code like
Object({a:1})
(without thenew
) - no-restricted-globals could work with a custom list of
Boolean
,Object
,Number
andString
but it would block code likea instanceof String
.
What category of rule is this? (place an “X” next to just one item)
[ ] Enforces code style [ ] Warns about a potential error [X] Suggests an alternate way of doing something [ ] Other (please specify:)
Provide 2-3 code examples that this rule will warn about:
const alreadyAnObject = new Object({a: 1});
const alreadyABoolean = new Boolean(true);
const alreadyAString = new String('hello world');
const alreadyANumber = new Number(12);
Why should this rule be included in ESLint (instead of a plugin)?
The 4 examples I gave are literally useless. What I propose is an improvement of no-new-object, but more powerful and with a needed renaming.
Issue Analytics
- State:
- Created 7 years ago
- Comments:18 (15 by maintainers)
Top Results From Across the Web
Rule 33. Interrogatories to Parties - Law.Cornell.Edu
Rule 33(d) states that a party electing to respond to an interrogatory by providing electronically stored information must ensure that the interrogating party ......
Read more >California Rules of Court: Title Three Rules
Chapter 1. Preliminary Rules; Rule 3.1. Title ; Rule 3.10. Application · Rule 3.20. Preemption of local rules ; Chapter 3. Attorneys; Rule...
Read more >Requesting Parties: Initial Considerations (Federal) - Westlaw
This Practice Note sets out considerations to consider before drafting requests for the production of documents (RFPs) in a federal lawsuit under Rule...
Read more >Federal Rules of Civil Procedure Rule 34 Document Request ...
A Rule 34 request will be considered served at the first Rule 26(f) conference and responses will be due 30 day after that...
Read more >Federal Rules of Civil Procedure - Social Security
(d) Waiving Service. (1) Requesting a Waiver. An individual, corporation, or association that is subject to service under Rule 4(e) ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thinking about this some more, I’m not sure combining
no-new-object
andno-new-wrappers
is the best course here, since we also haveno-array-constructor
. They all do slightly different things to deal with the pitfalls of their respective types, and I think it might be best to leave them as is (though we should maybe consider naming them in such a way that it’s obvious they’re related).Putting the discussion to combine
no-new-object
andno-new-wrappers
aside for a moment, disallowing unnecessary typecasting seems like a fundamentally different problem than what theno-new-wrappers
rule is trying to solve (preventing unnecessary type coercion of a value vs. preventing creating wrappers objects rather than primitive values).That being said, that does seem like a useful rule - maybe something like
no-useless-coercion
? The rule would disallow type coercion with the following function calls if the argument is already of that type:TL;DR: Maybe we should leave the current type constructor function rules alone and create a new rule that disallows unnecessary type coercion.
Thoughts?
I’m curious why we have both
no-new-object
andno-new-wrappers
. Seems like this could all be one rule.