[experimental] Add linting step in test pipeline (#1172)
* Add eslint as dev dep, reorder scripts. * Add tests & docs to eslintignore. * Add eslintcache to gitignore. * Update yarn lock file 😽. * Add linting step in the test pipeline. * Add a set of really basic rules for linting. * Fix linting 🚀. * No need for .jsx files to be linted... * Reorder rules alphabetically. * Refine rules: drop styling ones, only keep what provides dead code elimination. * Add no-console rule to be consistent along with the no-debugger one. * Remove empty line. * Add eslint-disable-next-line no-console where console log/warn/error are allowed. * Drop no-console rule. * Remove eslint-disable-next-line no-console comments. * Remove linting step in Travis CI. * Fix linting after merging current master. * Run `npm test -- -u` after noticing one test was out of sync. * Drop eslint references from previous implementation. * Revert yarn lock file. * Revert scripts ordering. * Fix incorrect yarn lock file.master
parent
a7319dbbbb
commit
c609a5415a
|
@ -6,12 +6,10 @@ var n = types.namedTypes;
|
|||
var isArray = types.builtInTypes.array;
|
||||
var isObject = types.builtInTypes.object;
|
||||
var docBuilders = require("./doc-builders");
|
||||
var fromString = docBuilders.fromString;
|
||||
var concat = docBuilders.concat;
|
||||
var hardline = docBuilders.hardline;
|
||||
var breakParent = docBuilders.breakParent;
|
||||
var indent = docBuilders.indent;
|
||||
var align = docBuilders.align;
|
||||
var lineSuffix = docBuilders.lineSuffix;
|
||||
var join = docBuilders.join;
|
||||
var util = require("./util");
|
||||
|
@ -126,7 +124,7 @@ function decorateComment(node, comment, text) {
|
|||
}
|
||||
}
|
||||
|
||||
function attach(comments, ast, text, options) {
|
||||
function attach(comments, ast, text) {
|
||||
if (!isArray.check(comments)) {
|
||||
return;
|
||||
}
|
||||
|
@ -810,7 +808,6 @@ function getQuasiRange(expr) {
|
|||
function printLeadingComment(commentPath, print, options) {
|
||||
const comment = commentPath.getValue();
|
||||
const contents = printComment(commentPath);
|
||||
const text = options.originalText;
|
||||
const isBlock = comment.type === "Block" || comment.type === "CommentBlock";
|
||||
|
||||
// Leading block comments should see if they need to stay on the
|
||||
|
@ -825,7 +822,7 @@ function printLeadingComment(commentPath, print, options) {
|
|||
return concat([contents, hardline]);
|
||||
}
|
||||
|
||||
function printTrailingComment(commentPath, print, options, parentNode) {
|
||||
function printTrailingComment(commentPath, print, options) {
|
||||
const comment = commentPath.getValue();
|
||||
const contents = printComment(commentPath);
|
||||
const isBlock = comment.type === "Block" || comment.type === "CommentBlock";
|
||||
|
@ -864,7 +861,6 @@ function printTrailingComment(commentPath, print, options, parentNode) {
|
|||
}
|
||||
|
||||
function printDanglingComments(path, options, sameIndent) {
|
||||
const text = options.originalText;
|
||||
const parts = [];
|
||||
const node = path.getValue();
|
||||
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
"use strict";
|
||||
|
||||
const utils = require("./doc-utils");
|
||||
const willBreak = utils.willBreak;
|
||||
|
||||
function assertDoc(val) {
|
||||
if (
|
||||
!(typeof val === "string" || (val != null && typeof val.type === "string"))
|
||||
|
|
|
@ -4,7 +4,6 @@ var assert = require("assert");
|
|||
var types = require("ast-types");
|
||||
var util = require("./util");
|
||||
var n = types.namedTypes;
|
||||
var Node = n.Node;
|
||||
var isArray = types.builtInTypes.array;
|
||||
var isNumber = types.builtInTypes.number;
|
||||
|
||||
|
@ -181,7 +180,7 @@ FPp.map = function map(callback /*, name1, name2, ... */) {
|
|||
|
||||
// Inspired by require("ast-types").NodePath.prototype.needsParens, but
|
||||
// more efficient because we're iterating backwards through a stack.
|
||||
FPp.needsParens = function(assumeExpressionContext) {
|
||||
FPp.needsParens = function() {
|
||||
var parent = this.getParentNode();
|
||||
if (!parent) {
|
||||
return false;
|
||||
|
@ -536,10 +535,6 @@ FPp.needsParens = function(assumeExpressionContext) {
|
|||
return false;
|
||||
};
|
||||
|
||||
function isBinary(node) {
|
||||
return n.BinaryExpression.check(node) || n.LogicalExpression.check(node);
|
||||
}
|
||||
|
||||
function containsCallExpression(node) {
|
||||
if (n.CallExpression.check(node)) {
|
||||
return true;
|
||||
|
|
|
@ -29,7 +29,6 @@ var isEmpty = docUtils.isEmpty;
|
|||
var types = require("ast-types");
|
||||
var namedTypes = types.namedTypes;
|
||||
var isString = types.builtInTypes.string;
|
||||
var isObject = types.builtInTypes.object;
|
||||
|
||||
function shouldPrintComma(options, level) {
|
||||
level = level || "es5";
|
||||
|
@ -307,10 +306,10 @@ function genericPrintNoParens(path, options, print, args) {
|
|||
return join(".", n.body);
|
||||
case "Identifier":
|
||||
var parentNode = path.getParentNode()
|
||||
var isFunctionDeclarationIdentifier =
|
||||
var isFunctionDeclarationIdentifier =
|
||||
parentNode.type === 'DeclareFunction' &&
|
||||
parentNode.id === n
|
||||
|
||||
|
||||
return concat([
|
||||
n.name,
|
||||
n.optional ? "?" : "",
|
||||
|
@ -1930,7 +1929,7 @@ function genericPrintNoParens(path, options, print, args) {
|
|||
return concat(parts);
|
||||
case "TSTypeReference":
|
||||
parts.push(path.call(print, "typeName"))
|
||||
|
||||
|
||||
if (n.typeArguments) {
|
||||
parts.push(
|
||||
"<",
|
||||
|
@ -1938,7 +1937,7 @@ function genericPrintNoParens(path, options, print, args) {
|
|||
">"
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
return concat(parts);
|
||||
case "TSCallSignature":
|
||||
return concat([
|
||||
|
@ -2013,14 +2012,14 @@ function genericPrintNoParens(path, options, print, args) {
|
|||
])
|
||||
case "TSTypeParameter":
|
||||
parts.push(path.call(print, "name"))
|
||||
|
||||
|
||||
if (n.constraint) {
|
||||
parts.push(
|
||||
" in ",
|
||||
path.call(print, "constraint")
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
return concat(parts)
|
||||
// TODO
|
||||
case "ClassHeritage":
|
||||
|
@ -2061,7 +2060,6 @@ function genericPrintNoParens(path, options, print, args) {
|
|||
case "XMLComment":
|
||||
case "XMLProcessingInstruction":
|
||||
default:
|
||||
debugger;
|
||||
throw new Error("unknown type: " + JSON.stringify(n.type));
|
||||
}
|
||||
}
|
||||
|
@ -2144,7 +2142,7 @@ function printPropertyKey(path, options, print) {
|
|||
) {
|
||||
// 'a' -> a
|
||||
return path.call(
|
||||
keyPath => comments.printComments(keyPath, p => key.value, options),
|
||||
keyPath => comments.printComments(keyPath, () => key.value, options),
|
||||
"key"
|
||||
);
|
||||
}
|
||||
|
@ -2543,14 +2541,6 @@ function printReturnType(path, print) {
|
|||
return concat(parts);
|
||||
}
|
||||
|
||||
function typeIsFunction(type) {
|
||||
return (
|
||||
type === "FunctionExpression" ||
|
||||
type === "ArrowFunctionExpression" ||
|
||||
type === "NewExpression"
|
||||
);
|
||||
}
|
||||
|
||||
function printExportDeclaration(path, options, print) {
|
||||
const decl = path.getValue();
|
||||
const semi = options.semi ? ";" : "";
|
||||
|
@ -2658,7 +2648,7 @@ function printFlowDeclaration(path, parts) {
|
|||
return concat(parts);
|
||||
}
|
||||
|
||||
function getFlowVariance(path, options) {
|
||||
function getFlowVariance(path) {
|
||||
if (!path.variance) {
|
||||
return null;
|
||||
}
|
||||
|
@ -2760,7 +2750,7 @@ function printMemberChain(path, options, print) {
|
|||
node: node,
|
||||
printed: comments.printComments(
|
||||
path,
|
||||
p => printArgumentsList(path, options, print),
|
||||
() => printArgumentsList(path, options, print),
|
||||
options
|
||||
)
|
||||
});
|
||||
|
@ -2770,7 +2760,7 @@ function printMemberChain(path, options, print) {
|
|||
node: node,
|
||||
printed: comments.printComments(
|
||||
path,
|
||||
p => printMemberLookup(path, options, print),
|
||||
() => printMemberLookup(path, options, print),
|
||||
options
|
||||
)
|
||||
});
|
||||
|
@ -3190,7 +3180,7 @@ function printJSXElement(path, options, print) {
|
|||
]);
|
||||
}
|
||||
|
||||
function maybeWrapJSXElementInParens(path, elem, options) {
|
||||
function maybeWrapJSXElementInParens(path, elem) {
|
||||
const parent = path.getParentNode();
|
||||
if (!parent) return elem;
|
||||
|
||||
|
@ -3295,7 +3285,7 @@ function printBinaryishExpressions(path, print, options, isNested, isInsideParen
|
|||
// the other ones since we don't call the normal print on BinaryExpression,
|
||||
// only for the left and right parts
|
||||
if (isNested && node.comments) {
|
||||
parts = comments.printComments(path, p => concat(parts), options);
|
||||
parts = comments.printComments(path, () => concat(parts), options);
|
||||
}
|
||||
} else {
|
||||
// Our stopping case. Simply print the node normally.
|
||||
|
@ -3347,24 +3337,6 @@ function adjustClause(node, clause, forceSpace) {
|
|||
return indent(concat([line, clause]));
|
||||
}
|
||||
|
||||
function shouldTypeScriptTypeAvoidColon(path) {
|
||||
// As the special TS nodes isn't returned by the node helpers,
|
||||
// we use the stack directly to get the parent node.
|
||||
const parent = path.stack[path.stack.length - 3];
|
||||
|
||||
switch (parent.type) {
|
||||
case "TSFunctionType":
|
||||
case "TSIndexSignature":
|
||||
case "TSParenthesizedType":
|
||||
case "TSCallSignature":
|
||||
case "TSConstructSignature":
|
||||
case "TSAsExpression":
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function nodeStr(node, options) {
|
||||
const str = node.value;
|
||||
isString.assert(str);
|
||||
|
@ -3460,13 +3432,6 @@ function printNumber(rawNumber) {
|
|||
);
|
||||
}
|
||||
|
||||
function isFirstStatement(path) {
|
||||
const parent = path.getParentNode();
|
||||
const node = path.getValue();
|
||||
const body = parent.body;
|
||||
return body && body[0] === node;
|
||||
}
|
||||
|
||||
function isLastStatement(path) {
|
||||
const parent = path.getParentNode();
|
||||
const node = path.getValue();
|
||||
|
@ -3568,7 +3533,6 @@ function classPropMayCauseASIProblems(path) {
|
|||
function classChildNeedsASIProtection(node) {
|
||||
if (!node) return;
|
||||
|
||||
let isAsync, isGenerator;
|
||||
switch (node.type) {
|
||||
case "ClassProperty":
|
||||
return node.computed;
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
"use strict";
|
||||
|
||||
var types = require("ast-types");
|
||||
var n = types.namedTypes;
|
||||
|
||||
function isExportDeclaration(node) {
|
||||
if (node)
|
||||
switch (node.type) {
|
||||
|
|
|
@ -168,7 +168,7 @@ type f = /* comment */ arg => void;
|
|||
|
||||
type f = arg /* comment */ => void;
|
||||
|
||||
type f = ?arg => void;
|
||||
type f = (?arg) => void;
|
||||
|
||||
class X {
|
||||
constructor(
|
||||
|
|
|
@ -58,7 +58,6 @@ function run_spec(dirname, options, additionalParsers) {
|
|||
if (RUN_AST_TESTS) {
|
||||
const source = read(dirname + "/" + filename);
|
||||
const ast = removeEmptyStatements(parse(source));
|
||||
let prettyprinted = false;
|
||||
let ppast;
|
||||
let pperr = null;
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue