Skip to content

Instantly share code, notes, and snippets.

@esnya
Last active February 15, 2016 11:32
Show Gist options
  • Select an option

  • Save esnya/6e7ab3d94c8d240696a7 to your computer and use it in GitHub Desktop.

Select an option

Save esnya/6e7ab3d94c8d240696a7 to your computer and use it in GitHub Desktop.
ESLint/Espree breaks Acorn?
'use strict';
/*
* syntax-error erroed after eslint executed.
*
* acorn@2.7.0
* eslint@2.0.0
* babel-eslint@4.1.8
*/
const aparse = require('acorn').parse;
const eslint = require('eslint');
function parse(src) {
return aparse(src, {
ecmaVersion: 6,
allowHashBang: true,
});
}
function lint() {
const fs = require('fs');
const config = {
extends: 'eslint:recommended',
parser: 'babel-eslint',
parserOptions: {
ecmaFeatures: {
ecmaVersion: 6,
},
},
env: {
node: true,
},
rules: {
'no-console': 1,
},
};
const linter = new eslint.CLIEngine(config);
const formatter = eslint.CLIEngine.getFormatter('stylish');
const file = __filename;
const res = linter.executeOnText(String(fs.readFileSync(file)), file);
console.log(formatter(res.results, config));
}
try {
aparse('foo bar');
} catch (e) {
console.dir(e);
}
lint();
try {
aparse('foo bar');
} catch (e) {
console.dir(e); // OK!
}
'use strict';
/*
* syntax-error erroed after eslint executed.
*
* acorn@2.7.0
* eslint@2.0.0
*/
const aparse = require('acorn').parse;
const eslint = require('eslint');
function parse(src) {
return aparse(src, {
ecmaVersion: 6,
allowHashBang: true,
});
}
function lint() {
const fs = require('fs');
const config = {
extends: 'eslint:recommended',
parserOptions: {
ecmaFeatures: {
ecmaVersion: 6,
},
},
env: {
node: true,
},
rules: {
'no-console': 1,
},
};
const linter = new eslint.CLIEngine(config);
const formatter = eslint.CLIEngine.getFormatter('stylish');
const file = __filename;
const res = linter.executeOnText(String(fs.readFileSync(file)), file);
console.log(formatter(res.results, config));
}
try {
aparse('foo bar');
} catch (e) {
console.dir(e); // { [SyntaxError: Unexpected token (1:4)] pos: 4, loc: Position { line: 1, column: 4 }, raisedAt: 7 }
}
lint();
try {
aparse('foo bar');
} catch (e) {
console.dir(e); // [TypeError: Cannot read property '1' of undefined]
}
'use strict';
/*
* syntax-error erroed after eslint executed.
*
* eslint@2.0.0
* syntax-error@1.1.5
*/
const syntaxError = require('syntax-error');
const eslint = require('eslint');
function lint() {
const fs = require('fs');
const config = {
extends: 'eslint:recommended',
parserOptions: {
ecmaFeatures: {
ecmaVersion: 6,
},
},
env: {
node: true,
},
rules: {
'no-console': 1,
},
};
const linter = new eslint.CLIEngine(config);
const formatter = eslint.CLIEngine.getFormatter('stylish');
const file = __filename;
const res = linter.executeOnText(String(fs.readFileSync(file)), file);
console.log(formatter(res.results, config));
}
console.log(syntaxError('foo bar'));
console.log(syntaxError('foo bar'));
lint();
console.log(syntaxError('foo bar')); // TypeError
'use strict';
/*
* syntax-error erroed after espree included.
*
* acorn@2.7.0
* espree@3.0.1
*/
const aparse = require('acorn').parse;
function parse(src) {
return aparse(src, {
ecmaVersion: 6,
allowHashBang: true,
});
}
try {
aparse('foo bar');
} catch (e) {
console.dir(e); // { [SyntaxError: Unexpected token (1:4)] pos: 4, loc: Position { line: 1, column: 4 }, raisedAt: 7 }
}
require('espree');
try {
aparse('foo bar');
} catch (e) {
console.dir(e); // [TypeError: Cannot read property 'ecmaFeatures' of undefined]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment