Skip to main content

noNewSymbol (since v0.10.0)

Disallow new operators with the Symbol object

Examples

Invalid

var foo = new Symbol('foo');
nursery/noNewSymbol.js:1:11 lint/nursery/noNewSymbol  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Symbol cannot be called as a constructor.
  
     nursery/noNewSymbol.js:1:11
    
  1  var foo = new Symbol('foo');
               ^^^^^^^^^^^^^^^^^
  
   Suggested fix: Remove new.
  
      | @@ -1 +1 @@
  0   | - var foo = new Symbol('foo');
    0 | + var foo = Symbol('foo');
  

Valid

var bar = Symbol('bar');
function baz() {
function Symbol() { }
new Symbol();
}