Babel-eslint: Incompatibility with eslint 4.14.0

Created on 24 Dec 2017  路  38Comments  路  Source: babel/babel-eslint

See: https://github.com/eslint/eslint/issues/9767

Something changed in esline 4.14.0 that is causing an incompatibility. With the result of:

> $ yarn lint                                                                          [卤master 鈼廬
yarn run v1.3.2
$ yarn lint:js . && yarn lint:md .
$ cross-env NODE_ENV=production eslint --cache --cache-location=.cache/eslint --ext .js,.jsx,.json .
Cannot read property 'type' of undefined
TypeError: Cannot read property 'type' of undefined
    at isForInRef (/Users/dev/Projects/GitHub/storybook/core/node_modules/eslint/lib/rules/no-unused-vars.js:410:24)
    at variable.references.some.ref (/Users/dev/Projects/GitHub/storybook/core/node_modules/eslint/lib/rules/no-unused-vars.js:447:21)
    at Array.some (<anonymous>)
    at isUsedVariable (/Users/dev/Projects/GitHub/storybook/core/node_modules/eslint/lib/rules/no-unused-vars.js:446:40)
    at collectUnusedVariables (/Users/dev/Projects/GitHub/storybook/core/node_modules/eslint/lib/rules/no-unused-vars.js:569:26)
    at collectUnusedVariables (/Users/dev/Projects/GitHub/storybook/core/node_modules/eslint/lib/rules/no-unused-vars.js:576:17)
    at Program:exit (/Users/dev/Projects/GitHub/storybook/core/node_modules/eslint/lib/rules/no-unused-vars.js:621:36)
    at listeners.(anonymous function).forEach.listener (/Users/dev/Projects/GitHub/storybook/core/node_modules/eslint/lib/util/safe-emitter.js:47:58)
    at Array.forEach (<anonymous>)
    at Object.emit (/Users/dev/Projects/GitHub/storybook/core/node_modules/eslint/lib/util/safe-emitter.js:47:38)
    at NodeEventGenerator.applySelector (/Users/dev/Projects/GitHub/storybook/core/node_modules/eslint/lib/util/node-event-generator.js:251:26)
    at NodeEventGenerator.applySelectors (/Users/dev/Projects/GitHub/storybook/core/node_modules/eslint/lib/util/node-event-generator.js:280:22)
    at NodeEventGenerator.leaveNode (/Users/dev/Projects/GitHub/storybook/core/node_modules/eslint/lib/util/node-event-generator.js:303:14)
    at CodePathAnalyzer.leaveNode (/Users/dev/Projects/GitHub/storybook/core/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:630:23)
    at Traverser.leave [as _leave] (/Users/dev/Projects/GitHub/storybook/core/node_modules/eslint/lib/linter.js:1000:32)
    at Traverser._traverse (/Users/dev/Projects/GitHub/storybook/core/node_modules/eslint/lib/util/traverser.js:155:18)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I've detailed more here

I've run eslint with debug enabled, and copied the final few lines:

  eslint:cli-engine Processing /Users/dev/Projects/GitHub/storybook/core/examples/official-storybook/components/FlowTypeButton.js +16ms
  eslint:cli-engine Linting /Users/dev/Projects/GitHub/storybook/core/examples/official-storybook/components/FlowTypeButton.js +0ms
  eslint:config Constructing config file hierarchy for /Users/dev/Projects/GitHub/storybook/core/examples/official-storybook/components +0ms
  eslint:config Using .eslintrc and package.json files +0ms
  eslint:config Loading /Users/dev/Projects/GitHub/storybook/core/examples/official-storybook/package.json +0ms
  eslint:config-file Loading package.json config file: /Users/dev/Projects/GitHub/storybook/core/examples/official-storybook/package.json +0ms
  eslint:config-file Loading JSON config file: /Users/dev/Projects/GitHub/storybook/core/examples/official-storybook/package.json +0ms
  eslint:config Using config from cache +0ms
  eslint:linter Linting code for /Users/dev/Projects/GitHub/storybook/core/examples/official-storybook/components/FlowTypeButton.js (pass 1) +0ms
  eslint:traverser Unknown node type "TypeAlias": Estimated visitor keys ["type","start","end","loc","range","id","typeParameters","right"] +328ms
  eslint:traverser Unknown node type "ObjectTypeAnnotation": Estimated visitor keys ["type","start","end","loc","range","callProperties","properties","indexers","exact"] +0ms
  eslint:traverser Unknown node type "ObjectTypeProperty": Estimated visitor keys ["type","start","end","loc","range","static","kind","value","variance","optional"] +0ms
  eslint:traverser Unknown node type "StringTypeAnnotation": Estimated visitor keys ["type","start","end","loc","range"] +0ms
  eslint:traverser Unknown node type "ObjectTypeProperty": Estimated visitor keys ["type","start","end","loc","range","static","kind","value","variance","optional"] +0ms
  eslint:traverser Unknown node type "GenericTypeAnnotation": Estimated visitor keys ["type","start","end","loc","range","typeParameters","id"] +0ms
  eslint:traverser Unknown node type "ObjectTypeProperty": Estimated visitor keys ["type","start","end","loc","range","static","kind","value","variance","optional"] +0ms
  eslint:traverser Unknown node type "BooleanTypeAnnotation": Estimated visitor keys ["type","start","end","loc","range"] +0ms
Cannot read property 'type' of undefined
TypeError: Cannot read property 'type' of undefined
    at isForInRef (/Users/dev/Projects/GitHub/storybook/core/node_modules/eslint/lib/rules/no-unused-vars.js:410:24)
    at variable.references.some.ref (/Users/dev/Projects/GitHub/storybook/core/node_modules/eslint/lib/rules/no-unused-vars.js:447:21)
    at Array.some (<anonymous>)
    at isUsedVariable (/Users/dev/Projects/GitHub/storybook/core/node_modules/eslint/lib/rules/no-unused-vars.js:446:40)
    at collectUnusedVariables (/Users/dev/Projects/GitHub/storybook/core/node_modules/eslint/lib/rules/no-unused-vars.js:569:26)
    at collectUnusedVariables (/Users/dev/Projects/GitHub/storybook/core/node_modules/eslint/lib/rules/no-unused-vars.js:576:17)
    at Program:exit (/Users/dev/Projects/GitHub/storybook/core/node_modules/eslint/lib/rules/no-unused-vars.js:621:36)
    at listeners.(anonymous function).forEach.listener (/Users/dev/Projects/GitHub/storybook/core/node_modules/eslint/lib/util/safe-emitter.js:47:58)
    at Array.forEach (<anonymous>)
    at Object.emit (/Users/dev/Projects/GitHub/storybook/core/node_modules/eslint/lib/util/safe-emitter.js:47:38)
    at NodeEventGenerator.applySelector (/Users/dev/Projects/GitHub/storybook/core/node_modules/eslint/lib/util/node-event-generator.js:251:26)
    at NodeEventGenerator.applySelectors (/Users/dev/Projects/GitHub/storybook/core/node_modules/eslint/lib/util/node-event-generator.js:280:22)
    at NodeEventGenerator.leaveNode (/Users/dev/Projects/GitHub/storybook/core/node_modules/eslint/lib/util/node-event-generator.js:303:14)
    at CodePathAnalyzer.leaveNode (/Users/dev/Projects/GitHub/storybook/core/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:630:23)
    at Traverser.leave [as _leave] (/Users/dev/Projects/GitHub/storybook/core/node_modules/eslint/lib/linter.js:1000:32)
    at Traverser._traverse (/Users/dev/Projects/GitHub/storybook/core/node_modules/eslint/lib/util/traverser.js:155:18)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Most helpful comment

I am now having this issue with the latest everything?

"babel-eslint": "^10.0.1",

[Error - 12:17:26 PM] TypeError: Cannot read property 'type' of undefined
    at isForInRef (/Users/Shared/Development/projects/pubchan/node_modules/eslint/lib/rules/no-unused-vars.js:430:24)
    at variable.references.some.ref (/Users/Shared/Development/projects/pubchan/node_modules/eslint/lib/rules/no-unused-vars.js:467:21)
    at Array.some (<anonymous>)
    at isUsedVariable (/Users/Shared/Development/projects/pubchan/node_modules/eslint/lib/rules/no-unused-vars.js:466:40)
    at collectUnusedVariables (/Users/Shared/Development/projects/pubchan/node_modules/eslint/lib/rules/no-unused-vars.js:578:26)
    at collectUnusedVariables (/Users/Shared/Development/projects/pubchan/node_modules/eslint/lib/rules/no-unused-vars.js:585:17)
    at Program:exit 
...

All 38 comments

Could you provide an example of a file that you're linting when this crash occurs? (To check which file causes the crash, you can run eslint with the --debug flag and see the last file that gets printed before the crash happens.)

// @flow
import React from 'react';

type PropsType = {
  /** The text to be rendered in the button */
  label: string,
  /** Function to be called when the button is clicked */
  onClick?: Function,
  /** Boolean representing wether the button is disabled */
  disabled?: boolean,
};

/** FlowTypeButton component description imported from comments inside the component file */
const FlowTypeButton = ({ label, onClick, disabled }: PropsType) => (
  <button onClick={onClick} disabled={disabled}>
    {label}
  </button>
);

FlowTypeButton.defaultProps = {
  disabled: false,
  onClick: () => {},
};

export default FlowTypeButton;

Thanks for providing the file. Could you also provide your config?

I can't reproduce this crash at the moment. I'm using your file as foo.js:


foo.js

// @flow
import React from 'react';

type PropsType = {
  /** The text to be rendered in the button */
  label: string,
  /** Function to be called when the button is clicked */
  onClick?: Function,
  /** Boolean representing wether the button is disabled */
  disabled?: boolean,
};

/** FlowTypeButton component description imported from comments inside the component file */
const FlowTypeButton = ({ label, onClick, disabled }: PropsType) => (
  <button onClick={onClick} disabled={disabled}>
    {label}
  </button>
);

FlowTypeButton.defaultProps = {
  disabled: false,
  onClick: () => {},
};

export default FlowTypeButton;


And I'm using the following config file:


.eslintrc.yml

parser: babel-eslint
rules:
  no-unused-vars: error


And I'm running the following commands to lint the file:

$ rm -rf node_modules/
$ npm i [email protected] [email protected]
$ node_modules/.bin/eslint foo.js

I get the following reported error as expected, but no crash:

  2:8  error  'React' is defined but never used  no-unused-vars

Creating a reproducible test case for this issue would make it much easier to determine whether this is a bug.

Here's my eslint config:

const error = 2;
const warn = 1;
const ignore = 0;

module.exports = {
  root: true,
  extends: ['eslint-config-airbnb', 'plugin:jest/recommended', 'prettier'],
  plugins: ['prettier', 'jest', 'react', 'json'],
  parser: 'babel-eslint',
  parserOptions: {
    sourceType: 'module',
  },
  env: {
    es6: true,
    node: true,
    'jest/globals': true,
  },
  settings: {
    'import/core-modules': ['enzyme'],
  },
  rules: {
    strict: [error, 'never'],
    'prettier/prettier': [
      warn,
      {
        printWidth: 100,
        tabWidth: 2,
        bracketSpacing: true,
        trailingComma: 'es5',
        singleQuote: true,
      },
    ],
    'no-debugger': process.env.NODE_ENV === 'production' ? error : ignore,
    quotes: [warn, 'single', { avoidEscape: true }],
    'class-methods-use-this': ignore,
    'arrow-parens': [warn, 'as-needed'],
    'space-before-function-paren': ignore,
    'import/no-unresolved': error,
    'import/extensions': [
      error,
      {
        js: 'never',
        json: 'always',
      },
    ],
    'import/no-extraneous-dependencies': [
      error,
      {
        devDependencies: [
          'examples/**',
          '**/example/**',
          '*.js',
          '**/*.test.js',
          '**/*.stories.js',
          '**/scripts/*.js',
          '**/stories/**/*.js',
          '**/__tests__/**/*.js',
        ],
        peerDependencies: true,
      },
    ],
    'import/prefer-default-export': ignore,
    'react/jsx-wrap-multilines': ignore,
    'react/jsx-indent': ignore,
    'react/jsx-indent-props': ignore,
    'react/jsx-closing-bracket-location': ignore,
    'react/jsx-uses-react': error,
    'react/jsx-uses-vars': error,
    'react/react-in-jsx-scope': error,
    'react/jsx-filename-extension': [
      warn,
      {
        extensions: ['.js', '.jsx'],
      },
    ],
    'jsx-a11y/accessible-emoji': ignore,
    'jsx-a11y/href-no-hash': ignore,
    'jsx-a11y/label-has-for': ignore,
    'jsx-a11y/click-events-have-key-events': error,
    'jsx-a11y/anchor-is-valid': [warn, { aspects: ['invalidHref'] }],
    'react/no-unescaped-entities': ignore,
  },
};

Oops, I had forgotten that you showed your config before in https://github.com/eslint/eslint/issues/9767#issuecomment-353804164. Thanks for pasting it again.

However, I'm still unable to reproduce the issue. When I install all of the latest versions of eslint, babel-eslint, and your plugins and configs, I still get no errors when linting your file using the config that you provided:

$ npm install [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected]
$ node_modules/.bin/eslint foo.js

Could you double-check the following?

  • You have [email protected] installed (run npm ls babel-eslint and check the version)
  • The file that you provided is the same file that is causing the crash (you can run node_modules/.bin/eslint theFile.js and ensure it crashes)

Thank you for all the amazing help @not-an-aardvark really really appreciate every second! 馃檱

I will do another attempt, possibly tomorrow, it's late over here 馃挙

I can give you the repo I had the problem on:
https://github.com/storybooks/storybook

If you interested in debugging it further, I have no expectations, thanks 馃憦

Thanks, I was able to reproduce the issue after cloning https://github.com/storybooks/storybook. I'll investigate it now.

I apology for this and thank you very much for the repro steps.
I'll investigate this as well!

@mysticatea On the storybooks/storybook repo, the issue can be reproduced by running:

$ node_modules/.bin/eslint examples/cra-kitchen-sink/src/stories/index.stories.js examples/official-storybook/components/FlowTypeButton.js

For some reason, everything works when FlowTypeButton.js is linted on its own, but it crashes when index.stories.js is linted first. I suspect babelEslint.parse is getting called somehow instead of babelEslint.parseForESLint, so it's reverting to the old monkeypatching behavior on all future runs.

I realized that it may be came from eslint-plugin-import

I agree, it looks like eslint-plugin-import is calling parser.parse here, which causes babel-eslint to revert to the monkeypatching behavior.

I think the best solution would be to avoid monkeypatching when babelEslint.parse is called, and just return an AST. (Alternatively, maybe it could patch eslint-scope when parse is called, but still use a custom scopeManager/visitorKeys if parseForESLint is called afterwards.)

Making this change in babel-eslint seems to fix the crash in storybook, at least:

diff --git a/lib/index.js b/lib/index.js
index 130b10b..d950300 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -1,18 +1,14 @@
 "use strict";

-let patched = false;
-
 exports.parse = function(code, options) {
-  patched = true;
   return require("./parse-with-patch")(code, options);
 };

 exports.parseForESLint = function(code, options) {
-  if (!patched && options.eslintVisitorKeys && options.eslintScopeManager) {
+  if (options.eslintVisitorKeys && options.eslintScopeManager) {
     return require("./parse-with-scope")(code, options);
   }

-  patched = true;
   return { ast: require("./parse-with-patch")(code, options) };
 };

Does it make sense to run parse-with-scope when eslint-scope has already been patched?

If options.eslintScopeManager in parse exists, we can use it. (I'm still on the linking phase of yarn command...)

Does it make sense to run parse-with-scope when eslint-scope has already been patched?

If npm did dedup, I'm not sure that parse-with-scope works correctly.

Here's a minimal reproduction case:

a.js:

export default function foo() {}

b.js:

import foo from './a.js';

c.js:

type Foo = {};

const x: Foo = 0;

.eslintrc.yml:

parser: babel-eslint

plugins:
  - import

rules:
  import/no-named-as-default: error
  no-unused-vars: error
$ npm install [email protected] [email protected] [email protected]
$ node_modules/.bin/eslint b.js c.js

If options.eslintScopeManager in parse exists, we can use it.

Unfortunately, it does not exist.

One possibility would be for parse-with-scope to create a copy of the eslint-scope classes before it extends them. Then if eslint-scope gets monkeypatched after a call to parse, it will still be possible to have parse-with-scope working correctly if parseForESLint is called later.

Alternatively, we could do something like this:

diff --git a/lib/analyze-scope.js b/lib/analyze-scope.js
index b538dea..28d7eb2 100644
--- a/lib/analyze-scope.js
+++ b/lib/analyze-scope.js
@@ -322,7 +322,10 @@ module.exports = function(ast, parserOptions) {
     fallback,
   };
   const scopeManager = new escope.ScopeManager(options);
-  const referencer = new Referencer(options, scopeManager);
+  const ReferencerConstructor = hasPatchedEslintScope
+    ? OriginalReferencer
+    : Referencer;
+  const referencer = new ReferencerConstructor(options, scopeManager);

   referencer.visit(ast);

After eslint-scope has already been monkeypatched, I think we could just use a regular eslint-scope referencer to get the scope.

EDIT: Actually, we would need to make sure that the resolved version of eslint-scope is the same as the version that was monkeypatched.

Sounds good idea

I was thinking to determine implementation at the first call:

"use strict";

let patched = undefined;

exports.parse = function(code, options) {
  return exports.parseForESLint(code, options).ast
};

exports.parseForESLint = function (code, options) {
  if (patched === undefined) {
    patched = !(options.eslintVisitorKeys && options.eslintScopeManager)
  }
  if (patched) {
    return { ast: require("./parse-with-patch")(code, options) };
  }
  return require("./parse-with-scope")(code, options);
};

exports.parseNoPatch = function(code, options) {
  return require("./parse")(code, options);
};

I think we should try to avoid global mutable state, aside from the places where we have to monkeypatch for legacy reasons. So I think it would be better to not depend on what calls parse first, assuming there are other available options.

Actually, it seems like the monkeypatched escope.analyze will never be called by parse-with-scope, because parse-with-scope creates a Referencer manually. The changes to estraverse shouldn't affect eslint-scope because eslint-scope only uses estraverse.Syntax (based on this search), not estraverse.VisitorKeys. So I think the change from https://github.com/babel/babel-eslint/issues/558#issuecomment-353814512 should work fine.

Hmm, but parse-with-patch modifies Referencer.prototype.

Oh, you're right. I hadn't realized that.

I'll try the approach in https://github.com/babel/babel-eslint/issues/558#issuecomment-353816668.

I added a test based on https://github.com/babel/babel-eslint/issues/558#issuecomment-353815391: f92b364136a5922cf7fc513f82dd0ff2125262f6

I added a fix based on https://github.com/babel/babel-eslint/issues/558#issuecomment-353816668 and reopened https://github.com/babel/babel-eslint/pull/559. However, I'm trying to figure out why this test is failing.

I guess related to parserOptions.ecmaFeatures.globalReturn... (escope's option's nodejsScope)

I've upgraded storybook to both latest versions, but I'm seeing some really unexpected results.

The process exits with a expected failure, saying there are errors in my code.
The errors weren't there before the upgrade, and when I have a look at the errors it's returning, they seem incorrect to me.

When I run with debug enabled, I'm seeing a whole lot of
eslint:traverser Unknown node type "Property": Estimated visitor keys ["type","start","end","loc","range","method","key","computed","shorthand","value","kind"] +0ms

Here's a section of the log:

  eslint:config-file Loading JSON config file: /Users/dev/Projects/GitHub/storybook/core/lib/ui/package.json +0ms
  eslint:config Using config from cache +0ms
  eslint:cli-engine Processing /Users/dev/Projects/GitHub/storybook/core/lib/ui/src/modules/ui/containers/stories_panel.js +8ms
  eslint:cli-engine Linting /Users/dev/Projects/GitHub/storybook/core/lib/ui/src/modules/ui/containers/stories_panel.js +0ms
  eslint:config Constructing config file hierarchy for /Users/dev/Projects/GitHub/storybook/core/lib/ui/src/modules/ui/containers +0ms
  eslint:config Using .eslintrc and package.json files +0ms
  eslint:config Loading /Users/dev/Projects/GitHub/storybook/core/lib/ui/package.json +0ms
  eslint:config-file Loading package.json config file: /Users/dev/Projects/GitHub/storybook/core/lib/ui/package.json +0ms
  eslint:config-file Loading JSON config file: /Users/dev/Projects/GitHub/storybook/core/lib/ui/package.json +0ms
  eslint:config Using config from cache +0ms
  eslint:linter Linting code for /Users/dev/Projects/GitHub/storybook/core/lib/ui/src/modules/ui/containers/stories_panel.js (pass 1) +0ms
  eslint:traverser Unknown node type "Literal": Estimated visitor keys ["type","start","end","loc","range","value","raw"] +9ms
  eslint:traverser Unknown node type "Literal": Estimated visitor keys ["type","start","end","loc","range","value","raw"] +1ms
  eslint:traverser Unknown node type "Literal": Estimated visitor keys ["type","start","end","loc","range","value","raw"] +0ms
  eslint:traverser Unknown node type "Literal": Estimated visitor keys ["type","start","end","loc","range","value","raw"] +0ms
  eslint:traverser Unknown node type "Literal": Estimated visitor keys ["type","start","end","loc","range","value","raw"] +1ms
  eslint:traverser Unknown node type "Property": Estimated visitor keys ["type","start","end","loc","range","method","key","computed","shorthand","value","kind","extra"] +0ms
  eslint:traverser Unknown node type "Property": Estimated visitor keys ["type","start","end","loc","range","method","key","computed","shorthand","value","kind","extra"] +0ms
  eslint:traverser Unknown node type "Property": Estimated visitor keys ["type","start","end","loc","range","method","key","computed","shorthand","value","kind","extra"] +0ms
  eslint:traverser Unknown node type "Property": Estimated visitor keys ["type","start","end","loc","range","method","key","computed","shorthand","value","kind","extra"] +0ms
  eslint:traverser Unknown node type "Property": Estimated visitor keys ["type","start","end","loc","range","method","key","computed","shorthand","value","kind","extra"] +0ms
  eslint:traverser Unknown node type "Property": Estimated visitor keys ["type","start","end","loc","range","method","key","computed","shorthand","value","kind","extra"] +0ms
  eslint:traverser Unknown node type "Property": Estimated visitor keys ["type","start","end","loc","range","method","key","computed","shorthand","value","kind","extra"] +0ms
  eslint:traverser Unknown node type "Property": Estimated visitor keys ["type","start","end","loc","range","method","key","computed","shorthand","value","kind","extra"] +1ms
  eslint:traverser Unknown node type "Property": Estimated visitor keys ["type","start","end","loc","range","method","key","computed","shorthand","value","kind","extra"] +0ms
  eslint:traverser Unknown node type "Property": Estimated visitor keys ["type","start","end","loc","range","method","key","computed","shorthand","value","kind","extra"] +0ms
  eslint:traverser Unknown node type "Property": Estimated visitor keys ["type","start","end","loc","range","method","key","computed","shorthand","value","kind","extra"] +0ms
  eslint:traverser Unknown node type "Property": Estimated visitor keys ["type","start","end","loc","range","method","key","computed","shorthand","value","kind","extra"] +0ms
  eslint:traverser Unknown node type "Property": Estimated visitor keys ["type","start","end","loc","range","method","key","computed","shorthand","value","kind","extra"] +0ms
  eslint:traverser Unknown node type "Property": Estimated visitor keys ["type","start","end","loc","range","method","key","computed","shorthand","value","kind","extra"] +0ms
  eslint:traverser Unknown node type "Property": Estimated visitor keys ["type","start","end","loc","range","method","key","computed","shorthand","value","kind","extra"] +0ms
  eslint:traverser Unknown node type "Property": Estimated visitor keys ["type","start","end","loc","range","method","key","computed","shorthand","value","kind"] +0ms
  eslint:traverser Unknown node type "Property": Estimated visitor keys ["type","start","end","loc","range","method","key","computed","shorthand","value","kind","extra"] +0ms
  eslint:traverser Unknown node type "Property": Estimated visitor keys ["type","start","end","loc","range","method","key","computed","shorthand","value","kind"] +0ms
  eslint:traverser Unknown node type "Property": Estimated visitor keys ["type","start","end","loc","range","method","key","computed","shorthand","value","kind"] +1ms
  eslint:traverser Unknown node type "Property": Estimated visitor keys ["type","start","end","loc","range","method","key","computed","shorthand","value","kind","extra"] +0ms
  eslint:traverser Unknown node type "Property": Estimated visitor keys ["type","start","end","loc","range","method","key","computed","shorthand","value","kind","extra"] +0ms
  eslint:traverser Unknown node type "Property": Estimated visitor keys ["type","start","end","loc","range","method","key","computed","shorthand","value","kind","extra"] +0ms
  eslint:linter Generating fixed text for /Users/dev/Projects/GitHub/storybook/core/lib/ui/src/modules/ui/containers/stories_panel.js (pass 1) +12ms
  eslint:text-fixer Applying fixes +12ms
  eslint:text-fixer shouldFix parameter was false, not attempting fixes +0ms

I can post the entire log if desired.

In the end, I get this list of errors:

/Users/dev/Projects/GitHub/storybook/core/addons/actions/src/lib/retrocycle.js
   1:8   error  'reviver' is defined but never used       no-unused-vars
   2:10  error  'muteProperty' is defined but never used  no-unused-vars
   3:10  error  'CYCLIC_KEY' is defined but never used    no-unused-vars
   5:7   error  'pathReg' is defined but never used       no-unused-vars
   5:7   error  'pathReg' is not defined                  no-undef
   7:36  error  'json' is defined but never used          no-unused-vars
   8:9   error  '$' is defined but never used             no-unused-vars
   8:9   error  '$' is not defined                        no-undef
   8:24  error  'json' is not defined                     no-undef
   8:30  error  'reviver' is not defined                  no-undef
  10:32  error  '$' is not defined                        no-undef
  11:12  error  '$' is not defined                        no-undef
  14:17  error  'value' is defined but never used         no-unused-vars
  15:9   error  'value' is not defined                    no-undef
  16:25  error  'value' is not defined                    no-undef
  17:29  error  'value' is not defined                    no-undef
  18:24  error  'value' is not defined                    no-undef
  21:45  error  'pathReg' is not defined                  no-undef
  22:15  error  'value' is not defined                    no-undef
  24:15  error  'rez' is not defined                      no-undef
  30:28  error  'value' is not defined                    no-undef
  31:24  error  'value' is not defined                    no-undef
  36:45  error  'pathReg' is not defined                  no-undef
  37:15  error  'value' is not defined                    no-undef
  39:15  error  'rez' is not defined                      no-undef
  45:6   error  '$' is not defined                        no-undef
  47:3   error  'muteProperty' is not defined             no-undef
  47:16  error  'CYCLIC_KEY' is not defined               no-undef
  47:28  error  '$' is not defined                        no-undef
  49:10  error  '$' is not defined                        no-undef

on this file:

import reviver from './reviver';
import { muteProperty } from './util';
import { CYCLIC_KEY } from './';

const pathReg = /^\$(?:\[(?:\d+|"(?:[^\\"\u0000-\u001f]|\\([\\"/bfnrt]|u[0-9a-zA-Z]{4}))*")])*$/;

export default function retrocycle(json) {
  const $ = JSON.parse(json, reviver);

  if (typeof $ !== 'object' || $ === null) {
    return $;
  }

  (function rez(value) {
    if (value && typeof value === 'object') {
      if (Array.isArray(value)) {
        for (let i = 0; i < value.length; i += 1) {
          const item = value[i];
          if (item && typeof item === 'object') {
            const path = item.$ref;
            if (typeof path === 'string' && pathReg.test(path)) {
              value[i] = eval(path); // eslint-disable-line no-eval, no-param-reassign
            } else {
              rez(item);
            }
          }
        }
      } else {
        // eslint-disable-next-line no-restricted-syntax, guard-for-in
        for (const name in value) {
          const item = value[name];

          if (typeof item === 'object' && item !== null) {
            const path = item.$ref;

            if (typeof path === 'string' && pathReg.test(path)) {
              value[name] = eval(path); // eslint-disable-line no-eval, no-param-reassign
            } else {
              rez(item);
            }
          }
        }
      }
    }
  })($);

  muteProperty(CYCLIC_KEY, $);

  return $;
}

Thank you for the report.
Probably #560 (#561) fixes it. Please wait for review of the team.

Sure, thanks @mysticatea just wanted to report any info that might be of use. Happy Holidays, really appreciate your efforts!

Thank you so much, I found a performance issue from your debug log. #562 should fix it.

Hi,

after upgrade to [email protected] I got an error:

6:30 error Parse errors in imported module '***': Cannot find module 'estraverse' (undefined:undefined) import/no-named-as-default

it looks like the babel-eslint in file patch-eslint-scope.js is looking for estraverse module, and because it was removed from eslint in version 4.14 it returns an error.
After I installed estraverse into my local devDependencies it started working, but what do you think, how it should be handled?

Thanks

Everything is working on my end.

@eljoaquin try removing all node_modules and your lockfiles and install again.

Upgrading all related dependencies might also resolve the issue.

Seeing the same issue as @eljoaquin. Running on node 4.8.7 and npm 2.15.11. It works fine on node >= 6. Downgrading eslint to 4.13.1 works so maybe more of an issue with eslint than with babel-eslint.

Seeing the same issue as @eljoaquin on npm 2.15.12, so the only solution is to install estraverse as devDependency?

@dickeylth what does estraverse do?

I'm having the same issues now where I get the Cannot read property range of undefined :(

I am now having this issue with the latest everything?

"babel-eslint": "^10.0.1",

[Error - 12:17:26 PM] TypeError: Cannot read property 'type' of undefined
    at isForInRef (/Users/Shared/Development/projects/pubchan/node_modules/eslint/lib/rules/no-unused-vars.js:430:24)
    at variable.references.some.ref (/Users/Shared/Development/projects/pubchan/node_modules/eslint/lib/rules/no-unused-vars.js:467:21)
    at Array.some (<anonymous>)
    at isUsedVariable (/Users/Shared/Development/projects/pubchan/node_modules/eslint/lib/rules/no-unused-vars.js:466:40)
    at collectUnusedVariables (/Users/Shared/Development/projects/pubchan/node_modules/eslint/lib/rules/no-unused-vars.js:578:26)
    at collectUnusedVariables (/Users/Shared/Development/projects/pubchan/node_modules/eslint/lib/rules/no-unused-vars.js:585:17)
    at Program:exit 
...

@bradennapier did you solve this? thx!

Was this page helpful?
0 / 5 - 0 ratings