Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule request: no-useless-builtin-calls

See original GitHub issue

Please 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 the new)
  • no-restricted-globals could work with a custom list of Boolean, Object, Number and String but it would block code like a 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:closed
  • Created 7 years ago
  • Comments:18 (15 by maintainers)

github_iconTop GitHub Comments

kaicataldocommented, Oct 12, 2016

Thinking about this some more, I’m not sure combining no-new-object and no-new-wrappers is the best course here, since we also have no-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 and no-new-wrappers aside for a moment, disallowing unnecessary typecasting seems like a fundamentally different problem than what the no-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:

Object({a: 1});
String('hello world');

TL;DR: Maybe we should leave the current type constructor function rules alone and create a new rule that disallows unnecessary type coercion.


kaicataldocommented, Oct 6, 2016

I’m curious why we have both no-new-object and no-new-wrappers. Seems like this could all be one rule.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found