jscs-dev / node-jscs

:arrow_heading_up: JavaScript Code Style checker (unmaintained)
https://jscs-dev.github.io
MIT License
4.96k stars 510 forks source link

Jscs chokes on es6 classes with constructor which calls super with "disallowUnusedParams" option set to true #2002

Closed danny-andrews closed 8 years ago

danny-andrews commented 8 years ago

Every time I run jscs against a file which has an es6 with a constructor that calls super, it chokes. .jscsrc:

{
  "disallowUnusedParams": true
}

src/example.js:

import Parent from './parent';

export default class extends Parent {
  constructor() {
    super('hi parent');
  }
}

Example error message

Error running rule disallowUnusedParams: This is an issue with JSCS and not your codebase.
Please file an issue (with the stack trace below) at: https://github.com/jscs-dev/node-jscs/issues/new
RangeError: Maximum call stack size exceeded
    at Function.isArray (native)
    at Referencer.Visitor.visitChildren (example_project/node_modules/grunt-jscs/node_modules/jscs/node_modules/escope/node_modules/esrecurse/esrecurse.js:84:27)
    at Referencer.CallExpression (example_project/node_modules/grunt-jscs/node_modules/jscs/node_modules/escope/lib/referencer.js:480:22)
    at Referencer.Visitor.visit (example_project/node_modules/grunt-jscs/node_modules/jscs/node_modules/escope/node_modules/esrecurse/esrecurse.js:109:34)
    at Referencer.Visitor.visitChildren (example_project/node_modules/grunt-jscs/node_modules/jscs/node_modules/escope/node_modules/esrecurse/esrecurse.js:93:26)
    at Referencer.Visitor.visit (example_project/node_modules/grunt-jscs/node_modules/jscs/node_modules/escope/node_modules/esrecurse/esrecurse.js:112:14)
    at Referencer.Visitor.visitChildren (example_project/node_modules/grunt-jscs/node_modules/jscs/node_modules/escope/node_modules/esrecurse/esrecurse.js:93:26)
    at Referencer.CallExpression (example_project/node_modules/grunt-jscs/node_modules/jscs/node_modules/escope/lib/referencer.js:480:22)
    at Referencer.Visitor.visit (example_project/node_modules/grunt-jscs/node_modules/jscs/node_modules/escope/node_modules/esrecurse/esrecurse.js:109:34)
    at Referencer.Visitor.visitChildren (example_project/node_modules/grunt-jscs/node_modules/jscs/node_modules/escope/node_modules/esrecurse/esrecurse.js:93:26) at src/example.js :
     1 |import Parent from './parent';
--------^
     2 |
     3 |export default class extends Parent {

Note, if I comment out the call to super in the constructor, everything works as expected.

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

markelog commented 8 years ago

Yeah, all because of the escope package which can't work with babel AST :/

danny-andrews commented 8 years ago

Ah, bummer. So this is a known issue then?

markelog commented 8 years ago

Yeah, bunch of issues with inability of escope to work with circular structures :/

hzoo commented 8 years ago

I think its related to multiple version of escope/estraverse (the same issue in eslint/babel-eslint). https://github.com/babel/babel-eslint/pull/209, https://github.com/eslint/eslint/issues/4485, some others? I haven't updated babel-jscs at all so need to port over babel-eslint changes

markelog commented 8 years ago

Basically, if parser generates AST with circular refs escope will go down, but the sad part is, no one of the maintainers of that package is interesting in fixing it :/

gibson042 commented 8 years ago

parser generates AST with circular refs

  • abstract syntax tree (AST): "a tree representation of the abstract syntactic structure of source code"
  • tree: "an undirected graph in which any two vertices are connected by exactly one path. In other words, any connected graph without simple cycles is a tree."

https://github.com/estree/estree is cycle-free for good reason.

hzoo commented 8 years ago

There are underscored properties like _paths which could do that (info on scopes, parent/child, etc)

markelog commented 8 years ago

@gibson042 sure, but we don't parse ourselves @hzoo underscore is meaningless :/

markelog commented 8 years ago

At this point only major and CST related bugs will be fixed.