AtomLinter / linter-jshint

Atom linter plugin for JavaScript, using jshint.
147 stars 36 forks source link

MAJOR BUG: JSHint do not recognizing [Symbol.toPrimitive)(hint) in ES6 classes #789

Closed jhack-jos closed 4 years ago

jhack-jos commented 4 years ago

Given the [Symbol.toPrimitive] method in a ES6 class put inside a ".js" file, such as the one in the following class:

/*jshint esversion: 6 */
class TruncableDate
{
  constructor(originalDate = null)
  {
      if(originalDate == null)
      {
        this.innerDate = new Date();
      }
      else
      {
        this.innerDate = new Date(originalDate);
      }
  }

  static from(originalDate)
  {
    return new TruncableDate(originalDate);
  }

  valueOf()
  {
    return this.innerDate.valueOf();
  }

  toString()
  {
    return this.innerDate.toString();
  }

  [Symbol.toPrimitive](hint)
  {
    return this.innerDate[Symbol.toPrimitive](hint);
  }
}

JSHint may or may not alert there are errors in the current source after the Symbol.toPrimitive part -depending on the file I had different results -, but does always throws errors on the Atom javascript console such as the following:

[Linter] Error running JSHint TypeError: Cannot convert undefined or null to object at Function.keys () at Object. (/Users/Jacopo/.atom/packages/linter-jshint/lib/main.js:168) at Generator.next () at step (/Users/Jacopo/.atom/packages/linter-jshint/lib/main.js:3)

The errors keep being thrown, so that it is impossible to program without disabling JSHint. I am currently using the latest available version of JSHint, 3.1.17. Let me know if I can share any further data to help pinpointing the problem. Thank you in advance for your support! Warmest Regards

Arcanemagus commented 4 years ago

You'll want to refile this on the JSHint project, this is just a wrapper around that that brings the results into Atom.