noNewSymbol
Summary
Section titled “Summary”- Rule available since:
v1.0.0
- Diagnostic Category:
lint/correctness/noNewSymbol
- This rule has an unsafe fix.
- The default severity of this rule is information.
- Sources:
- Same as
no-new-symbol
- Same as
Description
Section titled “Description”Disallow new
operators with the Symbol
object.
Symbol
cannot be instantiated. This results in throwing a TypeError
.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”var foo = new Symbol('foo');
code-block.js:1:11 lint/correctness/noNewSymbol FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Symbol cannot be called as a constructor.
> 1 │ var foo = new Symbol(‘foo’);
│ ^^^^^^^^^^^^^^^^^
2 │
ℹ Unsafe fix: Remove new.
1 │ var·foo·=·new·Symbol(‘foo’);
│ ----
var bar = Symbol('bar');function baz() { function Symbol() { } new Symbol();}
How to configure
Section titled “How to configure”{ "linter": { "rules": { "correctness": { "noNewSymbol": "error" } } }}