Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using babel-eslint as parser for esnext #3

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion esnext.js
@@ -1,6 +1,10 @@
'use strict';
var def = require('./');

def.parser = 'babel-eslint';

def.plugins = ['babel'];

def.ecmaFeatures = {
arrowFunctions: true,
binaryLiterals: true,
Expand Down Expand Up @@ -29,11 +33,18 @@ def.ecmaFeatures = {

def.env.es6 = true;
def.rules['no-var'] = 2;
def.rules['object-shorthand'] = [2, 'always'];
def.rules['prefer-arrow-callback'] = 2;
def.rules['prefer-const'] = 2;
def.rules['prefer-reflect'] = [2, {exceptions: ['delete']}];
def.rules['prefer-template'] = 2;
def.rules['prefer-spread'] = 2;
def.rules['babel/object-shorthand'] = [2, 'always'];
def.rules['babel/generator-star-spacing'] = def.rules['generator-star-spacing'];
def.rules['babel/arrow-parens'] = def.rules['arrow-parens'];
def.rules['babel/object-curly-spacing'] = def.rules['object-curly-spacing'];
def.rules['object-shorthand'] = 0;
def.rules['generator-star-spacing'] = 0;
def.rules['arrow-parens'] = 0;
def.rules['object-curly-spacing'] = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is all this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly to support async/await, but see eslint-plugin-babel readme for more reasons.


module.exports = def;
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -53,7 +53,9 @@
"clear-require": "^1.0.1",
"eslint": "^1.3.0",
"is-plain-obj": "^1.0.0",
"temp-write": "^1.1.2"
"temp-write": "^1.1.2",
"babel-eslint": "^4.1.0",
"eslint-plugin-babel": "^2.1.1"
},
"peerDependencies": {
"eslint": ">=1.3.0"
Expand Down
10 changes: 9 additions & 1 deletion readme.md
Expand Up @@ -11,6 +11,14 @@ This is for advanced users. You probably want to use XO directly.
$ npm install --save-dev eslint-config-xo
```

For the `esnext` version you'll also need Babel's ESLint [parser](https://github.com/babel/babel-eslint) and [plugin](https://github.com/babel/eslint-plugin-babel):

```
$ npm install --save-dev babel-eslint eslint-plugin-babel
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe mention below here some of the benefits with using the Babel parser. ES7 stuff, async/await, etc. So the user has some incentive to do the extra work.

```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annoying that this is needed. Could use some support on: eslint/eslint#3458

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't agree more!
In the case of XO, XO itself will depend on babel-eslint and eslint-plugin-babel to solve this (in my upcoming PR). What do you think about that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's what I'm thinking too, but still doesn't solve it for people using this directly...


This will let you use ES7/ES2016 features like [`async`/`await`](https://github.com/lukehoban/ecmascript-asyncawait) and [decorators](https://github.com/wycats/javascript-decorators). For a full list of features see [Babel's experimental features](https://babeljs.io/docs/usage/experimental/) and their [Learn ES2015](https://babeljs.io/docs/learn-es2015/).


## Usage

Expand All @@ -33,7 +41,7 @@ Or to `.eslintrc`:
}
```

This package also exposes [`xo/esnext`](esnext.js) if you want ES2015 support and rules:
This package also exposes [`xo/esnext`](esnext.js) if you want ES2015+ support and rules:

```json
{
Expand Down
25 changes: 22 additions & 3 deletions test/test.js
Expand Up @@ -5,6 +5,10 @@ var eslint = require('eslint');
var tempWrite = require('temp-write');
var clearRequire = require('clear-require');

function clearRequires() {
['./', './esnext', './browser'].map(clearRequire);
}

function runEslint(str, conf) {
var linter = new eslint.CLIEngine({
useEslintrc: false,
Expand All @@ -15,7 +19,7 @@ function runEslint(str, conf) {
}

test('main', function (t) {
clearRequire.all();
clearRequires();
var conf = require('../');

t.true(isPlainObj(conf));
Expand All @@ -30,7 +34,7 @@ test('main', function (t) {
});

test('esnext', function (t) {
clearRequire.all();
clearRequires();
var conf = require('../esnext');

t.true(isPlainObj(conf));
Expand All @@ -43,8 +47,23 @@ test('esnext', function (t) {
t.end();
});

test('esnext es2016', function (t) {
clearRequires();

var conf = require('../esnext');

t.true(isPlainObj(conf));
t.true(isPlainObj(conf.env));
t.true(isPlainObj(conf.rules));

var errors = runEslint('const x = {a: 0};\nasync function z() {\n\treturn Promise.resolve({b: 1, ...x});\n}\n', conf);
t.is(errors[0].ruleId, 'no-unused-vars');

t.end();
});

test('browser', function (t) {
clearRequire.all();
clearRequires();
var conf = require('../browser');

t.true(isPlainObj(conf));
Expand Down