Giter Club home page Giter Club logo

babel-eslint's Introduction

babel-eslint npm travis npm-downloads

NOTE: babel-eslint is now @babel/eslint-parser and has moved into the Babel monorepo.

babel-eslint allows you to lint ALL valid Babel code with the fantastic ESLint.

Breaking changes in v11.x.x

As of the v11.x.x release, babel-eslint now requires Babel as a peer dependency and expects a valid Babel configuration file to exist. This ensures that the same Babel configuration is used during both linting and compilation.

v11 also changes some AST node types to match espree v6:

  • ExperimentalSpreadProperty became SpreadElement.
  • ExperimentalRestProperty became RestElement.
  • Literal became JSXText (for JSXText).

When should I use babel-eslint?

ESLint's default parser and core rules only support the latest final ECMAScript standard and do not support experimental (such as new features) and non-standard (such as Flow or TypeScript types) syntax provided by Babel. babel-eslint is a parser that allows ESLint to run on source code that is transformed by Babel.

Note: You only need to use babel-eslint if you are using Babel to transform your code. If this is not the case, please use the relevant parser for your chosen flavor of ECMAScript (note that the default parser supports all non-experimental syntax as well as JSX).

How does it work?

ESLint allows for the use of custom parsers. When using this plugin, your code is parsed by Babel's parser (using the configuration specified in your Babel configuration file) and the resulting AST is transformed into an ESTree-compliant structure that ESLint can understand. All location info such as line numbers, columns is also retained so you can track down errors with ease.

Note: ESLint's core rules do not support experimental syntax and may therefore not work as expected when using babel-eslint. Please use the companion eslint-plugin-babel plugin for core rules that you have issues with.

Usage

Installation

$ npm install eslint babel-eslint --save-dev
# or
$ yarn add eslint babel-eslint -D

Note: babel-eslint requires babel/core@>=7.2.0 and a valid Babel configuration file to run. If you do not have this already set up, please see the Babel Usage Guide.

Setup

To use babel-eslint, "babel-eslint" must be specified as the parser in your ESLint configuration file (see here for more detailed information).

.eslintrc.js

module.exports = {
  parser: "babel-eslint",
};

With the parser set, your configuration can be configured as described in the Configuring ESLint documentation.

Note: The parserOptions described in the official documentation are for the default parser and are not necessarily supported by babel-eslint. Please see the section directly below for supported parserOptions.

Additional parser configuration

Additional configuration options can be set in your ESLint configuration under the parserOptions key. Please note that the ecmaFeatures config property may still be required for ESLint to work properly with features not in ECMAScript 5 by default.

  • requireConfigFile (default true) can be set to false to allow babel-eslint to run on files that do not have a Babel configuration associated with them. This can be useful for linting files that are not transformed by Babel (such as tooling configuration files), though we recommend using the default parser via glob-based configuration. Note: babel-eslint will not parse any experimental syntax when no configuration file is found.
  • sourceType can be set to "module"(default) or "script" if your code isn't using ECMAScript modules.
  • allowImportExportEverywhere (default false) can be set to true to allow import and export declarations to appear anywhere a statement is allowed if your build environment supports that. Otherwise import and export declarations can only appear at a program's top level.
  • ecmaFeatures.globalReturn (default false) allow return statements in the global scope when used with sourceType: "script".
  • babelOptions passes through Babel's configuration loading and merging options (for instance, in case of a monorepo). When not defined, babel-eslint will use Babel's default configuration file resolution logic.

.eslintrc.js

module.exports = {
  parser: "babel-eslint",
  parserOptions: {
    sourceType: "module",
    allowImportExportEverywhere: false,
    ecmaFeatures: {
      globalReturn: false,
    },
    babelOptions: {
      configFile: "path/to/config.js",
    },
  },
};

.eslintrc.js using glob-based configuration

This configuration would use the default parser for all files except for those found by the "files/transformed/by/babel/*.js" glob.

module.exports = {
  rules: {
    indent: "error"
  },
  overrides: [
    {
      files: ["files/transformed/by/babel/*.js"],
      parser: "babel-eslint",
    }
  ]
};

Run

$ ./node_modules/.bin/eslint yourfile.js

Known issues

Flow:

