Fix errors surfaced by new rule
MODIFY
packages/@romejs/cli-diagnostics/DiagnosticsPrinter.ts
packages/@romejs/cli-diagnostics/DiagnosticsPrinter.ts
@@ -627,7 +627,7 @@ export default class DiagnosticsPrinter extends Error {
const displayableProblems = this.getDisplayedProblemsCount();
let str = `Found <number emphasis>${displayableProblems}</number> problem`;
- if (displayableProblems > 1 || displayableProblems == 0) {
+ if (displayableProblems > 1 || displayableProblems === 0) {
str += 's';
}

MODIFY
packages/@romejs/codec-js-regexp/index.ts
packages/@romejs/codec-js-regexp/index.ts
@@ -623,7 +623,7 @@ export const createRegExpParser = createParser(
const start = this.input.slice(0, get0(token.start));
this.nextToken();
- if (token.value[token.value.length - 1] != '>') {
+ if (token.value[token.value.length - 1] !== '>') {
this.addDiagnostic({
description: descriptions.REGEX_PARSER.UNCLOSED_NAMED_CAPTURE,
loc: this.finishLocFromToken(token),

MODIFY
packages/@romejs/codec-source-map/MappingList.ts
packages/@romejs/codec-source-map/MappingList.ts
@@ -25,7 +25,7 @@ function generatedPositionAfter(mappingA: Mapping, mappingB: Mapping): boolean {
const lineB = mappingB.generated.line;
const columnA = mappingA.generated.column;
const columnB = mappingB.generated.column;
- return lineB > lineA || lineB == lineA && columnB >= columnA ||
+ return lineB > lineA || lineB === lineA && columnB >= columnA ||
compareByGeneratedPositionsInflated(mappingA, mappingB) <=
0;
}

MODIFY
packages/@romejs/codec-source-map/SourceMapConsumer.ts
packages/@romejs/codec-source-map/SourceMapConsumer.ts
@@ -188,7 +188,7 @@ export default class SourceMapConsumer {
return undefined;
}
- const source = mapping.source == undefined
+ const source = mapping.source === undefined
? this.map.file
: this.map.sources[mapping.source];
if (source === undefined) {

MODIFY
packages/@romejs/codec-watchman/bser.ts
packages/@romejs/codec-watchman/bser.ts
@@ -12,7 +12,7 @@ import os = require('os');
// BSER uses the local endianness to reduce byte swapping overheads
// (the protocol is expressly local IPC only). We need to tell node
// to use the native endianness when reading various native values.
-const isBigEndian = os.endianness() == 'BE';
+const isBigEndian = os.endianness() === 'BE';
type Bufferish = Buffer | string;
@@ -286,22 +286,15 @@ export class BunserBuf {
}
// Do something with the buffer to advance our state.
-
// If we're running synchronously we'll return either
-
// the value we've decoded or undefined if we don't
-
// yet have enought data.
-
// If we're running asynchronously, we'll emit the value
-
// when it becomes ready and schedule another invocation
-
// of process on the next tick if we still have data we
-
// can process.
process(synchronous: boolean) {
- if (this.state == ST_NEED_PDU) {
+ if (this.state === ST_NEED_PDU) {
if (this.acc.readAvail() < 2) {
return;
}
@@ -321,7 +314,7 @@ export class BunserBuf {
this.state = ST_FILL_PDU;
}
- if (this.state == ST_FILL_PDU) {
+ if (this.state === ST_FILL_PDU) {
if (this.acc.readAvail() < this.pduLen) {
// Need more data
return;
@@ -358,7 +351,7 @@ export class BunserBuf {
expectCode(expected: number): void {
const code = this.acc.readInt(1);
- if (code != expected) {
+ if (code !== expected) {
this.raise(`Expected bser opcode ${expected} but got ${code}`);
}
}
@@ -439,7 +432,7 @@ export class BunserBuf {
for (let i = 0; i < nitems; ++i) {
const obj: Dict<unknown> = {};
for (let keyidx = 0; keyidx < keys.length; ++keyidx) {
- if (this.acc.peekInt(1) == BSER_SKIP) {
+ if (this.acc.peekInt(1) === BSER_SKIP) {
this.acc.readAdvance(1);
continue;
}
@@ -654,7 +647,8 @@ export function dumpToBuffer(val: unknown): Buffer {
// Compute PDU length
const off = buf.writeOffset;
- const len = off - 7 /* the header length */;
+ const len = off - 7;
+ /* the header length */
buf.writeOffset = 3; // The length value to fill in
buf.writeInt(len, 4); // write the length in the space we reserved
buf.writeOffset = off;

MODIFY
packages/@romejs/js-compiler/api/analyzeDependencies/utils.ts
packages/@romejs/js-compiler/api/analyzeDependencies/utils.ts
@@ -178,7 +178,8 @@ function exportsSame(a: AnyAnalyzeExport, b: AnyAnalyzeExport): boolean {
return b.type === 'local' && a.name === b.name;
case 'external':
- return b.type === 'external' && a.imported === b.imported && a.exported ==
+ return b.type === 'external' && a.imported === b.imported &&
+ a.exported ===
b.exported && a.source === b.source;
case 'externalAll':

MODIFY
packages/@romejs/js-compiler/transforms/compile/jsx.ts
packages/@romejs/js-compiler/transforms/compile/jsx.ts
@@ -227,7 +227,7 @@ function cleanJSXElementLiteralChild(value: string): undefined | StringLiteral {
}
}
- if (str != '') {
+ if (str !== '') {
return stringLiteral.quick(str);
} else {
return undefined;

MODIFY
packages/@romejs/js-formatter/builders/literals/StringLiteral.ts
packages/@romejs/js-formatter/builders/literals/StringLiteral.ts
@@ -17,10 +17,8 @@ export default function StringLiteral(
node: AnyNode,
parent: AnyNode,
): Tokens {
- node =
- node.type == 'StringLiteralTypeAnnotation' || node.type === 'Directive'
- ? node
- : stringLiteral.assert(node);
+ node = node.type === 'StringLiteralTypeAnnotation' || node.type ===
+ 'Directive' ? node : stringLiteral.assert(node);
// JSX Attribute strings have ridiculous alternate semantics, should probably be a distinct AST node
const quotes = parent.type === 'JSXAttribute' || node.value.includes("'")

MODIFY
packages/@romejs/js-parser/parser.ts
packages/@romejs/js-parser/parser.ts
@@ -93,7 +93,8 @@ const SCOPE_TYPES: Array<ScopeType> = [
];
const createJSParser = createParser(
- (ParserCore, ParserWithRequiredPath) => // rome-suppress-next-line lint/noExplicitAny
+ (ParserCore, ParserWithRequiredPath) => {
+ // rome-suppress-next-line lint/noExplicitAny
class JSParser extends ParserWithRequiredPath<any, State> {
constructor(options: JSParserOptions) {
const state = createInitialState();
@@ -191,7 +192,8 @@ const createJSParser = createParser(
// and doesn't exceed
const maxDiagnostics = this.getLastScope('MAX_NEW_DIAGNOSTICS');
if (typeof maxDiagnostics === 'number' && maxDiagnostics !== -1) {
- const diff = newState.diagnostics.length - this.state.diagnostics.length;
+ const diff = newState.diagnostics.length -
+ this.state.diagnostics.length;
if (diff > maxDiagnostics) {
throw new DiagnosticsFatalError();
}
@@ -227,7 +229,11 @@ const createJSParser = createParser(
return this.finishNodeAt(start, this.getLastEndPosition(), node);
}
- finishNodeAt<T extends AnyNode>(start: Position, end: Position, node: T): T {
+ finishNodeAt<T extends AnyNode>(
+ start: Position,
+ end: Position,
+ node: T,
+ ): T {
// Maybe mutating `node` is better...?
const newNode: T = {
...node,
@@ -440,7 +446,7 @@ const createJSParser = createParser(
isLookaheadRelational(op: '<' | '>'): boolean {
const l = this.lookaheadState();
- return l.tokenType == tt.relational && l.tokenValue == op;
+ return l.tokenType === tt.relational && l.tokenValue === op;
}
banUnicodeEscape(index: undefined | Number0, name: string) {
@@ -525,9 +531,11 @@ const createJSParser = createParser(
// pretend that there is a semicolon at this position.
semicolon(): void {
if (!this.isLineTerminator()) {
- this.addDiagnostic({
+ this.addDiagnostic(
+ {
description: descriptions.JS_PARSER.EXPECTED_SEMI_OR_LINE_TERMINATOR,
- });
+ },
+ );
}
}
@@ -755,6 +763,9 @@ const createJSParser = createParser(
return program;
}
+ }
+
+ return JSParser;
},
);

MODIFY
packages/@romejs/js-parser/parser/expression.ts
packages/@romejs/js-parser/parser/expression.ts
@@ -844,7 +844,7 @@ export function parseExpressionSubscript(
if (parser.match(tt.questionDot)) {
state.optionalChainMember = true;
- if (noCalls && parser.lookaheadState().tokenType == tt.parenL) {
+ if (noCalls && parser.lookaheadState().tokenType === tt.parenL) {
state.stop = true;
return base;
}
@@ -3351,7 +3351,6 @@ export function parseYield(parser: JSParser, noIn?: boolean): YieldExpression {
}
if (parser.state.maybeInArrowParameters && // We only set yieldInPossibleArrowParameters if we haven't already
-
// found a possible invalid YieldExpression.
parser.state.yieldInPossibleArrowParameters === undefined) {
parser.state.yieldInPossibleArrowParameters = start;

MODIFY
packages/@romejs/js-parser/parser/modules.ts
packages/@romejs/js-parser/parser/modules.ts
@@ -377,7 +377,7 @@ function isExportDefaultSpecifier(parser: JSParser): boolean {
if (parser.match(tt.name) && (parser.state.tokenValue === 'type' ||
parser.state.tokenValue ===
- 'interface' || parser.state.tokenValue == 'opaque')) {
+ 'interface' || parser.state.tokenValue === 'opaque')) {
return false;
}

MODIFY
packages/@romejs/js-parser/parser/statement.ts
packages/@romejs/js-parser/parser/statement.ts
@@ -372,7 +372,7 @@ export function parseStatement(
parser.next();
let result: ParseExportResult | ParseImportResult;
- if (startType == tt._import) {
+ if (startType === tt._import) {
result = parseImport(parser, start);
} else {
result = parseExport(parser, start);
@@ -977,9 +977,9 @@ export function parseLabeledStatement(
}
const body = parseStatement(parser, statementContext);
- if (body.type == 'ClassDeclaration' || body.type ==
+ if (body.type === 'ClassDeclaration' || body.type ===
'VariableDeclarationStatement' && body.declaration.kind !== 'var' ||
- body.type ==
+ body.type ===
'FunctionDeclaration' &&
(parser.inScope('STRICT') || body.head.generator === true ||
body.head.async ===

MODIFY
packages/@romejs/js-parser/parser/typescript.ts
packages/@romejs/js-parser/parser/typescript.ts
@@ -241,7 +241,7 @@ function parseTSDelimitedList<
}
const element = parseElement(parser);
- if (element == undefined) {
+ if (element === undefined) {
break;
}

MODIFY
packages/@romejs/js-parser/scripts/generate-identifier-regex.js
packages/@romejs/js-parser/scripts/generate-identifier-regex.js
@@ -19,7 +19,7 @@ let last = -1;
const cont = [8_204, 8_205].concat(require(
`unicode-${version}/Binary_Property/ID_Continue/code-points.js`,
).filter(function(ch) {
- return ch > 127 && search(start, ch, last + 1) == -1;
+ return ch > 127 && search(start, ch, last + 1) === -1;
}));
function search(arr, ch, starting) {
@@ -45,12 +45,12 @@ function generate(chars) {
for (let i = 0, at = 65_536; 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 <= 65_535) {
- if (from == to) re += esc(from); else if (from + 1 == to) re +=
+ if (from === to) re += esc(from); else if (from + 1 === to) re +=
esc(from) +
esc(to); else re += `${esc(from)}-esc(to)`;
} else {

MODIFY
packages/@romejs/string-diff/index.ts
packages/@romejs/string-diff/index.ts
@@ -383,7 +383,7 @@ function commonPrefix(text1: string, text2: string): number {
let pointermid = pointermax;
let pointerstart = 0;
while (pointermin < pointermid) {
- if (text1.substring(pointerstart, pointermid) == text2.substring(
+ if (text1.substring(pointerstart, pointermid) === text2.substring(
pointerstart,
pointermid,
)) {
@@ -422,7 +422,7 @@ function commonSuffix(text1: string, text2: string): number {
let pointermid = pointermax;
let pointerend = 0;
while (pointermin < pointermid) {
- if (text1.substring(text1.length - pointermid, text1.length - pointerend) ==
+ if (text1.substring(text1.length - pointermid, text1.length - pointerend) ===
text2.substring(text2.length - pointermid, text2.length - pointerend)) {
pointermin = pointermid;
pointerend = pointermin;
@@ -744,7 +744,7 @@ function cleanupMerge(diffs: Diffs, fix_unicode: boolean) {
diffs[pointer + 1][1] = diffs[pointer - 1][1] + diffs[pointer + 1][1];
diffs.splice(pointer - 1, 1);
changes = true;
- } else if (diffs[pointer][1].substring(0, diffs[pointer + 1][1].length) ==
+ } else if (diffs[pointer][1].substring(0, diffs[pointer + 1][1].length) ===
diffs[pointer + 1][1]) {
// Shift the edit over the next equality.
diffs[pointer - 1][1] += diffs[pointer + 1][1];

MODIFY
packages/@romejs/string-escape/escapeString.ts
packages/@romejs/string-escape/escapeString.ts
@@ -138,25 +138,25 @@ export default function escapeString(
}
// Escape double quotes
- if (char == DOUBLE_QUOTE) {
- result += quote == char ? '\\"' : char;
+ if (char === DOUBLE_QUOTE) {
+ result += quote === char ? '\\"' : char;
continue;
}
// Escape single quotes
- if (char == SINGLE_QUOTE) {
- result += quote == char ? "\\'" : char;
+ if (char === SINGLE_QUOTE) {
+ result += quote === char ? "\\'" : char;
continue;
}
// Escape back tick
- if (char == TICK_QUOTE) {
- result += quote == char ? '\\`' : char;
+ if (char === TICK_QUOTE) {
+ result += quote === char ? '\\`' : char;
continue;
}
// Null escape
- if (char == '\0' && !json && !isDigit(str[index + 1])) {
+ if (char === '\0' && !json && !isDigit(str[index + 1])) {
result += '\\0';
continue;
}

Fix errors surfaced by new rule