Enable no-implicit-coercion rule (#10186)

This commit is contained in:
fisker Cheung authored and GitHub committed 2021-02-01 13:14:04 +08:00
1 parent 2c1b8f6fab
commit f04b2b991c
16 files changed
+28 -28

No files matched your search

+1
View File
@@ -27,6 +27,7 @@ rules:
- devDependencies: ["tests*/**", "scripts/**"]
import/order: error
no-else-return: error
no-implicit-coercion: error
no-inner-declarations: error
no-unneeded-ternary: error
no-useless-return: error
+1 -1
View File
@@ -3,7 +3,7 @@
const installPrettier = require("./scripts/install-prettier");
const isProduction = process.env.NODE_ENV === "production";
const ENABLE_CODE_COVERAGE = !!process.env.ENABLE_CODE_COVERAGE;
const ENABLE_CODE_COVERAGE = Boolean(process.env.ENABLE_CODE_COVERAGE);
if (isProduction || process.env.INSTALL_PACKAGE) {
process.env.PRETTIER_DIR = installPrettier();
}
+3 -4
View File
@@ -197,13 +197,12 @@ function format(context, input, opt) {
repeat +
" times."
);
// should be using `performance.now()`, but only `Date` is cross-platform enough
const now = Date.now ? () => Date.now() : () => +new Date();
let totalMs = 0;
for (let i = 0; i < repeat; ++i) {
const startMs = now();
// should be using `performance.now()`, but only `Date` is cross-platform enough
const startMs = Date.now();
prettier.formatWithCursor(input, opt);
totalMs += now() - startMs;
totalMs += Date.now() - startMs;
}
const averageMs = totalMs / repeat;
const results = {
+3 -3
View File
@@ -68,9 +68,9 @@ function getExplorer(opts) {
function _resolveConfig(filePath, opts, sync) {
opts = { useCache: true, ...opts };
const loadOpts = {
cache: !!opts.useCache,
sync: !!sync,
editorconfig: !!opts.editorconfig,
cache: Boolean(opts.useCache),
sync: Boolean(sync),
editorconfig: Boolean(opts.editorconfig),
};
const { load, search } = getExplorer(loadOpts);
const loadEditorConfig = resolveEditorConfig.getLoadFunction(loadOpts);
+1 -1
View File
@@ -95,7 +95,7 @@ function group(contents, opts = {}) {
type: "group",
id: opts.id,
contents,
break: !!opts.shouldBreak,
break: Boolean(opts.shouldBreak),
expandedStates: opts.expandedStates,
};
}
+1 -1
View File
@@ -96,7 +96,7 @@ function isSCSS(parser, text) {
}
function isSCSSVariable(node) {
return !!(node && node.type === "word" && node.value.startsWith("$"));
return Boolean(node && node.type === "word" && node.value.startsWith("$"));
}
function isWideKeywords(value) {
+1 -1
View File
@@ -35,7 +35,7 @@ function genericPrint(path, options, print) {
}
case "OperationDefinition": {
const hasOperation = options.originalText[locStart(n)] !== "{";
const hasName = !!n.name;
const hasName = Boolean(n.name);
return [
hasOperation ? n.operation : "",
hasOperation && hasName ? [" ", path.call(print, "name")] : "",
+1 -1
View File
@@ -67,7 +67,7 @@ function format(path, print, textToDoc, options, { parser }) {
continue;
}
const placeholderIndex = +component;
const placeholderIndex = Number(component);
parts.push(expressionDocs[placeholderIndex]);
}
+1 -1
View File
@@ -581,7 +581,7 @@ function needsParens(path, options) {
case "ArrowFunctionExpression":
switch (parent.type) {
case "PipelineTopicExpression":
return !!(node.extra && node.extra.parenthesized);
return Boolean(node.extra && node.extra.parenthesized);
case "BinaryExpression":
return (
+2 -2
View File
@@ -101,8 +101,8 @@ function printHardlineAfterHeritage(node) {
function hasMultipleHeritage(node) {
return (
["superClass", "extends", "mixins", "implements"].filter(
(key) => !!node[key]
["superClass", "extends", "mixins", "implements"].filter((key) =>
Boolean(node[key])
).length > 1
);
}
+1 -1
View File
@@ -713,7 +713,7 @@ function printJsx(path, options, print) {
case "JSXAttribute":
return printJsxAttribute(path, options, print);
case "JSXIdentifier":
return "" + n.name;
return String(n.name);
case "JSXNamespacedName":
return join(":", [
path.call(print, "namespace"),
+2 -2
View File
@@ -490,7 +490,7 @@ function printPathNoParens(path, options, print, args) {
return printNumber(n.raw);
}
if (typeof n.value !== "string") {
return "" + n.value;
return String(n.value);
}
return nodeStr(n, options);
case "Directive":
@@ -873,7 +873,7 @@ function printPathNoParens(path, options, print, args) {
case "ArrayTypeAnnotation":
return [path.call(print, "elementType"), "[]"];
case "BooleanLiteralTypeAnnotation":
return "" + n.value;
return String(n.value);
case "EnumDeclaration":
return ["enum ", path.call(print, "id"), " ", path.call(print, "body")];
+1 -1
View File
@@ -1160,7 +1160,7 @@ function getLeftMost(node) {
function isBitwiseOperator(operator) {
return (
!!bitshiftOperators[operator] ||
Boolean(bitshiftOperators[operator]) ||
operator === "|" ||
operator === "^" ||
operator === "&"
+1 -1
View File
@@ -892,7 +892,7 @@ function clamp(value, min, max) {
}
function hasPrettierIgnore(path) {
const index = +path.getName();
const index = Number(path.getName());
if (index === 0) {
return false;
+5 -5
View File
@@ -37,12 +37,12 @@ function textToDoc(
...parentOptions,
...partialNextOptions,
parentParser: parentOptions.parser,
embeddedInHtml: !!(
embeddedInHtml: Boolean(
parentOptions.embeddedInHtml ||
parentOptions.parser === "html" ||
parentOptions.parser === "vue" ||
parentOptions.parser === "angular" ||
parentOptions.parser === "lwc"
parentOptions.parser === "html" ||
parentOptions.parser === "vue" ||
parentOptions.parser === "angular" ||
parentOptions.parser === "lwc"
),
originalText: text,
},
+3 -3
View File
@@ -63,8 +63,8 @@ function runPrettier(dir, args = [], options = {}) {
const originalStdoutIsTTY = process.stdout.isTTY;
process.chdir(normalizeDir(dir));
process.stdin.isTTY = !!options.isTTY;
process.stdout.isTTY = !!options.stdoutIsTTY;
process.stdin.isTTY = Boolean(options.isTTY);
process.stdout.isTTY = Boolean(options.stdoutIsTTY);
process.argv = ["path/to/node", "path/to/prettier/bin", ...args];
jest.resetModules();
@@ -77,7 +77,7 @@ function runPrettier(dir, args = [], options = {}) {
.mockImplementation(() => SynchronousPromise.resolve(options.input || ""));
jest
.spyOn(require(thirdParty), "isCI")
.mockImplementation(() => !!options.ci);
.mockImplementation(() => Boolean(options.ci));
jest
.spyOn(require(thirdParty), "cosmiconfig")
.mockImplementation((moduleName, options) =>