Check out eslint-plugin-flowtype: An eslint plugin that makes flow type annotations global variables and marks declarations as used. Solves the problem of false positives with no-undef and no-unused-vars.

  • no-undef for global flow types: ReactElement, ReactClass #130
    • Workaround: define types as globals in .eslintrc or define types and import them import type ReactElement from './types'
  • no-unused-vars/no-undef with Flow declarations (declare module A {}) #132

Modules/strict mode

  • no-unused-vars: ["error", { vars: local }] #136

Please check out eslint-plugin-react for React/JSX issues.

  • no-unused-vars with jsx

Please check out eslint-plugin-babel for other issues.

Questions and support

If you have an issue, please first check if it can be reproduced with the default parser and with the latest versions of eslint and babel-eslint. If it is not reproducible with the default parser, it is most likely an issue with babel-eslint.

For questions and support please visit the #discussion Babel Slack channel (sign up here) or the ESLint Gitter.

babel-eslint's People

Contributors

alexkuz avatar benoitzugmeyer avatar bgw avatar cellule avatar couto avatar danez avatar dependabot[bot] avatar douglasduteil avatar eventualbuddha avatar existentialism avatar fatfisz avatar globegitter avatar greenkeeper[bot] avatar greenkeeperio-bot avatar hzoo avatar jlhwung avatar josh avatar kaicataldo avatar kesne avatar leebyron avatar loganfsmyth avatar mysticatea avatar neverendingqs avatar not-an-aardvark avatar rubennorte avatar sebmck avatar soda0289 avatar standard8 avatar viztor avatar zertosh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

babel-eslint's Issues

Array comprehension [no-undef]

From the example in Babel website

// Array comprehensions
var results = [
  for(c of customers)
    if (c.city == "Seattle")
      { name: c.name, age: c.age }
]

Error =>
'c' is not defined. (no-undef);

Is it on purpose? Am I suppose to declare c before the array comprehension (since I cannot do it in the forblock)?

Thanks

Erroneous no-inner-declarations

Great work on this! Not sure if these are eslint bugs or babel-eslint bugs, but reporting here for now.

No linter warning:

/*eslint-env mocha*/

describe('stuff', function() {
    it("should help", function() {
        helper();
    });
    function helper() {
        return 1;
    }
});

Linter warning:

/*eslint-env mocha*/

describe('stuff', () => {
    it("should help", () => {
        helper();
    });
    function helper() {
        return 1;
    }
});

Gratuitous parentheses around expression

Hey there thanks for the cool project,

I noticed the following error:
the following code produce a "Gratuitous parentheses around expression"

if ((yield someGenerator()) === 1) {
}

rule: padded-blocks: false positive with comments

With padded-blocks set to "never" the following is reported as a warning and should not be:

if (a){
  // i'm a comment!
 let b = c
}

Removing the comment allows the rule to pass. The problem does not exist with the default eslint parser.

ECMAFeature classes should throw when disabled

I've noticed that if I use babel-eslint as parser, the ecmaFeatures.classes = false option does nothing.

Given this configuration

$ cat .eslintrc
/* http://eslint.org/docs/rules/ */
{
  "parser": "babel-eslint",
  "ecmaFeatures": {
    "classes": false
  },
  "env": {
    "node": true
  },
  "rules": {
    "eol-last": 2,
    "quotes": [2, "single"],
    "semi": 0,
    "strict": 0
  }
}

and this file

// test-class.js

class Foo {
  constructor() {
    this.foo = 'bar'
  }
}

When I run

$ eslint test-class.js
$ echo $?
0

When I remove the parser option it works

$ cat .eslintrc
/* http://eslint.org/docs/rules/ */
{
  "ecmaFeatures": {
    "classes": false
  },
  "env": {
    "node": true
  },
  "rules": {
    "eol-last": 2,
    "quotes": [2, "single"],
    "semi": 0,
    "strict": 0
  }
}

$ eslint test-class.js

test-class.js
  1:1  error  Unexpected reserved word

โœ– 1 problem (1 error, 0 warnings)

Is this a problem with babel-eslint ?

Issue with finally block and no-empty

If no-empty is set to 1 (default), a finally block will cause the error below. Here is a small test to reproduce it.

test.js:

function test() {};

