Replace logical-assignment-operators with the one from unicorn (#19391)

This commit is contained in:
fisker Cheung authored and GitHub committed 2026-06-17 06:27:09 +08:00
1 parent cf00244e01
commit 638e4b82c0
7 files changed
+19 -31

No files matched your search

+6 -3
View File
@@ -63,7 +63,6 @@ const configs = [
curly: "error", curly: "error",
"dot-notation": "error", "dot-notation": "error",
eqeqeq: "error", eqeqeq: "error",
"logical-assignment-operators": "error",
"no-console": isCI ? "error" : "warn", "no-console": isCI ? "error" : "warn",
"no-constant-binary-expression": "error", "no-constant-binary-expression": "error",
"no-duplicate-imports": "error", "no-duplicate-imports": "error",
@@ -250,7 +249,11 @@ const configs = [
"unicorn/escape-case": "off", "unicorn/escape-case": "off",
"unicorn/filename-case": ["error", { checkDirectories: false }], "unicorn/filename-case": ["error", { checkDirectories: false }],
"unicorn/import-style": "off", "unicorn/import-style": "off",
"unicorn/logical-assignment-operators": "off", "unicorn/logical-assignment-operators": [
"error",
"always",
{ enforceForIfStatements: true },
],
"unicorn/max-nested-calls": "off", "unicorn/max-nested-calls": "off",
"unicorn/no-array-callback-reference": "off", "unicorn/no-array-callback-reference": "off",
"unicorn/no-array-method-this-argument": "off", "unicorn/no-array-method-this-argument": "off",
@@ -419,7 +422,7 @@ const configs = [
files: ["tests/**/*.{js,cjs}"], files: ["tests/**/*.{js,cjs}"],
rules: { rules: {
// TODO: Enable this when we drop support for Node.js v14 // TODO: Enable this when we drop support for Node.js v14
"logical-assignment-operators": "off", "unicorn/logical-assignment-operators": "off",
"unicorn/prefer-array-flat": "off", "unicorn/prefer-array-flat": "off",
"unicorn/prefer-array-flat-map": "off", "unicorn/prefer-array-flat-map": "off",
"unicorn/prefer-string-replace-all": "off", "unicorn/prefer-string-replace-all": "off",
+1 -3
View File
@@ -61,9 +61,7 @@ class Node {
if (nodes) { if (nodes) {
const mappedNodes = mapNodesIfChanged(nodes, (node) => node.map(fn)); const mappedNodes = mapNodesIfChanged(nodes, (node) => node.map(fn));
if (newNode !== nodes) { if (newNode !== nodes) {
if (!newNode) { newNode ??= new Node({ parent: this.parent });
newNode = new Node({ parent: this.parent });
}
newNode.setProperty(NODES_KEY, mappedNodes); newNode.setProperty(NODES_KEY, mappedNodes);
} }
} }
+3 -5
View File
@@ -244,11 +244,9 @@ function getFencedCodeBlockValue(node, originalText) {
function mapAst(ast, handler) { function mapAst(ast, handler) {
return (function preorder(node, index, parentStack) { return (function preorder(node, index, parentStack) {
const newNode = { ...handler(node, index, parentStack) }; const newNode = { ...handler(node, index, parentStack) };
if (newNode.children) { newNode.children &&= newNode.children.map((child, index) =>
newNode.children = newNode.children.map((child, index) => preorder(child, index, [newNode, ...parentStack]),
preorder(child, index, [newNode, ...parentStack]), );
);
}
return newNode; return newNode;
})(ast, null, []); })(ast, null, []);
+1 -3
View File
@@ -50,9 +50,7 @@ function getFrontMatter(text) {
); );
let language = explicitLanguage; let language = explicitLanguage;
if (!language) { language ||= startDelimiter === "+++" ? "toml" : "yaml";
language = startDelimiter === "+++" ? "toml" : "yaml";
}
if ( if (
endDelimiterIndex === -1 && endDelimiterIndex === -1 &&
+1 -3
View File
@@ -83,9 +83,7 @@ async function normalizeFormatOptions(options, opts = {}) {
const mixedDefaults = { ...defaults, ...pluginDefaults }; const mixedDefaults = { ...defaults, ...pluginDefaults };
for (const [k, value] of Object.entries(mixedDefaults)) { for (const [k, value] of Object.entries(mixedDefaults)) {
if (rawOptions[k] === null || rawOptions[k] === undefined) { rawOptions[k] ??= value;
rawOptions[k] = value;
}
} }
if (rawOptions.parser === "json") { if (rawOptions.parser === "json") {
+3 -6
View File
@@ -31,12 +31,9 @@ function handleParseError(error, text) {
// We use 1-based column, but `@babel/code-frame` uses 0-based column // We use 1-based column, but `@babel/code-frame` uses 0-based column
// https://github.com/babel/babel/pull/17849 // https://github.com/babel/babel/pull/17849
let { start, end } = loc; let { start, end } = loc;
if (start) {
start = { line: start.line, column: start.column - 1 }; start &&= { line: start.line, column: start.column - 1 };
} end &&= { line: end.line, column: end.column - 1 };
if (end) {
end = { line: end.line, column: end.column - 1 };
}
const codeFrame = codeFrameColumns( const codeFrame = codeFrameColumns(
text, text,
+4 -8
View File
@@ -25,18 +25,14 @@ let prettierPluginDocExplorerCache;
let pluginsCache; let pluginsCache;
async function loadPrettier() { async function loadPrettier() {
if (!prettierCache) { prettierCache ??= import(`./lib/${version}/prettier/standalone.mjs`);
prettierCache = import(`./lib/${version}/prettier/standalone.mjs`);
}
return await prettierCache; return await prettierCache;
} }
async function loadPrettierPackageManifest() { async function loadPrettierPackageManifest() {
if (!prettierPackageManifestCache) { prettierPackageManifestCache ??= import(
prettierPackageManifestCache = import( `./lib/${version}/package-manifest.mjs`
`./lib/${version}/package-manifest.mjs` ).then((m) => m.default);
).then((m) => m.default);
}
return await prettierPackageManifestCache; return await prettierPackageManifestCache;
} }