Rename inconsiderateLanguage to confusingLanguage
MODIFY
packages/@romejs/diagnostics/categories.ts
packages/@romejs/diagnostics/categories.ts
@@ -101,7 +101,7 @@ type LintDiagnosticCategory =
| "lint/emptyMatches"
| "lint/getterReturn"
| "lint/importDefaultBasename"
- | "lint/inconsiderateLanguage"
+ | "lint/confusingLanguage"
| "lint/jsxA11yHTMLHasLang"
| "lint/jsxA11yIframeHasTitle"
| "lint/jsxA11yImgRedundantAlt"

MODIFY
packages/@romejs/diagnostics/descriptions.ts
packages/@romejs/diagnostics/descriptions.ts
@@ -461,18 +461,20 @@ export const descriptions = createMessages({
category: "lint/caseSingleStatement",
message: "A switch case should only have a single statement. If you want more then wrap it in a block.",
},
- INCONSIDERATE_LANGUAGE: (
+ CONFUSING_LANGUAGE: (
description: string,
word: string,
suggestion: string,
+ advice: DiagnosticAdvice,
) => ({
- category: "lint/inconsiderateLanguage",
+ category: "lint/confusingLanguage",
message: description,
advice: [
+ ...advice,
{
type: "log",
category: "info",
- text: markup`Instead of <emphasis>${word}</emphasis> use <emphasis>${suggestion}</emphasis>`,
+ text: markup`Consider using <emphasis>${suggestion}</emphasis> instead`,
},
],
}),

MODIFY
packages/@romejs/js-compiler/lint/rules/index.ts
packages/@romejs/js-compiler/lint/rules/index.ts
@@ -15,7 +15,7 @@ import emptyBlocks from "./regular/emptyBlocks";
import emptyMatches from "./regular/emptyMatches";
import getterReturn from "./regular/getterReturn";
import importDefaultBasename from "./regular/importDefaultBasename";
-import inconsiderateLanguage from "./regular/inconsiderateLanguage";
+import confusingLanguage from "./regular/confusingLanguage";
import jsxA11YHTMLHasLang from "./react/jsxA11yHTMLHasLang";
import jsxA11YIframeHasTitle from "./react/jsxA11yIframeHasTitle";
import jsxA11YImgRedundantAlt from "./react/jsxA11yImgRedundantAlt";
@@ -80,7 +80,7 @@ export const lintTransforms = [
emptyMatches,
getterReturn,
importDefaultBasename,
- inconsiderateLanguage,
+ confusingLanguage,
jsxA11YHTMLHasLang,
jsxA11YIframeHasTitle,
jsxA11YImgRedundantAlt,

ADD
packages/@romejs/js-compiler/lint/rules/regular/confusingLanguage.json
+[
+ {
+ "description": "<emphasis>whitelist</emphasis> can be considered raciallly charged language",
+ "word": "whitelist",
+ "suggestion": "allowlist",
+ "advice": [
+ {
+ "type": "log",
+ "category": "info",
+ "text": "See <hyperlink target=\"https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6148600/\" /> for a more detailed explanation"
+ }
+ ]
+ },
+ {
+ "description": "<emphasis>blacklist</emphasis> can be considered raciallly charged language",
+ "word": "blacklist",
+ "suggestion": "denylist",
+ "advice": [
+ {
+ "type": "log",
+ "category": "info",
+ "text": "See <hyperlink target=\"https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6148600/\" /> for a more detailed explanation"
+ }
+ ]
+ }
+]
\ No newline at end of file

RENAME
packages/@romejs/js-compiler/lint/rules/regular/inconsiderateLanguage.test.ts
packages/@romejs/js-compiler/lint/rules/regular/confusingLanguage.test.ts
@@ -9,7 +9,7 @@ import {test} from "rome";
import {testLintMultiple} from "../testHelpers";
test(
- "inconsiderate language",
+ "confusing language",
async (t) => {
await testLintMultiple(
t,
@@ -21,7 +21,7 @@ test(
"someBlacklist;",
"SOME_BLACKLIST;",
],
- {category: "lint/inconsiderateLanguage"},
+ {category: "lint/confusingLanguage"},
);
},
);

RENAME
packages/@romejs/js-compiler/lint/rules/regular/inconsiderateLanguage.ts
packages/@romejs/js-compiler/lint/rules/regular/confusingLanguage.ts
@@ -10,13 +10,20 @@ import {AnyNode} from "@romejs/js-ast";
import {PositionTracker, SourceLocation} from "@romejs/parser-core";
import {ob1Coerce0} from "@romejs/ob1";
import {isIdentifierish} from "@romejs/js-ast-utils";
-import {descriptions} from "@romejs/diagnostics";
-import inconsiderateLanguage from "./inconsiderateLanguage.json";
+import {DiagnosticAdvice, descriptions} from "@romejs/diagnostics";
+import confusingLanguage from "./confusingLanguage.json";
import {preserveCasing} from "@romejs/string-utils";
+type ConfusingLanguage = Array<{
+ description: string;
+ word: string;
+ suggestion: string;
+ advice: DiagnosticAdvice;
+}>;
+
// Fast regex for checking if we need to validate a string
const regex = new RegExp(
- inconsiderateLanguage.map((term) => term.word).join("|"),
+ confusingLanguage.map((term) => term.word).join("|"),
"gi",
);
@@ -27,6 +34,7 @@ type CheckResult = {
suggestion: string;
startIndex: number;
endIndex: number;
+ advice: DiagnosticAdvice;
};
function check(
@@ -52,7 +60,7 @@ function check(
for (let i = 0; i < lower.length; i++) {
const char = lower[i];
- for (const {word, description, suggestion} of inconsiderateLanguage) {
+ for (const {advice, word, description, suggestion} of (confusingLanguage as ConfusingLanguage)) {
if (char === word[0] && lower.startsWith(word, i)) {
const wordWithSourceCasing = input.slice(i, i + word.length);
@@ -60,6 +68,7 @@ function check(
// We want to preserve the original casing
word: wordWithSourceCasing,
description,
+ advice,
suggestion: preserveCasing(wordWithSourceCasing, suggestion),
startIndex: i,
endIndex: i + word.length,
@@ -113,10 +122,15 @@ export default {
// Produce diagnostics
const {results, fixed} = check(loc, value);
let suppressed = false;
- for (const {loc, word, description, suggestion} of results) {
+ for (const {loc, word, description, suggestion, advice} of results) {
({suppressed} = context.addLocDiagnostic(
loc,
- descriptions.LINT.INCONSIDERATE_LANGUAGE(description, word, suggestion),
+ descriptions.LINT.CONFUSING_LANGUAGE(
+ description,
+ word,
+ suggestion,
+ advice,
+ ),
{fixable: true},
));

DELETE
packages/@romejs/js-compiler/lint/rules/regular/inconsiderateLanguage.json
-[
- {
- "description": "Replace racially-charged language with more accurate and inclusive words",
- "word": "whitelist",
- "suggestion": "allowlist"
- },
- {
- "description": "Replace racially-charged language with more accurate and inclusive words",
- "word": "blacklist",
- "suggestion": "denylist"
- }
-]

Rename inconsiderateLanguage to confusingLanguage