try {
  test();
}
catch(e) {
}
finally {
}
.../lib/node_modules/eslint/lib/rules/no-empty.js:23
                    (isFinallyBlock && !parent.handlers.length)) {
                                                       ^
TypeError: Cannot read property 'length' of undefined
    at EventEmitter.BlockStatement (.../lib/node_modules/eslint/lib/rules/no-empty.js:23:56)
    at EventEmitter.emit (events.js:129:20)
    at Controller.controller.traverse.enter (.../lib/node_modules/eslint/lib/eslint.js:683:25)
    at Controller.__execute (.../lib/node_modules/eslint/node_modules/estraverse/estraverse.js:397:31)
    at Controller.traverse (.../lib/node_modules/eslint/node_modules/estraverse/estraverse.js:495:28)
    at EventEmitter.module.exports.api.verify (.../lib/node_modules/eslint/lib/eslint.js:676:24)
    at processFile (../lib/node_modules/eslint/lib/cli-engine.js:172:23)
    at ..lib/node_modules/eslint/lib/cli-engine.js:271:26
    at walk (../lib/node_modules/eslint/lib/util/traverse.js:81:9)
    at .../lib/node_modules/eslint/lib/util/traverse.js:102:9

space-before-function-parentheses error

I have the rule space-before-function-parentheses: [2, never] which gives an error when there's a space before the function keyword:

function () {}

But this is also giving the same error:

[1].map(x => x);

semicolon at end of file not detected unless there's a newline

No lint warning

module.exports = "something";

Lint warning about semicolon when there's no newline at EOF

module.exports = "something";
semicolon.js
  1:1   error  Newline required at end of file but not found  eol-last
  1:32  error  Missing semicolon                              semi

โœ– 2 problems (2 errors, 0 warnings)

ES6 class appears as unused despite a code below creating an instance of it.

I was testing ES6 with Babel when I ran into the following problem:

function jello(fn) {
  fn();
}
class Hey {
  constructor() {
    this.name = "John";
  }
  sayHello(partingMessage) {
    jello(() => console.log(`Hello, ${this.name}!`));
    console.log(partingMessage);
  }
}
var h = new Hey();
h.sayHello();

I get this warning:

4:6 error Hey is defined but never used no-unused-vars

โœ– 1 problem (1 error, 0 warnings)

Also, should h.sayHello produce a warning since it's calling it without an argument? Is there an option for that one? :-)

Apparently Espree got a related fix and I also checked out a couple of related bugs. But I couldn't see a code like mine in the samples for the error. Most of them were worried about module exporting instead.

Thanks.

Require semicolon after import statements

I would like to enforce semicolons after import statements.

Example:

import * as utils from './utils'

should be enforced to have a semicolon:

import * as utils from './utils';

Right now, with the semi rule on in eslint, this does not warn or throw an error.

Not sure if this is a eslint issue, babel-eslint issue, or not an issue at all because this rule would never catch this.

JSX html attrs flagged as 'no-undef'

Is it normal for every JSX tag name and attribute to be flagged as no-undef?

Here's a simplified case (extra boilerplate was removed):

var EshintJSXTest = React.createClass({
  render: function() {
    return <div className="foo" />;
  }
});

Running eslint from the command line gives me this:

EshintJSXTest.jsx
   7:16  error  'div' is not defined        no-undef
   7:20  error  'className' is not defined  no-undef

Exempting no-undef rules isn't really a viable workaround, I'd like the linter to inform me about those.

I'm fairly sure babel-eslint is installed correctly, if I remove the "parser" key from .eshintrc I get a JS syntax error at the first JSX bracket.

Type annotations are broken

I think this may be due to a bug in acorn-babel, but when I write:

type F = (x: string, y: Object) => string

I get the following error:

server.js
  24:5   error  'F' is not defined  no-undef
  24:10  error  'x' is not defined  no-undef
  24:21  error  'y' is not defined  no-undef

I tried to run the tests in acorn-babel and they are failing:
(had to fix main in package.json first)

> [email protected] test /Users/evan.simmons/repos/acorn-babel
> node test/run.js

([a.a]) => 42 Expected error message: Assigning to rvalue (1:2)
But parsing succeeded.
((...rest: Array<number>) => rest) {
  "type": "TypeAnnotation",
  "start": 9,
  "end": 24,
  "typeAnnotation": {
    "type": "GenericTypeAnnotation",
    "start": 11,
    "end": 24,
    "typeParameters": {
      "type": "TypeParameterInstantiation",
      "start": 16,
      "end": 24,
      "params": [
        {
          "type": "NumberTypeAnnotation",
          "start": 17,
          "end": 23
        }
      ]
    },
    "id": {
      "type": "Identifier",
      "start": 11,
      "end": 16,
      "name": "Array"
    }
  }
} !== undefined (returnType/0/params/expression/0/body)
var a: (number) SyntaxError: Unexpected token (1:14)
    at raise (/Users/evan.simmons/repos/acorn-babel/acorn.js:343:15)
    at unexpected (/Users/evan.simmons/repos/acorn-babel/acorn.js:2297:5)
    at expect (/Users/evan.simmons/repos/acorn-babel/acorn.js:2285:18)
    at parseFunctionTypeParam (/Users/evan.simmons/repos/acorn-babel/acorn.js:4583:5)
    at parseFunctionTypeParams (/Users/evan.simmons/repos/acorn-babel/acorn.js:4592:23)
    at parsePrimaryType (/Users/evan.simmons/repos/acorn-babel/acorn.js:4707:15)
    at parsePostfixType (/Users/evan.simmons/repos/acorn-babel/acorn.js:4743:35)
    at parsePrefixType (/Users/evan.simmons/repos/acorn-babel/acorn.js:4758:12)
    at parseIntersectionType (/Users/evan.simmons/repos/acorn-babel/acorn.js:4763:16)
    at parseUnionType (/Users/evan.simmons/repos/acorn-babel/acorn.js:4773:16)
var a: number & (string | bool) SyntaxError: Unexpected token (1:24)
    at raise (/Users/evan.simmons/repos/acorn-babel/acorn.js:343:15)
    at unexpected (/Users/evan.simmons/repos/acorn-babel/acorn.js:2297:5)
    at expect (/Users/evan.simmons/repos/acorn-babel/acorn.js:2285:18)
    at parseFunctionTypeParam (/Users/evan.simmons/repos/acorn-babel/acorn.js:4583:5)
    at parseFunctionTypeParams (/Users/evan.simmons/repos/acorn-babel/acorn.js:4592:23)
    at parsePrimaryType (/Users/evan.simmons/repos/acorn-babel/acorn.js:4707:15)
    at parsePostfixType (/Users/evan.simmons/repos/acorn-babel/acorn.js:4743:35)
    at parsePrefixType (/Users/evan.simmons/repos/acorn-babel/acorn.js:4758:12)
    at parseIntersectionType (/Users/evan.simmons/repos/acorn-babel/acorn.js:4766:23)
    at parseUnionType (/Users/evan.simmons/repos/acorn-babel/acorn.js:4773:16)
function bar<T: ?number>() {} [] !== undefined (defaults/0/body)
Normal parser: 1104 tests run in 161ms; 5 failures.
Total: 1104 tests run in 161ms; 5 failures.

Comma spacing issue with JSX

I get a warning with commas in JSX:

      413:72  error  A space is required after ','            comma-spacing

An example:

var X = React.createClass({

    render: function () {
        var hello = "Hello";
        var world = "World";
        return <span>{hello}, {world}</span>;
    }

});

TypeError `no-shadow-restricted-names`

[...]/node_modules/eslint/lib/rules/no-shadow-restricted-names.js:17
        if (RESTRICTED.indexOf(id.name) > -1) {
                                 ^
TypeError: Cannot read property 'name' of null
    at checkForViolation ([...]/node_modules/eslint/lib/rules/no-shadow-restricted-names.js:17:34)
    at EventEmitter.FunctionDeclaration ([...]/node_modules/eslint/lib/rules/no-shadow-restricted-names.js:39:13)
    at EventEmitter.emit (events.js:129:20)
    at Controller.controller.traverse.enter ([...]/node_modules/eslint/lib/eslint.js:735:25)
    at Controller.__execute ([...]/node_modules/eslint/node_modules/estraverse/estraverse.js:393:31)
    at Controller.traverse ([...]/node_modules/eslint/node_modules/estraverse/estraverse.js:491:28)
    at EventEmitter.module.exports.api.verify ([...]/node_modules/eslint/lib/eslint.js:728:24)
    at processFile ([...]/node_modules/eslint/lib/cli-engine.js:193:27)
    at [...]/node_modules/eslint/lib/cli-engine.js:293:26
    at [...]/node_modules/eslint/lib/util/traverse.js:61:17

Linted code: index.js

Chocking on the export default function ().

React is defined but never used

Not sure if it's the same as #5.

I get

error  React is defined but never used         no-unused-vars

in a JS file that doesn't reference React directly, but uses JSX (and thus needs to have React in scope).

TypeError: Cannot read property 'name'/'type' of undefined

I tried upgrading to ESLint 0.17 and latest babel-eslint and got a load of crashes, almost in each file where I use ES6 module syntax.

First one:

/usr/local/lib/node_modules/eslint/lib/rules/no-func-assign.js:42
                if (def.name.name === name && def.type === "FunctionName") {
                            ^
TypeError: Cannot read property 'name' of undefined
    at checkIfIdentifierIsFunction (/usr/local/lib/node_modules/eslint/lib/rules/no-func-assign.js:42:29)
    at checkIfIdentifierIsFunction (/usr/local/lib/node_modules/eslint/lib/rules/no-func-assign.js:56:20)

on

import shallowEqual from 'react/lib/shallowEqual';

export default function(spec) {
  return {
    getInitialState() {
      this.subscribe((key, value) => {
        data[key] = value;
      });
    }
  }
};

Next one:

/usr/local/lib/node_modules/eslint/lib/rules/no-unused-vars.js:43
            if (definition.type === "VariableDeclarator") {
                          ^
TypeError: Cannot read property 'type' of undefined
    at isExported (/usr/local/lib/node_modules/eslint/lib/rules/no-unused-vars.js:43:27)
    at EventEmitter.Program:exit (/usr/local/lib/node_modules/eslint/lib/rules/no-unused-vars.js:120:70)
    at emitOne (events.js:82:20)
    at EventEmitter.emit (events.js:166:7)

on

import shallowEqual from 'react/lib/shallowEqual';

export default function(spec) {
  return {
    getInitialState() {
    }
  };
};

Arrow Functions incorrectly trigger errors on func-names & space-before-blocks

When I run

$ ./node_modules/.bin/eslint index.js --format=compact

I get the error:

index.js: line 2, col 14, Warning - Missing function expression name. (func-names)
index.js: line 2, col 14, Warning - Missing space before opening brace. (space-before-blocks)

2 problems

index.js:

'use strict';
[1, 2, 3].map(i => i * 2);

func-names

The grammar for Arrow Functions doesn't appear to allow for names. So, func-names should not be checked against at all.

space-before-blocks

The function is not a block (at least, according what the documentation on eslint rules considers a block).

It should be noted that this error goes away when I do actually use the block format of arrow functions:

'use strict';
[1, 2, 3].map((i) => {
  return i * 2;
});

Additional Details

.eslintrc:

{ "parser": "babel-eslint" }

package.json:

{
  ...
  "dependencies": {
    "babel": "^4.6.5",
    "babel-eslint": "babel/babel-eslint#master",
    "eslint": "^0.15.1"
  }
}

Breaks prefs.enabled(enabled => enabled && _run())

It breaks on such code

prefs.enabled(enabled => enabled && _run())

outout

/Users/kigorw/.nvm/v0.10.26/lib/node_modules/eslint/lib/rules/strict.js:33
    for (i = 0; i < statements.length; i++) {
                              ^
TypeError: Cannot read property 'length' of undefined
    at getUseStrictDirectives (/Users/kigorw/.nvm/v0.10.26/lib/node_modules/eslint/lib/rules/strict.js:33:31)
    at EventEmitter.modes.never.FunctionExpression (/Users/kigorw/.nvm/v0.10.26/lib/node_modules/eslint/lib/rules/strict.js:156:20)
    at EventEmitter.emit (events.js:117:20)
    at Controller.controller.traverse.enter (/Users/kigorw/.nvm/v0.10.26/lib/node_modules/eslint/lib/eslint.js:683:25)
    at Controller.__execute (/Users/kigorw/.nvm/v0.10.26/lib/node_modules/eslint/node_modules/estraverse/estraverse.js:397:31)
    at Controller.traverse (/Users/kigorw/.nvm/v0.10.26/lib/node_modules/eslint/node_modules/estraverse/estraverse.js:495:28)
    at EventEmitter.module.exports.api.verify (/Users/kigorw/.nvm/v0.10.26/lib/node_modules/eslint/lib/eslint.js:676:24)
    at processFile (/Users/kigorw/.nvm/v0.10.26/lib/node_modules/eslint/lib/cli-engine.js:172:23)
    at /Users/kigorw/.nvm/v0.10.26/lib/node_modules/eslint/lib/cli-engine.js:271:26
    at walk (/Users/kigorw/.nvm/v0.10.26/lib/node_modules/eslint/lib/util/traverse.js:81:9)
k:lib kigorw$ eslint app.js

Super is not defined in ES6 classes

Given the code

import Service from './Service';

export default class AService extends Service {

  constructor(config) {
    super(config);
  }

}

output is

6:4  error  'super' is not defined  no-undef

error 'App' is not defined no-undef

Hi,

I get the following error:

var App = React.createClass({
  render: function() {
    return (
      <div>
        <h3>My Component Example</h3>
        <MyComponent />
      </div>
    );
  }
});

React.render(<App />, document.getElementById('app'));    // error  'App' is not defined  no-undef

Here is my .eslintrc file:

{
  "env": {
    "node": true,
    "browser": true
  },
  "parser": "babel-eslint",
  "rules": {
    "space-after-keywords": "always",
    "quotes": "single"
  }
}

I use babel-loader to run eslint with WebPack. Here is the relevant bit from webpack.config.js:

module: {
  loaders: [
    { test: /\.js$/, loaders: ["react-hot", "babel-loader", "eslint-loader"], exclude: /node_modules/ }
  ]
}

What am I doing wrong?

Error when short-hand fat arrow func used with `"strict": [1, "global"]` rule

When I run

$ ./node_modules/.bin/eslint index.js

I get the error:

$ ./node_modules/.bin/eslint index.js
/dev/node_modules/eslint/lib/rules/strict.js:33
    for (i = 0; i < statements.length; i++) {
                              ^
TypeError: Cannot read property 'length' of undefined
    at getUseStrictDirectives (/dev/node_modules/eslint/lib/rules/strict.js:33:31)
    at EventEmitter.modes.global.FunctionExpression (/dev/node_modules/eslint/lib/rules/strict.js:178:20)
    at EventEmitter.emit (events.js:120:20)
    at Controller.controller.traverse.enter (/dev/node_modules/eslint/lib/eslint.js:683:25)
    at Controller.__execute (/dev/node_modules/eslint/node_modules/estraverse/estraverse.js:397:31)
    at Controller.traverse (/dev/node_modules/eslint/node_modules/estraverse/estraverse.js:495:28)
    at EventEmitter.module.exports.api.verify (/dev/node_modules/eslint/lib/eslint.js:676:24)
    at processFile (/dev/node_modules/eslint/lib/cli-engine.js:172:23)
    at /dev/node_modules/eslint/lib/cli-engine.js:271:26
    at walk (/dev/node_modules/eslint/lib/util/traverse.js:81:9)

index.js:

'use strict';
var foo = bar => bar.zip;

.eslintrc:

{
  "parser": "babel-eslint",
  "rules": {
    "strict": [1, "global"]
  }
}

package.json:

{
  ...
  "dependencies": {
    "babel": "^4.6.5",
    "babel-eslint": "^1.0.12",
    "eslint": "^0.15.1"
  }
}

Note that babel correctly understands the shorthand fat arrow syntax when compiling:

$ ./node_modules/.bin/babel index.js
"use strict";

var foo = function (bar) {
  return bar.zip;
};

Crash with arrow functions and strict rule

Moving this from eslint/eslint#1906.

$ mkdir test
$ cd test
$ npm i eslint babel-eslint

Save the following files in the test directory:

// test.js
'use strict';

() => foo;
// config-espree.json
{
    "rules": {
        "strict": [2, "global"]
    },
    "ecmaFeatures": {
        "arrowFunctions": true
    }
}
// config-babel.json
{
    "parser": "babel-eslint",
    "rules": {
        "strict": [2, "global"]
    }
}

Then run ESLint using each config:

$ node_modules/.bin/eslint --reset --no-eslintrc -c config-espree.json test.js

$ node_modules/.bin/eslint --reset --no-eslintrc -c config-babel.json test.js
~/code/babel/babel-eslint-test/node_modules/eslint/lib/rules/strict.js:33
    for (i = 0; i < statements.length; i++) {
                              ^
TypeError: Cannot read property 'length' of undefined
    at getUseStrictDirectives (~/code/babel/babel-eslint-test/node_modules/eslint/lib/rules/strict.js:33:31)
    at EventEmitter.modes.global.FunctionExpression (~/code/babel/babel-eslint-test/node_modules/eslint/lib/rules/strict.js:178:20)
    at EventEmitter.emit (events.js:107:17)
    at Controller.controller.traverse.enter (~/code/babel/babel-eslint-test/node_modules/eslint/lib/eslint.js:683:25)
    at Controller.__execute (~/code/babel/babel-eslint-test/node_modules/eslint/node_modules/estraverse/estraverse.js:397:31)
    at Controller.traverse (~/code/babel/babel-eslint-test/node_modules/eslint/node_modules/estraverse/estraverse.js:495:28)
    at EventEmitter.module.exports.api.verify (~/code/babel/babel-eslint-test/node_modules/eslint/lib/eslint.js:676:24)
    at processFile (~/code/babel/babel-eslint-test/node_modules/eslint/lib/cli-engine.js:172:23)
    at ~/code/babel/babel-eslint-test/node_modules/eslint/lib/cli-engine.js:271:26
    at walk (~/code/babel/babel-eslint-test/node_modules/eslint/lib/util/traverse.js:81:9

Perhaps because the ArrowFunctionExpression is getting turned into a FunctionExpression?

no-unused-vars for jsx

First, thank you for babel-eslint: it's like a dream ๐Ÿ‘

The following code warns for Router is defined but never used (no-unused-vars):

import Router from 'react-router';
export default (
  <Router.Route name="app" path="/" />
);

It seems happening when using JSX outside a React.createClass(). Is there a way to make eslint recognizing the use of the var?

arrow functions parameters scope

something(e) {
  ...
  console.log(e.target);

  reader.addEventListener('load', e => {
    console.log(e.target);
  }, false);

  ...
}

In the example above e parameter in arrow function belongs to arrow function scope and not interfering with e parameter in the upper scope. But I'm having an error:

25:45  error    e is already declared in the upper scope  no-shadow

Multiple destructure assignment leads to `no-dupe-keys`

Given

import React from 'react';

const st = {
  x: {},
  y: {},
  z: {}
};

let Component = React.createClass({

  render() {
    const style = {
      ...st.x,
      ...st.y,
      ...st.z
    };
    return <div style={style} />;
  }

});

module.exports = Component;

leads to

  12:18  error  Duplicate key 'undefined'  no-dupe-keys
  12:18  error  Duplicate key 'undefined'  no-dupe-keys

no-unused-vars, no-undef errors in simple ES6 class / react example

index_es6.js (using the react 0.13 syntax)

'use strict';

import React from 'react';

class HelloMessage extends React.Component {
  render() {
    return <div>Hello {this.props.name}</div>;
  }
}

React.render(<HelloMessage name="Sebastian" />, document.body);

eslint output (using eslint-babel):

index_es6.js
   5:6   error  HelloMessage is defined but never used  no-unused-vars
  11:14  error  'HelloMessage' is not defined           no-undef

index_es5.js

'use strict';

var React = require('react');

var HelloMessage = React.createClass({
    render: function () {
        return <div>Hello {this.props.name}</div>;
    }
});

React.render(<HelloMessage name="Sebastian" />, document.body);

eslint output (using eslint-babel):

src/app/index_old.js
  11:14  error  'HelloMessage' is not defined  no-undef

Is this an issue or am I doing something stupid here?

Externalize acorn-to-esprima?

Would you be open to publishing acorn-to-esprima as it's own package? I had something like this half done and would love to just drop it and use what you have. I think it would be useful for a number of tools that would like to support both acorn and esprima.

"is not defined" for ...rest arguments

function createStoreMixin(...stores) {
  var StoreMixin = {
    componentDidMount() {
      this.stores = stores;

will say stores is not defined. This happens in any method with ...rest arguments.

Imported symbols are erroneously detected undefined when using JSX

import App from "./components/App";

React.render(<App />, document.querySelector("#app"));

Gives:

26:14  error  'App' is not defined  no-undef

Also,

import App from "./components/App";

React.render(App(), document.querySelector("#app"));

makes it going away, so it's a JSX-related thingy.

Exporting destructured assignment causes no-undef

This is a bit of an edge case, but I'm currently dealing with some variables that are on the window that I want to wrap up for browserify. I created a WindowService like the following:

/*global window*/

export default {
  foo,
  bar,
  baz
} = window

but I'm getting the following errors when I lint:

 app/services/window.js
  4:6  error  'foo' is not defined  no-undef
  5:6  error  'bar' is not defined  no-undef
  6:6  error  'baz' is not defined  no-undef

Seems similar to but distinct from #56.

How do I parse async/await?

I can't seem to get this to properly parse async/await. I'm getting the following error:

'async' is not defined

Here's my .eslintrc:

{
  "env": {
    "node": true,
  },
  "parser": "babel-eslint"
}

Here's the code that fails:

async function foo() {}

FWIW, there's a .babelrc in the same directory:

{
  "experimental": true
}

vars-on-top module issue

I see the following error:

app.js
  8:0  error  All "var" declarations must be at the top of the function scope  vars-on-top

With this code:

import Ember from 'ember';
import Resolver from 'ember/resolver';
import loadInitializers from 'ember/load-initializers';
import config from './config/environment';

Ember.MODEL_FACTORY_INJECTIONS = true;

var App = Ember.Application.extend({
  modulePrefix: config.modulePrefix,
  podModulePrefix: config.podModulePrefix,
  Resolver: Resolver
});

loadInitializers(App, config.modulePrefix);

export default App;

This silences the error however certainly looks wrong:

var App;
import Ember from 'ember';
import Resolver from 'ember/resolver';
import loadInitializers from 'ember/load-initializers';
import config from './config/environment';

Ember.MODEL_FACTORY_INJECTIONS = true;

App = Ember.Application.extend({
  modulePrefix: config.modulePrefix,
  podModulePrefix: config.podModulePrefix,
  Resolver: Resolver
});

loadInitializers(App, config.modulePrefix);

export default App;

I'm not really sure if this should be raised here or part of ESLint itself or if it will just resolve itself when ESLint supports import natively soon, however I just thought I would track the progress here.

brace-style error

Introduced in 1.0.13 (no problem in 1.0.12)

Source code:

listeners.forEach(callback => callback.apply(null, args));

Produce this error:

64:32  error  Statement inside of curly braces should be on next line  brace-style

Install babel-eslint as dev-dependency

In the spirit of keeping all my dependencies in my package.json I'd much rather have babel-eslint in my package.json as a dev-dependency than having to install it -g. Reading eslint's guide this seems to be possible, but I cannot make it work, and the README instructs to install globally - why?

Cheers

Variable of array comprehension not defined

let a = [], b = [for (e of a) String(e)];

results in:

  1:12  error  b is defined but never used  no-unused-vars
  1:22  error  'e' is not defined           no-undef
  1:37  error  'e' is not defined           no-undef

`space-infix-ops` is broken

var i = 0, a = 1, b = 2;
console.log(i-a);
console.log(i+a);
console.log(i>a);
console.log(i<a);
console.log(i<=a);
console.log(i>=a);
console.log(i>=a);
console.log(i^a);
console.log(i?a:b);

This produces no warnings when using babel-eslint as a parser and the space-infix-ops rule.
However, the rule will still produce warnings with operators such as *, =, +=, etc.

Support for comments

I wanted to use the rule no-warning-comments, however the ast doesn't have the comment node when passed to ESLint.
Is there any plan to support comments?
I wanted to try it out myself, but I don't know well enough the ast structure to add node to it. I saw that all the comments are available on ast.comments, but are not used in acornToEsprima

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.