Enable more eslint recommended rules (#11168)

* chore: enable no-constant-condition

* chore: enable no-empty rule

* chore: enable no-unreachable

* chore: enable no-cond-assign

* chore: enable no-inner-declarations

* chore: remove disabled rules that are not in eslint:recommended

* fix: oops
This commit is contained in:
Huáng Jùnliàng 2020-02-24 19:04:25 -05:00 committed by GitHub
parent 2d1bac9666
commit afb0f489de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 184 additions and 198 deletions

View File

@ -19,29 +19,14 @@ module.exports = {
browser: true,
},
rules: {
camelcase: "off",
"consistent-return": "off",
curly: ["error", "multi-line"],
"linebreak-style": ["error", "unix"],
"new-cap": "off",
"no-case-declarations": "error",
"no-cond-assign": "off",
"no-confusing-arrow": "error",
"no-console": "off",
"no-constant-condition": "off",
"no-empty": "off",
"no-inner-declarations": "off",
"no-labels": "off",
"no-loop-func": "off",
"no-empty": ["error", { allowEmptyCatch: true }],
"no-process-exit": "error",
"no-return-assign": "off",
"no-shadow": "off",
"no-underscore-dangle": "off",
"no-unreachable": "off",
"no-use-before-define": "off",
"no-var": "error",
"prefer-const": "error",
strict: "off",
"flowtype/define-flow-type": "warn",
"flowtype/use-flow-type": "warn",
},

View File

@ -99,7 +99,7 @@ function ExportDeclaration(node: Object) {
// print "special" specifiers first
let hasSpecial = false;
while (true) {
for (;;) {
const first = specifiers[0];
if (
t.isExportDefaultSpecifier(first) ||
@ -149,7 +149,7 @@ export function ImportDeclaration(node: Object) {
const specifiers = node.specifiers.slice(0);
if (specifiers && specifiers.length) {
// print "special" specifiers first
while (true) {
for (;;) {
const first = specifiers[0];
if (
t.isImportDefaultSpecifier(first) ||

View File

@ -78,34 +78,7 @@ function findFile(filepath: string, allowJSON: boolean) {
return matches[0];
}
export default function get(entryLoc): Array<Suite> {
const suites = [];
let rootOpts = {};
const rootOptsLoc = tryResolve(entryLoc + "/options");
if (rootOptsLoc) rootOpts = require(rootOptsLoc);
for (const suiteName of fs.readdirSync(entryLoc)) {
if (shouldIgnore(suiteName)) continue;
const suite = {
options: clone(rootOpts),
tests: [],
title: humanize(suiteName),
filename: entryLoc + "/" + suiteName,
};
assertDirectory(suite.filename);
suites.push(suite);
const suiteOptsLoc = tryResolve(suite.filename + "/options");
if (suiteOptsLoc) suite.options = require(suiteOptsLoc);
for (const taskName of fs.readdirSync(suite.filename)) {
push(taskName, suite.filename + "/" + taskName);
}
function push(taskName, taskDir) {
function pushTask(taskName, taskDir, suite, suiteName) {
const taskDirStats = fs.statSync(taskDir);
let actualLoc = findFile(taskDir + "/input");
let execLoc = findFile(taskDir + "/exec");
@ -277,6 +250,33 @@ export default function get(entryLoc): Array<Suite> {
// Delete to avoid option validation error
delete test.options.validateLogs;
delete test.options.ignoreOutput;
}
export default function get(entryLoc): Array<Suite> {
const suites = [];
let rootOpts = {};
const rootOptsLoc = tryResolve(entryLoc + "/options");
if (rootOptsLoc) rootOpts = require(rootOptsLoc);
for (const suiteName of fs.readdirSync(entryLoc)) {
if (shouldIgnore(suiteName)) continue;
const suite = {
options: clone(rootOpts),
tests: [],
title: humanize(suiteName),
filename: entryLoc + "/" + suiteName,
};
assertDirectory(suite.filename);
suites.push(suite);
const suiteOptsLoc = tryResolve(suite.filename + "/options");
if (suiteOptsLoc) suite.options = require(suiteOptsLoc);
for (const taskName of fs.readdirSync(suite.filename)) {
pushTask(taskName, suite.filename + "/" + taskName, suite, suiteName);
}
}

View File

@ -142,7 +142,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
modified: { [key: TsModifier]: ?true },
allowedModifiers: T[],
): void {
while (true) {
for (;;) {
const startPos = this.state.start;
const modifier: ?T = this.tsParseModifier(allowedModifiers);
@ -204,7 +204,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
): ?(T[]) {
const result = [];
while (true) {
for (;;) {
if (this.tsIsListTerminator(kind)) {
break;
}

View File

@ -20,10 +20,9 @@ export function shareCommentsWithSiblings() {
const next = this.getSibling(this.key + 1);
const hasPrev = Boolean(prev.node);
const hasNext = Boolean(next.node);
if (hasPrev && hasNext) {
} else if (hasPrev) {
if (hasPrev && !hasNext) {
prev.addComments("trailing", trailing);
} else if (hasNext) {
} else if (hasNext && !hasPrev) {
next.addComments("leading", leading);
}
}

View File

@ -62,6 +62,7 @@ export default class Renamer {
// retain the `name` of a class/function declaration
// eslint-disable-next-line no-unreachable
if (!path.isFunctionDeclaration() && !path.isClassDeclaration()) return;
if (this.binding.kind !== "hoisted") return;
@ -83,6 +84,7 @@ export default class Renamer {
// retain the `name` of a class/function expression
// eslint-disable-next-line no-unreachable
if (!path.isFunctionExpression() && !path.isClassExpression()) return;
if (this.binding.kind !== "local") return;