fix(lint): change rule name
MODIFY
internal/compiler/lint/rules/index.ts
internal/compiler/lint/rules/index.ts
-/* GENERATED:START(hash:067905d26092d9f43a3792c9d668e05b7c1656fc,id:main) Everything below is automatically generated. DO NOT MODIFY. Run `./rome run scripts/generated-files/lint-rules` to update. */
+/* GENERATED:START(hash:85c9da9226b18c99e88a90f91952180f414ab8dc,id:main) Everything below is automatically generated. DO NOT MODIFY. Run `./rome run scripts/generated-files/lint-rules` to update. */
import useClosingNonVoid from "./html/useClosingNonVoid";
import noArguments from "./js/noArguments";
import noAsyncPromiseExecutor from "./js/noAsyncPromiseExecutor";
@@ -41,7 +41,7 @@ import useCamelCase from "./js/useCamelCase";
import useDefaultExportBasename from "./js/useDefaultExportBasename";
import useDefaultImportBasename from "./js/useDefaultImportBasename";
import useFunctionDeclarations from "./js/useFunctionDeclarations";
-import useSimplifiedBooleanExpression from "./js/useSimplifiedBooleanExpression";
+import useSimplifiedLogicalExpression from "./js/useSimplifiedLogicalExpression";
import useSingleCaseStatement from "./js/useSingleCaseStatement";
import useSingleVarDeclarator from "./js/useSingleVarDeclarator";
import useSortedSpecifiers from "./js/useSortedSpecifiers";
@@ -157,8 +157,8 @@ lintTransforms.set("js/useDefaultExportBasename", useDefaultExportBasename);
lintTransforms.set("js/useDefaultImportBasename", useDefaultImportBasename);
lintTransforms.set("js/useFunctionDeclarations", useFunctionDeclarations);
lintTransforms.set(
- "js/useSimplifiedBooleanExpression",
- useSimplifiedBooleanExpression,
+ "js/useSimplifiedLogicalExpression",
+ useSimplifiedLogicalExpression,
);
lintTransforms.set("js/useSingleCaseStatement", useSingleCaseStatement);
lintTransforms.set("js/useSingleVarDeclarator", useSingleVarDeclarator);
@@ -303,7 +303,7 @@ export const lintRuleNames: Array<LintRuleName> = [
"js/useDefaultExportBasename",
"js/useDefaultImportBasename",
"js/useFunctionDeclarations",
- "js/useSimplifiedBooleanExpression",
+ "js/useSimplifiedLogicalExpression",
"js/useSingleCaseStatement",
"js/useSingleVarDeclarator",
"js/useSortedSpecifiers",
@@ -418,7 +418,7 @@ export type LintRuleName =
| "js/useDefaultExportBasename"
| "js/useDefaultImportBasename"
| "js/useFunctionDeclarations"
- | "js/useSimplifiedBooleanExpression"
+ | "js/useSimplifiedLogicalExpression"
| "js/useSingleCaseStatement"
| "js/useSingleVarDeclarator"
| "js/useSortedSpecifiers"

RENAME
internal/compiler/lint/rules/js/useSimplifiedBooleanExpression.test.rjson
internal/compiler/lint/rules/js/useSimplifiedLogicalExpression.test.rjson
filename: "file.ts"
invalid: [
- "
- const boolExp = true;
- const r = boolExp === true;
- "
- "
- const boolExp = true;
- const r = true !== boolExp;
- "
- "
- const boolExp = true;
- const r = !!boolExp;
- "
"
const boolExp = true;
const r = true && boolExp;
@@ -30,6 +18,4 @@ invalid: [
const r = (!boolExpr1) || (!boolExpr2);
"
]
-valid: [
-
-]
\ No newline at end of file
+valid: []

RENAME
internal/compiler/lint/rules/js/useSimplifiedBooleanExpression.ts
internal/compiler/lint/rules/js/useSimplifiedLogicalExpression.ts
@@ -9,7 +9,7 @@ import { createVisitor } from "@internal/compiler/utils";
import {descriptions} from "@internal/diagnostics";
export default createVisitor({
- name: "js/useSimplifiedBooleanExpression",
+ name: "js/useSimplifiedLogicalExpression",
enter(path) {
const {node} = path;
@@ -43,7 +43,7 @@ export default createVisitor({
...node.right,
}),
},
- descriptions.LINT.JS_USE_SIMPLIFIED_BOOLEAN_EXPRESSION
+ descriptions.LINT.JS_USE_SIMPLIFIED_LOGICAL_EXPRESSION,
);
}
}
@@ -61,7 +61,7 @@ export default createVisitor({
function simplifyAndExpression(
path: Path,
literal: JSBooleanLiteral,
- expression: AnyJSExpression
+ expression: AnyJSExpression,
) {
return keepExpressionIfLiteral(path, expression, literal, true);
}
@@ -69,7 +69,7 @@ function simplifyAndExpression(
function simplifyOrExpression(
path: Path,
literal: JSBooleanLiteral,
- expression: AnyJSExpression
+ expression: AnyJSExpression,
) {
return keepExpressionIfLiteral(path, expression, literal, false);
}
@@ -78,23 +78,23 @@ function keepExpressionIfLiteral(
path: Path,
expression: AnyJSExpression,
literal: JSBooleanLiteral,
- expectedValue: boolean
+ expectedValue: boolean,
) {
if (literal.value === expectedValue) {
return path.addFixableDiagnostic(
{fixed: signals.replace({...expression})},
- descriptions.LINT.JS_USE_SIMPLIFIED_BOOLEAN_EXPRESSION
+ descriptions.LINT.JS_USE_SIMPLIFIED_LOGICAL_EXPRESSION,
);
}
return path.addFixableDiagnostic(
{fixed: signals.replace({...literal})},
- descriptions.LINT.JS_USE_SIMPLIFIED_BOOLEAN_EXPRESSION
+ descriptions.LINT.JS_USE_SIMPLIFIED_LOGICAL_EXPRESSION,
);
}
// https://en.wikipedia.org/wiki/De_Morgan%27s_laws
function couldApplyDeMorgan(
- node: JSLogicalExpression
+ node: JSLogicalExpression,
): node is DeMorganExpression {
return (
node.left.type === "JSUnaryExpression" &&
@@ -118,7 +118,7 @@ function simplifyDeMorgan(path: Path, node: DeMorganExpression) {
},
}),
},
- descriptions.LINT.JS_USE_SIMPLIFIED_BOOLEAN_EXPRESSION
+ descriptions.LINT.JS_USE_SIMPLIFIED_LOGICAL_EXPRESSION,
);
}

MODIFY
internal/compiler/lint/rules/tests.ts
internal/compiler/lint/rules/tests.ts
@@ -8,7 +8,7 @@ type Test = {
type Tests = Dict<Test | Array<Test>>;
-/* GENERATED:START(hash:1f918a6fdde78d80ad8778847105378ec2cb90d6,id:main) Everything below is automatically generated. DO NOT MODIFY. Run `./rome run scripts/generated-files/lint-rules` to update. */
+/* GENERATED:START(hash:5c373e4d80013d28386f30234efc3397af15ec8d,id:main) Everything below is automatically generated. DO NOT MODIFY. Run `./rome run scripts/generated-files/lint-rules` to update. */
// @ts-ignore
import useClosingNonVoid from "./html/useClosingNonVoid.test.rjson";
// @ts-ignore
@@ -92,7 +92,7 @@ import useDefaultImportBasename from "./js/useDefaultImportBasename.test.rjson";
// @ts-ignore
import useFunctionDeclarations from "./js/useFunctionDeclarations.test.rjson";
// @ts-ignore
-import useSimplifiedBooleanExpression from "./js/useSimplifiedBooleanExpression.test.rjson";
+import useSimplifiedLogicalExpression from "./js/useSimplifiedLogicalExpression.test.rjson";
// @ts-ignore
import useSingleCaseStatement from "./js/useSingleCaseStatement.test.rjson";
// @ts-ignore
@@ -266,7 +266,7 @@ export const tests: Tests = {
"js/useDefaultExportBasename": useDefaultExportBasename,
"js/useDefaultImportBasename": useDefaultImportBasename,
"js/useFunctionDeclarations": useFunctionDeclarations,
- "js/useSimplifiedBooleanExpression": useSimplifiedBooleanExpression,
+ "js/useSimplifiedLogicalExpression": useSimplifiedLogicalExpression,
"js/useSingleCaseStatement": useSingleCaseStatement,
"js/useSingleVarDeclarator": useSingleVarDeclarator,
"js/useSortedSpecifiers": useSortedSpecifiers,

MODIFY
internal/compiler/lint/rules/ts/useSimplifiedBooleanExpression.ts
internal/compiler/lint/rules/ts/useSimplifiedBooleanExpression.ts
-import { AnyJSExpression, AnyNode } from "@internal/ast";
-import { createVisitor, Path, Scope, signals } from "@internal/compiler";
+import {AnyJSExpression, AnyNode, JSBooleanLiteral} from "@internal/ast";
+import {Path, Scope, createVisitor, signals} from "@internal/compiler";
import {descriptions} from "@internal/diagnostics";
-import { JSBooleanLiteral } from "@internal/ast";
+
import {resolveIndirection} from "@internal/js-ast-utils";
export default createVisitor({
@@ -26,7 +26,7 @@ export default createVisitor({
path,
node.left,
node.right,
- negated
+ negated,
);
}
}
@@ -41,7 +41,7 @@ export default createVisitor({
path,
node.right,
node.left,
- negated
+ negated,
);
}
}
@@ -55,14 +55,14 @@ export default createVisitor({
const realArgument = node.argument.argument;
const {node: resolvedNode, scope: resolvedScope} = resolveIndirection(
realArgument,
- scope
+ scope,
);
if (isBooleanType(resolvedNode, resolvedScope)) {
return path.addFixableDiagnostic(
{
fixed: signals.replace({...node.argument.argument}),
},
- descriptions.LINT.JS_USE_SIMPLIFIED_BOOLEAN_EXPRESSION
+ descriptions.LINT.TS_USE_SIMPLIFIED_BOOLEAN_EXPRESSION,
);
}
}
@@ -75,20 +75,20 @@ function simplifyBinaryExpression(
path: Path,
toRemove: JSBooleanLiteral,
expression: AnyJSExpression,
- negated: boolean
+ negated: boolean,
) {
const shouldNegate = xor(negated, !toRemove.value);
return path.addFixableDiagnostic(
{
fixed: signals.replace(createSimpleExpression(expression, shouldNegate)),
},
- descriptions.LINT.TS_USE_SIMPLIFIED_BOOLEAN_EXPRESSION
+ descriptions.LINT.TS_USE_SIMPLIFIED_BOOLEAN_EXPRESSION,
);
}
function createSimpleExpression(
expression: AnyJSExpression,
- shouldNegate: boolean
+ shouldNegate: boolean,
): AnyJSExpression {
return shouldNegate
? {
@@ -102,16 +102,22 @@ function createSimpleExpression(
}
function isBooleanType(node: AnyNode, scope: Scope): boolean {
- if (node.type === "JSBooleanLiteral") return true;
- if (node.type === "JSLogicalExpression") return true;
+ if (node.type === "JSBooleanLiteral") {
+ return true;
+ }
+ if (node.type === "JSLogicalExpression") {
+ return true;
+ }
if (node.type === "JSReferenceIdentifier") {
const binding = scope.getBinding(node.name);
return (
- binding?.node.type === "JSBindingIdentifier" &&
- (binding.node.meta?.typeAnnotation?.type ===
+ binding !== undefined &&
+ (binding?.node).type === "JSBindingIdentifier" &&
+ binding.node.meta?.optional !== true &&
+ ((binding.node.meta?.typeAnnotation)?.type ===
"TSBooleanKeywordTypeAnnotation" ||
- binding.node.meta?.typeAnnotation?.type ===
+ (binding.node.meta?.typeAnnotation)?.type ===
"TSBooleanLiteralTypeAnnotation")
);
}

MODIFY
internal/diagnostics/categories.ts
internal/diagnostics/categories.ts
@@ -109,7 +109,7 @@ export type DiagnosticCategoryPrefix =
| "typeCheck"
| "v8";
-/* GENERATED:START(hash:b0511b655f548dfe017bf72d78ef1f822d359eba,id:main) Everything below is automatically generated. DO NOT MODIFY. Run `./rome run scripts/generated-files/lint-rules` to update. */
+/* GENERATED:START(hash:1e077744ab1325ad812d397d002c68764a5a97e5,id:main) Everything below is automatically generated. DO NOT MODIFY. Run `./rome run scripts/generated-files/lint-rules` to update. */
export type DiagnosticLintCategory =
| "lint/html/useClosingNonVoid"
| "lint/js/noArguments"
@@ -153,7 +153,7 @@ export type DiagnosticLintCategory =
| "lint/js/useDefaultExportBasename"
| "lint/js/useDefaultImportBasename"
| "lint/js/useFunctionDeclarations"
- | "lint/js/useSimplifiedBooleanExpression"
+ | "lint/js/useSimplifiedLogicalExpression"
| "lint/js/useSingleCaseStatement"
| "lint/js/useSingleVarDeclarator"
| "lint/js/useSortedSpecifiers"

MODIFY
internal/diagnostics/descriptions/lint.ts
internal/diagnostics/descriptions/lint.ts
@@ -111,19 +111,20 @@ export const lint = createDiagnosticsCategory({
},
JSX_A11Y_ARIA_PROPTYPES: (
attributeName: string,
- values?: Array<string | boolean>
+ values?: Array<string | boolean>,
) => {
let advice: DiagnosticAdvice = [];
if (values) {
advice.push({
type: "log",
category: "info",
- text: markup`The supported values for the <emphasis>${attributeName}</emphasis> attribute are: ${values
- .reduce((str, value) => {
+ text: markup`The supported values for the <emphasis>${attributeName}</emphasis> attribute are: ${values.reduce(
+ (str, value) => {
str.push(typeof value === "boolean" ? String(value) : `"${value}"`);
return str;
- }, [] as Array<string>)
- .join(", ")}`,
+ },
+ ([] as Array<string>),
+ ).join(", ")}`,
});
}
return {
@@ -133,9 +134,7 @@ export const lint = createDiagnosticsCategory({
};
},
- JSX_A11Y_NO_NONINTERACTIVE_ELEMENT_TO_INTERACTIVE_ROLE: (
- element: string
- ) => ({
+ JSX_A11Y_NO_NONINTERACTIVE_ELEMENT_TO_INTERACTIVE_ROLE: (element: string) => ({
category: "lint/jsx-a11y/noNoninteractiveElementToInteractiveRole",
message: markup`The HTML element <emphasis>${element}</emphasis> is non-interactive and should not have an interactive role.`,
advice: [
@@ -303,7 +302,7 @@ export const lint = createDiagnosticsCategory({
},
JSX_A11Y_MOUSE_EVENTS_HAVE_KEY_EVENTS: (
mouseEvent: string,
- keyboardEvent: string
+ keyboardEvent: string,
) => ({
category: "lint/jsx-a11y/useKeyWithMouseEvents",
message: markup`Pair the <emphasis>${mouseEvent}</emphasis> mouse event with the <emphasis>${keyboardEvent}</emphasis> keyboard event.`,
@@ -487,7 +486,7 @@ export const lint = createDiagnosticsCategory({
},
JSX_A11Y_ROLE_HAS_REQUIRED_ARIA_PROPS: (
roleName: string,
- missingAttributes: Array<string>
+ missingAttributes: Array<string>,
) => ({
category: "lint/jsx-a11y/useAriaPropsForRole",
message: markup`The element with the <emphasis>${roleName}</emphasis> ARIA role does not have the required ARIA attributes.`,
@@ -590,7 +589,7 @@ export const lint = createDiagnosticsCategory({
REACT_USE_SORT_COMP: (
right: string,
wrong: string,
- position: "before" | "after"
+ position: "before" | "after",
) => ({
category: "lint/react/useSortComp",
message: markup`<emphasis>${wrong}</emphasis> should be placed ${position} <emphasis>${right}</emphasis>.`,
@@ -623,17 +622,17 @@ export const lint = createDiagnosticsCategory({
},
REACT_NO_VOID_ELEMENTS_WITH_CHILDREN: (
element: string,
- properties: Array<string>
+ properties: Array<string>,
) => ({
category: "lint/react/noVoidElementsWithChildren",
message: markup`<emphasis>${element}</emphasis> is a void element tag and must not have <emphasis>${orJoin(
- properties.map((name) => markup`${name}`)
+ properties.map((name) => markup`${name}`),
)}</emphasis>.`,
}),
JS_USE_DEFAULT_IMPORT_BASENAME: (prev: string, basenames: Array<string>) => ({
category: "lint/js/useDefaultImportBasename",
message: markup`Use the basename ${orJoin(
- addEmphasis(basenames.map((basename) => markup`${basename}`))
+ addEmphasis(basenames.map((basename) => markup`${basename}`)),
)} when importing the default.`,
advice: [
{
@@ -705,10 +704,7 @@ export const lint = createDiagnosticsCategory({
},
],
}),
- JS_NO_UNDECLARED_VARIABLES: (
- name: string,
- bindingsInScope: Array<string>
- ) => ({
+ JS_NO_UNDECLARED_VARIABLES: (name: string, bindingsInScope: Array<string>) => ({
category: "lint/js/noUndeclaredVariables",
message: markup`The <emphasis>${name}</emphasis> variable is undeclared`,
advice: buildSuggestionAdvice(name, bindingsInScope),
@@ -856,7 +852,7 @@ export const lint = createDiagnosticsCategory({
type: "log",
category: "info",
text: markup`It's hard to visually count the amount of spaces, it's clearer if you use a quantifier instead. eg / {${String(
- count
+ count,
)}}/`,
},
],
@@ -1044,7 +1040,8 @@ export const lint = createDiagnosticsCategory({
category: "lint/regex/noReferenceToNonExistingGroup",
message: markup`Avoid nonexistent group names. Check the <emphasis>${name}</emphasis> group.`,
}),
- JS_USE_DEFAULT_EXPORT_BASENAME: ({
+ JS_USE_DEFAULT_EXPORT_BASENAME: (
+ {
defaultName,
defaultType,
actualFilename,
@@ -1054,7 +1051,8 @@ export const lint = createDiagnosticsCategory({
defaultType: string;
actualFilename: string;
correctFilename: string;
- }) => {
+ },
+ ) => {
let adviceMessage;
if (defaultName === "*default*") {
@@ -1100,7 +1098,7 @@ export const lint = createDiagnosticsCategory({
relativeFilename: string,
language: DiagnosticLanguage,
original: string,
- formatted: string
+ formatted: string,
) => ({
category: "lint/pendingFixes",
message: markup`Pending formatting and safe fixes`,
@@ -1110,7 +1108,7 @@ export const lint = createDiagnosticsCategory({
language,
diff: stringDiff(original, formatted),
},
- {
+ ({
type: "action",
command: "check",
shortcut: "f",
@@ -1120,8 +1118,8 @@ export const lint = createDiagnosticsCategory({
commandFlags: {
apply: true,
},
- } as DiagnosticAdviceAction,
- {
+ } as DiagnosticAdviceAction),
+ ({
type: "action",
hidden: true,
command: "check",
@@ -1132,7 +1130,7 @@ export const lint = createDiagnosticsCategory({
commandFlags: {
format: true,
},
- } as DiagnosticAdviceAction,
+ } as DiagnosticAdviceAction),
],
}),
TS_NO_EXPLICIT_ANY: {
@@ -1146,9 +1144,9 @@ export const lint = createDiagnosticsCategory({
},
],
},
- JS_USE_SIMPLIFIED_BOOLEAN_EXPRESSION: {
- category: "lint/js/useSimplifiedBooleanExpression",
- message: markup`Boolean expression contains unnecessary complexity.`,
+ JS_USE_SIMPLIFIED_LOGICAL_EXPRESSION: {
+ category: "lint/js/useSimplifiedLogicalExpression",
+ message: markup`Logical expression contains unnecessary complexity.`,
},
TS_USE_SIMPLIFIED_BOOLEAN_EXPRESSION: {
category: "lint/ts/useSimplifiedBooleanExpression",

fix(lint): change rule name