Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Commit

Permalink
Misc: use babel-jscs for the esnext option
Browse files Browse the repository at this point in the history
Fixes #1353
  • Loading branch information
hzoo authored and markelog committed Jul 7, 2015
1 parent 5cfea59 commit 431b723
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions OVERVIEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ jscs path[ path[...]] --reporter=./some-dir/my-reporter.js
```

### `--esnext` (`-e`)
Attempts to parse your code as ES6 using the harmony version of the esprima parser. Please note that this is currently experimental, and will improve over time.
Attempts to parse your code as ES6+, JSX, and Flow using the babel-jscs package as the parser. Please note that this is experimental, and will improve over time.

### `--esprima` (`-s`)
Attempts to parse your code with a custom Esprima version.
Expand Down Expand Up @@ -242,7 +242,7 @@ Default: Infinity

### esnext

Attempts to parse your code as ES6 using the harmony version of the esprima parser.
Attempts to parse your code as ES6+, JSX, and Flow using the babel-jscs package as the parser. Please note that this is experimental, and will improve over time.

Type: `Boolean`

Expand Down
6 changes: 3 additions & 3 deletions lib/string-checker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var defaultEsprima = require('esprima');
var harmonyEsprima = require('esprima-harmony-jscs');
var babelJscs = require('babel-jscs');
var Errors = require('./errors');
var JsFile = require('./js-file');
var Configuration = require('./config/configuration');
Expand Down Expand Up @@ -31,7 +31,7 @@ var StringChecker = function(options) {
} else {
options = options || {};
this._verbose = options.verbose || false;
this._esprima = options.esprima || (options.esnext ? harmonyEsprima : defaultEsprima);
this._esprima = options.esprima || (options.esnext ? babelJscs : defaultEsprima);
}
};

Expand Down Expand Up @@ -72,7 +72,7 @@ StringChecker.prototype = {
if (this._configuration.hasCustomEsprima()) {
this._esprima = this._configuration.getCustomEsprima();
} else if (this._configuration.isESNextEnabled()) {
this._esprima = harmonyEsprima;
this._esprima = babelJscs;
}

if (this._verbose === false) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@
"node": ">= 0.10.0"
},
"dependencies": {
"babel-jscs": "^1.0.1",
"chalk": "~1.0.0",
"cli-table": "~0.3.1",
"commander": "~2.8.1",
"esprima": "~2.4.0",
"esprima-harmony-jscs": "1.1.0-bin",
"estraverse": "^1.9.3",
"exit": "~0.1.2",
"glob": "^5.0.1",
Expand Down
2 changes: 1 addition & 1 deletion test/data/cli/esprima.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"disallowKeywords": ["with"],
"esprima": "esprima-harmony-jscs"
"esprima": "babel-jscs"
}
2 changes: 1 addition & 1 deletion test/specs/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ describe('modules/cli', function() {
it('should use a custom esprima provided at CLI', function() {
return assertNoCliErrors(cli({
args: ['test/data/cli/esnext.js'],
esprima: 'esprima-harmony-jscs',
esprima: 'babel-jscs',
config: 'test/data/cli/cli.json'
}));
});
Expand Down
4 changes: 2 additions & 2 deletions test/specs/config/node-configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('modules/config/node-configuration', function() {
preset: 'jquery',
maxErrors: '2',
errorFilter: path.resolve(__dirname, '../../data/error-filter.js'),
esprima: 'esprima-harmony-jscs',
esprima: 'babel-jscs',
es3: true,
verbose: true,
esnext: true
Expand Down Expand Up @@ -86,7 +86,7 @@ describe('modules/config/node-configuration', function() {

it('should accept `esprima` to register different esprima', function() {
configuration.load({
esprima: 'esprima-harmony-jscs'
esprima: 'babel-jscs'
});

assert.equal(configuration.hasCustomEsprima(), true);
Expand Down
14 changes: 7 additions & 7 deletions test/specs/js-file.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var assert = require('assert');
var esprima = require('esprima');
var harmonyEsprima = require('esprima-harmony-jscs');
var babelJscs = require('babel-jscs');
var JsFile = require('../../lib/js-file');
var sinon = require('sinon');
var fs = require('fs');
Expand All @@ -18,11 +18,11 @@ describe('modules/js-file', function() {
return new JsFile(assign(params, options));
}

function createHarmonyJsFile(sources) {
function createBabelJsFile(sources) {
return new JsFile({
filename: 'example.js',
source: sources,
esprima: harmonyEsprima,
esprima: babelJscs,
es6: true
});
}
Expand Down Expand Up @@ -311,7 +311,7 @@ describe('modules/js-file', function() {
describe('iterateNodesByType', function() {
it('should handle ES6 export keyword', function() {
var spy = sinon.spy();
createHarmonyJsFile('export function foo() { var a = "b"; };')
createBabelJsFile('export function foo() { var a = "b"; };')
.iterateNodesByType('VariableDeclaration', spy);
assert(spy.calledOnce);
});
Expand Down Expand Up @@ -348,13 +348,13 @@ describe('modules/js-file', function() {

it('should not have duplicate tokens in es6 export default statements', function() {
var spy = sinon.spy();
createHarmonyJsFile('export default function() {}').iterateTokenByValue('(', spy);
createBabelJsFile('export default function() {}').iterateTokenByValue('(', spy);
assert(spy.calledOnce);
});

it('should not have duplicate tokens in es6 export default statements', function() {
var spy = sinon.spy();
createHarmonyJsFile('export default function init() {\n' +
createBabelJsFile('export default function init() {\n' +
' window.addEventListener(\'fb-flo-reload\', function(ev) {\n' +
' });\n' +
'}').iterateTokenByValue('(', spy);
Expand Down Expand Up @@ -1153,7 +1153,7 @@ describe('modules/js-file', function() {
fs.readdirSync(absDirPath).forEach(function(filename) {
it('file ' + relativeDirPath + '/' + filename + ' should be rendered correctly', function() {
var source = fs.readFileSync(absDirPath + '/' + filename, 'utf8');
var file = createHarmonyJsFile(source);
var file = createBabelJsFile(source);
assert.equal(file.render(), source);
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/specs/string-checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,15 @@ describe('modules/string-checker', function() {
assert(error.message === customDescription);
});

it('uses the harmony esprima when true is provided to the constructor', function() {
it('uses babel-jscs when true is provided to the constructor', function() {
checker = new StringChecker({ esnext: true });
checker.registerDefaultRules();

var errors = checker.checkString('import { foo } from "bar";');
assert(errors.isEmpty());
});

it('uses the harmony esprima when esnext is set to true in the config', function() {
it('uses babel-jscs when esnext is set to true in the config', function() {
checker = new StringChecker();
checker.registerDefaultRules();
checker.configure({ esnext: true });
Expand Down

0 comments on commit 431b723

Please sign in to comment.