Skip to content

Commit

Permalink
Enable eqeqeq rule (#16404)
Browse files Browse the repository at this point in the history
* eqeqeq

* review

* review
  • Loading branch information
liuxingbaoyu authored Apr 6, 2024
1 parent f7a7715 commit a84ec28
Show file tree
Hide file tree
Showing 20 changed files with 31 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Gulpfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ async function buildBabel(useWorker, ignore = []) {
return Promise.allSettled(promises)
.then(results => {
results.forEach(result => {
if (result.status == "rejected") {
if (result.status === "rejected") {
if (process.env.WATCH_SKIP_BUILD) {
console.error(result.reason);
} else {
Expand Down
4 changes: 2 additions & 2 deletions Makefile.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Makefile.source.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function exec(executable, args, cwd, inheritStdio = true) {
env: process.env,
});
} catch (error) {
if (inheritStdio && error.status != 0) {
if (inheritStdio && error.status !== 0) {
console.error(
new Error(
`\ncommand: ${executable} ${args.join(" ")}\ncode: ${error.status}`
Expand Down Expand Up @@ -180,7 +180,7 @@ target["bootstrap"] = function () {
target["build"] = function () {
target["build-no-bundle"]();

if (process.env.BABEL_COVERAGE != "true") {
if (process.env.BABEL_COVERAGE !== "true") {
target["build-standalone"]();
}
};
Expand Down
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ function pluginGeneratorOptimization({ types: t }) {
t.isStringLiteral(args[0])
) {
const str = args[0].value;
if (str.length == 1) {
if (str.length === 1) {
node.callee.property.name = "tokenChar";
args[0] = t.numericLiteral(str.charCodeAt(0));
}
Expand Down
1 change: 1 addition & 0 deletions eslint/babel-eslint-config-internal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = [
},
rules: {
curly: ["error", "multi-line"],
eqeqeq: ["error", "smart"],
"linebreak-style": ["error", "unix"],
"no-case-declarations": "error",
"no-confusing-arrow": "error",
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-cli/src/babel/dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default async function ({
let outputMap: "both" | "external" | false = false;
if (babelOptions.sourceMaps && babelOptions.sourceMaps !== "inline") {
outputMap = "external";
} else if (babelOptions.sourceMaps == undefined) {
} else if (babelOptions.sourceMaps == null) {
outputMap = util.hasDataSourcemap(res.code) ? "external" : "both";
}

Expand Down
2 changes: 1 addition & 1 deletion packages/babel-cli/src/babel/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default async function ({
let outputMap: "both" | "external" | false = false;
if (babelOptions.sourceMaps && babelOptions.sourceMaps !== "inline") {
outputMap = "external";
} else if (babelOptions.sourceMaps == undefined && result.hasRawMap) {
} else if (babelOptions.sourceMaps == null && result.hasRawMap) {
outputMap = util.hasDataSourcemap(result.code) ? "external" : "both";
}

Expand Down
2 changes: 2 additions & 0 deletions packages/babel-cli/src/babel/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,12 @@ function booleanify(val: "true" | 1): true;
function booleanify(val: any): any {
if (val === undefined) return undefined;

// eslint-disable-next-line eqeqeq
if (val === "true" || val == 1) {
return true;
}

// eslint-disable-next-line eqeqeq
if (val === "false" || val == 0 || !val) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-cli/src/babel/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function addSourceMappingUrl(code: string, loc: string): string {

export function hasDataSourcemap(code: string): boolean {
const pos = code.lastIndexOf("\n", code.length - 2);
return pos != -1 && code.lastIndexOf("//# sourceMappingURL") < pos;
return pos !== -1 && code.lastIndexOf("//# sourceMappingURL") < pos;
}

const CALLER = {
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-generator/src/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ class Printer {
this._printStack.push(node);

const oldInAux = this._insideAux;
this._insideAux = node.loc == undefined;
this._insideAux = node.loc == null;
this._maybeAddAuxComment(this._insideAux && !oldInAux);

const parenthesized = node.extra?.parenthesized as boolean | undefined;
Expand Down Expand Up @@ -1128,7 +1128,7 @@ class Printer {
if (
this._buf.hasContent() &&
(comment.type === "CommentLine" ||
commentStartLine != commentEndLine)
commentStartLine !== commentEndLine)
) {
offset = leadingCommentNewline = 1;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-helper-simple-access/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ if (!process.env.BABEL_8_BREAKING) {
!path.isCompletionRecord()
) {
// ++i => (i += 1);
const operator = path.node.operator == "++" ? "+=" : "-=";
const operator = path.node.operator === "++" ? "+=" : "-=";
path.replaceWith(
assignmentExpression(operator, arg.node, numericLiteral(1)),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let last = -1;
const cont = require(
"@unicode/unicode-" + version + "/Binary_Property/ID_Continue/code-points.js"
).filter(function (ch) {
return ch > 0x7f && search(start, ch, last + 1) == -1;
return ch > 0x7f && search(start, ch, last + 1) === -1;
});

function search(arr, ch, starting) {
Expand All @@ -40,13 +40,13 @@ function generate(chars) {
for (let i = 0, at = 0x10000; i < chars.length; i++) {
const from = chars[i];
let to = from;
while (i < chars.length - 1 && chars[i + 1] == to + 1) {
while (i < chars.length - 1 && chars[i + 1] === to + 1) {
i++;
to++;
}
if (to <= 0xffff) {
if (from == to) re += esc(from);
else if (from + 1 == to) re += esc(from) + esc(to);
if (from === to) re += esc(from);
else if (from + 1 === to) re += esc(from) + esc(to);
else re += esc(from) + "-" + esc(to);
} else {
astral.push(from - at, to - from);
Expand Down
3 changes: 2 additions & 1 deletion packages/babel-helpers/src/helpers/applyDecs2311.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,10 @@ export default /* @no-mangle */ function applyDecs2311(
var kind = decInfo[1];
var kindOnly: PROP_KIND = kind & PROP_KIND.KIND_MASK;
if (
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison, eqeqeq
(kind & PROP_KIND.STATIC) == isStatic &&
// @ts-expect-error comparing a boolean with 0 | 1
// eslint-disable-next-line eqeqeq
!kindOnly == isField
) {
var name = decInfo[2];
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-highlight/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ if (process.env.BABEL_8_BREAKING) {

if (
JSX_TAG.test(token.value) &&
(text[offset - 1] === "<" || text.slice(offset - 2, offset) == "</")
(text[offset - 1] === "<" || text.slice(offset - 2, offset) === "</")
) {
return "jsxIdentifier";
}
Expand Down
4 changes: 3 additions & 1 deletion packages/babel-parser/src/parser/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ export default class CommentsParser extends BaseParser {
addComment(comment: Comment): void {
if (this.filename) comment.loc.filename = this.filename;
const { commentsLen } = this.state;
if (this.comments.length != commentsLen) this.comments.length = commentsLen;
if (this.comments.length !== commentsLen) {
this.comments.length = commentsLen;
}
this.comments.push(comment);
this.state.commentsLen++;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-parser/src/plugins/jsx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export default (superClass: typeof Parser) =>
while (
count++ < 10 &&
this.state.pos < this.length &&
!(semi = this.codePointAtPos(this.state.pos) == charCodes.semicolon)
!(semi = this.codePointAtPos(this.state.pos) === charCodes.semicolon)
) {
++this.state.pos;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-parser/src/plugins/typescript/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class TypeScriptScopeHandler extends ScopeHandler<TypeScriptScope
}

enter(flags: ScopeFlag): void {
if (flags == ScopeFlag.TS_MODULE) {
if (flags === ScopeFlag.TS_MODULE) {
this.importsStack.push(new Set());
}

Expand All @@ -46,7 +46,7 @@ export default class TypeScriptScopeHandler extends ScopeHandler<TypeScriptScope
exit() {
const flags = super.exit();

if (flags == ScopeFlag.TS_MODULE) {
if (flags === ScopeFlag.TS_MODULE) {
this.importsStack.pop();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ export default function transformClass(
});

if (
maxGuaranteedSuperBeforeIndex != -1 &&
maxGuaranteedSuperBeforeIndex !== -1 &&
thisIndex > maxGuaranteedSuperBeforeIndex
) {
thisPath.replaceWith(thisRef());
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-traverse/src/path/evaluation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ function _evaluate(path: NodePath, state: State): any {
case "==":
return left == right; // eslint-disable-line eqeqeq
case "!=":
return left != right;
return left != right; // eslint-disable-line eqeqeq
case "===":
return left === right;
case "!==":
Expand Down
2 changes: 1 addition & 1 deletion scripts/pack-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async function pack(inputPath, outputPath, dynamicRequireTargets) {
.update(readFileSync(inputPath, "utf8"))
.digest("hex");

if (process.argv[2] == "--auto") {
if (process.argv[2] === "--auto") {
if (readFileSync(outputPath, "utf8").includes(hash)) {
return;
}
Expand Down

0 comments on commit a84ec28

Please sign in to comment.