Merge pull request babel/babel-eslint#706 from kaicataldo/es6
Update ESLint config
This commit is contained in:
parent
40d9bb3a77
commit
22a1681e11
@ -5,12 +5,22 @@ module.exports = {
|
||||
"prettier"
|
||||
],
|
||||
rules: {
|
||||
"no-var": 0,
|
||||
"max-len": 0,
|
||||
"max-len": "off",
|
||||
"strict": "error",
|
||||
"prettier/prettier": "error",
|
||||
},
|
||||
env: {
|
||||
node: true,
|
||||
mocha: true
|
||||
}
|
||||
},
|
||||
parserOptions: {
|
||||
sourceType: "script",
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
files: ["test/**/*"],
|
||||
env: {
|
||||
mocha: true
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
1
eslint/babel-eslint-parser/.npmrc
Normal file
1
eslint/babel-eslint-parser/.npmrc
Normal file
@ -0,0 +1 @@
|
||||
package-lock = false
|
||||
@ -3,8 +3,8 @@
|
||||
// comment fixes
|
||||
module.exports = function(ast, comments, tokens) {
|
||||
if (comments.length) {
|
||||
var firstComment = comments[0];
|
||||
var lastComment = comments[comments.length - 1];
|
||||
const firstComment = comments[0];
|
||||
const lastComment = comments[comments.length - 1];
|
||||
// fixup program start
|
||||
if (!tokens.length) {
|
||||
// if no tokens, the program starts at the end of the last comment
|
||||
@ -17,7 +17,7 @@ module.exports = function(ast, comments, tokens) {
|
||||
}
|
||||
} else if (firstComment.start < tokens[0].start) {
|
||||
// if there are comments before the first token, the program starts at the first token
|
||||
var token = tokens[0];
|
||||
const token = tokens[0];
|
||||
// ast.start = token.start;
|
||||
// ast.loc.start.line = token.loc.start.line;
|
||||
// ast.loc.start.column = token.loc.start.column;
|
||||
@ -25,18 +25,18 @@ module.exports = function(ast, comments, tokens) {
|
||||
// estraverse do not put leading comments on first node when the comment
|
||||
// appear before the first token
|
||||
if (ast.body.length) {
|
||||
var node = ast.body[0];
|
||||
const node = ast.body[0];
|
||||
node.leadingComments = [];
|
||||
var firstTokenStart = token.start;
|
||||
var len = comments.length;
|
||||
for (var i = 0; i < len && comments[i].start < firstTokenStart; i++) {
|
||||
const firstTokenStart = token.start;
|
||||
const len = comments.length;
|
||||
for (let i = 0; i < len && comments[i].start < firstTokenStart; i++) {
|
||||
node.leadingComments.push(comments[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
// fixup program end
|
||||
if (tokens.length) {
|
||||
var lastToken = tokens[tokens.length - 1];
|
||||
const lastToken = tokens[tokens.length - 1];
|
||||
if (lastComment.end > lastToken.end) {
|
||||
// If there is a comment after the last token, the program ends at the
|
||||
// last token and not the comment
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = function(comments) {
|
||||
for (var i = 0; i < comments.length; i++) {
|
||||
var comment = comments[i];
|
||||
for (let i = 0; i < comments.length; i++) {
|
||||
const comment = comments[i];
|
||||
if (comment.type === "CommentBlock") {
|
||||
comment.type = "Block";
|
||||
} else if (comment.type === "CommentLine") {
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
var attachComments = require("./attachComments");
|
||||
var convertComments = require("./convertComments");
|
||||
var toTokens = require("./toTokens");
|
||||
var toAST = require("./toAST");
|
||||
const attachComments = require("./attachComments");
|
||||
const convertComments = require("./convertComments");
|
||||
const toTokens = require("./toTokens");
|
||||
const toAST = require("./toAST");
|
||||
|
||||
module.exports = function(ast, traverse, tt, code) {
|
||||
// convert tokens
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
"use strict";
|
||||
|
||||
var t = require("@babel/types");
|
||||
var convertComments = require("./convertComments");
|
||||
const t = require("@babel/types");
|
||||
const convertComments = require("./convertComments");
|
||||
|
||||
module.exports = function(ast, traverse, code) {
|
||||
var state = { source: code };
|
||||
const state = { source: code };
|
||||
|
||||
// Monkey patch visitor keys in order to be able to traverse the estree nodes
|
||||
t.VISITOR_KEYS.Property = t.VISITOR_KEYS.ObjectProperty;
|
||||
@ -22,10 +22,10 @@ module.exports = function(ast, traverse, code) {
|
||||
delete t.VISITOR_KEYS.MethodDefinition;
|
||||
};
|
||||
|
||||
var astTransformVisitor = {
|
||||
const astTransformVisitor = {
|
||||
noScope: true,
|
||||
enter(path) {
|
||||
var node = path.node;
|
||||
const node = path.node;
|
||||
|
||||
// private var to track original node type
|
||||
node._babelType = node.type;
|
||||
@ -44,7 +44,7 @@ var astTransformVisitor = {
|
||||
}
|
||||
},
|
||||
exit(path) {
|
||||
var node = path.node;
|
||||
const node = path.node;
|
||||
|
||||
if (path.isJSXText()) {
|
||||
node.type = "Literal";
|
||||
@ -98,8 +98,8 @@ var astTransformVisitor = {
|
||||
|
||||
// template string range fixes
|
||||
if (path.isTemplateLiteral()) {
|
||||
for (var j = 0; j < node.quasis.length; j++) {
|
||||
var q = node.quasis[j];
|
||||
for (let j = 0; j < node.quasis.length; j++) {
|
||||
const q = node.quasis[j];
|
||||
q.range[0] -= 1;
|
||||
if (q.tail) {
|
||||
q.range[1] += 1;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = function(token, tt, source) {
|
||||
var type = token.type;
|
||||
const type = token.type;
|
||||
token.range = [token.start, token.end];
|
||||
|
||||
if (type === tt.name) {
|
||||
@ -72,7 +72,7 @@ module.exports = function(token, tt, source) {
|
||||
token.value = source.slice(token.start, token.end);
|
||||
} else if (type === tt.regexp) {
|
||||
token.type = "RegularExpression";
|
||||
var value = token.value;
|
||||
const value = token.value;
|
||||
token.regex = {
|
||||
pattern: value.pattern,
|
||||
flags: value.flags,
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
var convertTemplateType = require("./convertTemplateType");
|
||||
var toToken = require("./toToken");
|
||||
const convertTemplateType = require("./convertTemplateType");
|
||||
const toToken = require("./toToken");
|
||||
|
||||
module.exports = function(tokens, tt, code) {
|
||||
return convertTemplateType(tokens, tt)
|
||||
|
||||
@ -1,16 +1,16 @@
|
||||
"use strict";
|
||||
|
||||
var babylonToEspree = require("./babylon-to-espree");
|
||||
var parse = require("@babel/parser").parse;
|
||||
var tt = require("@babel/parser").tokTypes;
|
||||
var traverse = require("@babel/traverse").default;
|
||||
var codeFrameColumns = require("@babel/code-frame").codeFrameColumns;
|
||||
const babylonToEspree = require("./babylon-to-espree");
|
||||
const parse = require("@babel/parser").parse;
|
||||
const tt = require("@babel/parser").tokTypes;
|
||||
const traverse = require("@babel/traverse").default;
|
||||
const codeFrameColumns = require("@babel/code-frame").codeFrameColumns;
|
||||
|
||||
module.exports = function(code, options) {
|
||||
const legacyDecorators =
|
||||
options.ecmaFeatures && options.ecmaFeatures.legacyDecorators;
|
||||
|
||||
var opts = {
|
||||
const opts = {
|
||||
codeFrame: options.hasOwnProperty("codeFrame") ? options.codeFrame : true,
|
||||
sourceType: options.sourceType,
|
||||
allowImportExportEverywhere: options.allowImportExportEverywhere, // consistent with espree
|
||||
@ -51,7 +51,7 @@ module.exports = function(code, options) {
|
||||
],
|
||||
};
|
||||
|
||||
var ast;
|
||||
let ast;
|
||||
try {
|
||||
ast = parse(code, opts);
|
||||
} catch (err) {
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
var assert = require("assert");
|
||||
var babelEslint = require("..");
|
||||
var espree = require("espree");
|
||||
var escope = require("eslint-scope");
|
||||
var util = require("util");
|
||||
var unpad = require("dedent");
|
||||
var assertImplementsAST = require("./fixtures/assert-implements-ast");
|
||||
"use strict";
|
||||
|
||||
const assert = require("assert");
|
||||
const babelEslint = require("..");
|
||||
const espree = require("espree");
|
||||
const escope = require("eslint-scope");
|
||||
const util = require("util");
|
||||
const unpad = require("dedent");
|
||||
const assertImplementsAST = require("./fixtures/assert-implements-ast");
|
||||
|
||||
function lookup(obj, keypath, backwardsDepth) {
|
||||
if (!keypath) {
|
||||
@ -21,7 +23,7 @@ function lookup(obj, keypath, backwardsDepth) {
|
||||
|
||||
function parseAndAssertSame(code) {
|
||||
code = unpad(code);
|
||||
var esAST = espree.parse(code, {
|
||||
const esAST = espree.parse(code, {
|
||||
ecmaFeatures: {
|
||||
// enable JSX parsing
|
||||
jsx: true,
|
||||
@ -40,14 +42,14 @@ function parseAndAssertSame(code) {
|
||||
ecmaVersion: 2018,
|
||||
sourceType: "module",
|
||||
});
|
||||
var babylonAST = babelEslint.parseForESLint(code, {
|
||||
const babylonAST = babelEslint.parseForESLint(code, {
|
||||
eslintVisitorKeys: true,
|
||||
eslintScopeManager: true,
|
||||
}).ast;
|
||||
try {
|
||||
assertImplementsAST(esAST, babylonAST);
|
||||
} catch (err) {
|
||||
var traversal = err.message.slice(3, err.message.indexOf(":"));
|
||||
const traversal = err.message.slice(3, err.message.indexOf(":"));
|
||||
err.message += unpad(`
|
||||
espree:
|
||||
${util.inspect(lookup(esAST, traversal, 2), {
|
||||
@ -68,7 +70,7 @@ function parseAndAssertSame(code) {
|
||||
describe("babylon-to-espree", () => {
|
||||
describe("compatibility", () => {
|
||||
it("should allow ast.analyze to be called without options", function() {
|
||||
var esAST = babelEslint.parseForESLint("`test`", {
|
||||
const esAST = babelEslint.parseForESLint("`test`", {
|
||||
eslintScopeManager: true,
|
||||
eslintVisitorKeys: true,
|
||||
}).ast;
|
||||
@ -271,7 +273,7 @@ describe("babylon-to-espree", () => {
|
||||
// Espree doesn't support the optional chaining operator yet
|
||||
it("optional chaining operator (token)", () => {
|
||||
const code = "foo?.bar";
|
||||
var babylonAST = babelEslint.parseForESLint(code, {
|
||||
const babylonAST = babelEslint.parseForESLint(code, {
|
||||
eslintVisitorKeys: true,
|
||||
eslintScopeManager: true,
|
||||
}).ast;
|
||||
@ -281,7 +283,7 @@ describe("babylon-to-espree", () => {
|
||||
// Espree doesn't support the nullish coalescing operator yet
|
||||
it("nullish coalescing operator (token)", () => {
|
||||
const code = "foo ?? bar";
|
||||
var babylonAST = babelEslint.parseForESLint(code, {
|
||||
const babylonAST = babelEslint.parseForESLint(code, {
|
||||
eslintVisitorKeys: true,
|
||||
eslintScopeManager: true,
|
||||
}).ast;
|
||||
@ -291,7 +293,7 @@ describe("babylon-to-espree", () => {
|
||||
// Espree doesn't support the pipeline operator yet
|
||||
it("pipeline operator (token)", () => {
|
||||
const code = "foo |> bar";
|
||||
var babylonAST = babelEslint.parseForESLint(code, {
|
||||
const babylonAST = babelEslint.parseForESLint(code, {
|
||||
eslintVisitorKeys: true,
|
||||
eslintScopeManager: true,
|
||||
}).ast;
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
// Checks if the source ast implements the target ast. Ignores extra keys on source ast
|
||||
module.exports = function assertImplementsAST(target, source, path) {
|
||||
if (!path) {
|
||||
@ -5,13 +7,13 @@ module.exports = function assertImplementsAST(target, source, path) {
|
||||
}
|
||||
|
||||
function error(text) {
|
||||
var err = new Error(`At ${path.join(".")}: ${text}:`);
|
||||
const err = new Error(`At ${path.join(".")}: ${text}:`);
|
||||
err.depth = path.length + 1;
|
||||
throw err;
|
||||
}
|
||||
|
||||
var typeA = target === null ? "null" : typeof target;
|
||||
var typeB = source === null ? "null" : typeof source;
|
||||
const typeA = target === null ? "null" : typeof target;
|
||||
const typeB = source === null ? "null" : typeof source;
|
||||
if (typeA !== typeB) {
|
||||
error(
|
||||
`have different types (${typeA} !== ${typeB}) (${target} !== ${source})`
|
||||
@ -26,9 +28,9 @@ module.exports = function assertImplementsAST(target, source, path) {
|
||||
.name} !== ${source.constructor.name}`
|
||||
);
|
||||
} else if (typeA === "object") {
|
||||
var keysTarget = Object.keys(target);
|
||||
for (var i in keysTarget) {
|
||||
var key = keysTarget[i];
|
||||
const keysTarget = Object.keys(target);
|
||||
for (const i in keysTarget) {
|
||||
const key = keysTarget[i];
|
||||
path.push(key);
|
||||
assertImplementsAST(target[key], source[key], path);
|
||||
path.pop();
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
const babelEslint = require("../..")
|
||||
|
||||
// Apply monkeypatch to eslint-scope.
|
||||
|
||||
@ -1,16 +1,18 @@
|
||||
var assert = require("assert");
|
||||
var eslint = require("eslint");
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
"use strict";
|
||||
|
||||
var paths = {
|
||||
const assert = require("assert");
|
||||
const eslint = require("eslint");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const paths = {
|
||||
fixtures: path.join(__dirname, "fixtures", "rules"),
|
||||
};
|
||||
|
||||
var encoding = "utf8";
|
||||
var errorLevel = 2;
|
||||
const encoding = "utf8";
|
||||
const errorLevel = 2;
|
||||
|
||||
var baseEslintOpts = {
|
||||
const baseEslintOpts = {
|
||||
parser: require.resolve(".."),
|
||||
parserOptions: {
|
||||
sourceType: "script",
|
||||
@ -48,10 +50,10 @@ describe("Rules:", () => {
|
||||
// describe
|
||||
|
||||
function strictSuite() {
|
||||
var ruleId = "strict";
|
||||
const ruleId = "strict";
|
||||
|
||||
describe("when set to 'never'", () => {
|
||||
var eslintOpts = Object.assign({}, baseEslintOpts, {
|
||||
const eslintOpts = Object.assign({}, baseEslintOpts, {
|
||||
rules: {},
|
||||
});
|
||||
eslintOpts.rules[ruleId] = [errorLevel, "never"];
|
||||
@ -76,7 +78,7 @@ function strictSuite() {
|
||||
// describe
|
||||
|
||||
describe("when set to 'global'", () => {
|
||||
var eslintOpts = Object.assign({}, baseEslintOpts, {
|
||||
const eslintOpts = Object.assign({}, baseEslintOpts, {
|
||||
rules: {},
|
||||
});
|
||||
eslintOpts.rules[ruleId] = [errorLevel, "global"];
|
||||
@ -152,7 +154,7 @@ function strictSuite() {
|
||||
// describe
|
||||
|
||||
describe("when set to 'function'", () => {
|
||||
var eslintOpts = Object.assign({}, baseEslintOpts, {
|
||||
const eslintOpts = Object.assign({}, baseEslintOpts, {
|
||||
rules: {},
|
||||
});
|
||||
eslintOpts.rules[ruleId] = [errorLevel, "function"];
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*eslint-env mocha*/
|
||||
"use strict";
|
||||
var eslint = require("eslint");
|
||||
var unpad = require("dedent");
|
||||
|
||||
const eslint = require("eslint");
|
||||
const unpad = require("dedent");
|
||||
|
||||
function verifyAndAssertMessagesWithSpecificESLint(
|
||||
code,
|
||||
@ -11,7 +11,7 @@ function verifyAndAssertMessagesWithSpecificESLint(
|
||||
overrideConfig,
|
||||
linter
|
||||
) {
|
||||
var config = {
|
||||
const config = {
|
||||
parser: require.resolve(".."),
|
||||
rules,
|
||||
env: {
|
||||
@ -30,12 +30,12 @@ function verifyAndAssertMessagesWithSpecificESLint(
|
||||
};
|
||||
|
||||
if (overrideConfig) {
|
||||
for (var key in overrideConfig) {
|
||||
for (const key in overrideConfig) {
|
||||
config[key] = overrideConfig[key];
|
||||
}
|
||||
}
|
||||
|
||||
var messages = linter.verify(code, config);
|
||||
const messages = linter.verify(code, config);
|
||||
|
||||
if (messages.length !== expectedMessages.length) {
|
||||
throw new Error(
|
||||
@ -46,7 +46,7 @@ function verifyAndAssertMessagesWithSpecificESLint(
|
||||
}
|
||||
|
||||
messages.forEach((message, i) => {
|
||||
var formatedMessage = `${message.line}:${message.column} ${
|
||||
const formatedMessage = `${message.line}:${message.column} ${
|
||||
message.message
|
||||
}${message.ruleId ? ` ${message.ruleId}` : ""}`;
|
||||
if (formatedMessage !== expectedMessages[i]) {
|
||||
|
||||
@ -4,7 +4,7 @@ const eslint = require("eslint");
|
||||
const assert = require("assert");
|
||||
const babelEslint = require("..");
|
||||
const espree = require("espree");
|
||||
var assertImplementsAST = require("./fixtures/assert-implements-ast");
|
||||
const assertImplementsAST = require("./fixtures/assert-implements-ast");
|
||||
|
||||
describe("https://github.com/babel/babel-eslint/issues/558", () => {
|
||||
it("don't crash with eslint-plugin-import", () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user