From 638e4b82c098a73bc119de1bb42478985ea33e47 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Wed, 17 Jun 2026 06:27:09 +0800 Subject: [PATCH] Replace `logical-assignment-operators` with the one from `unicorn` (#19391) --- eslint.config.js | 9 ++++++--- src/language-html/parse/ast.js | 4 +--- src/language-markdown/utilities.js | 8 +++----- src/main/front-matter/parse.js | 4 +--- src/main/normalize-format-options.js | 4 +--- src/main/parse.js | 9 +++------ website/static/worker.mjs | 12 ++++-------- 7 files changed, 19 insertions(+), 31 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index 052df209b..ddf27e6df 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -63,7 +63,6 @@ const configs = [ curly: "error", "dot-notation": "error", eqeqeq: "error", - "logical-assignment-operators": "error", "no-console": isCI ? "error" : "warn", "no-constant-binary-expression": "error", "no-duplicate-imports": "error", @@ -250,7 +249,11 @@ const configs = [ "unicorn/escape-case": "off", "unicorn/filename-case": ["error", { checkDirectories: false }], "unicorn/import-style": "off", - "unicorn/logical-assignment-operators": "off", + "unicorn/logical-assignment-operators": [ + "error", + "always", + { enforceForIfStatements: true }, + ], "unicorn/max-nested-calls": "off", "unicorn/no-array-callback-reference": "off", "unicorn/no-array-method-this-argument": "off", @@ -419,7 +422,7 @@ const configs = [ files: ["tests/**/*.{js,cjs}"], rules: { // 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-map": "off", "unicorn/prefer-string-replace-all": "off", diff --git a/src/language-html/parse/ast.js b/src/language-html/parse/ast.js index 315009c38..b075d59c4 100644 --- a/src/language-html/parse/ast.js +++ b/src/language-html/parse/ast.js @@ -61,9 +61,7 @@ class Node { if (nodes) { const mappedNodes = mapNodesIfChanged(nodes, (node) => node.map(fn)); if (newNode !== nodes) { - if (!newNode) { - newNode = new Node({ parent: this.parent }); - } + newNode ??= new Node({ parent: this.parent }); newNode.setProperty(NODES_KEY, mappedNodes); } } diff --git a/src/language-markdown/utilities.js b/src/language-markdown/utilities.js index 82e5eed59..d5025e280 100644 --- a/src/language-markdown/utilities.js +++ b/src/language-markdown/utilities.js @@ -244,11 +244,9 @@ function getFencedCodeBlockValue(node, originalText) { function mapAst(ast, handler) { return (function preorder(node, index, parentStack) { const newNode = { ...handler(node, index, parentStack) }; - if (newNode.children) { - newNode.children = newNode.children.map((child, index) => - preorder(child, index, [newNode, ...parentStack]), - ); - } + newNode.children &&= newNode.children.map((child, index) => + preorder(child, index, [newNode, ...parentStack]), + ); return newNode; })(ast, null, []); diff --git a/src/main/front-matter/parse.js b/src/main/front-matter/parse.js index 803f08e66..af7a49eac 100644 --- a/src/main/front-matter/parse.js +++ b/src/main/front-matter/parse.js @@ -50,9 +50,7 @@ function getFrontMatter(text) { ); let language = explicitLanguage; - if (!language) { - language = startDelimiter === "+++" ? "toml" : "yaml"; - } + language ||= startDelimiter === "+++" ? "toml" : "yaml"; if ( endDelimiterIndex === -1 && diff --git a/src/main/normalize-format-options.js b/src/main/normalize-format-options.js index 4efb250af..73d6c5fec 100644 --- a/src/main/normalize-format-options.js +++ b/src/main/normalize-format-options.js @@ -83,9 +83,7 @@ async function normalizeFormatOptions(options, opts = {}) { const mixedDefaults = { ...defaults, ...pluginDefaults }; 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") { diff --git a/src/main/parse.js b/src/main/parse.js index 2cbd652df..f8cc98cfd 100644 --- a/src/main/parse.js +++ b/src/main/parse.js @@ -31,12 +31,9 @@ function handleParseError(error, text) { // We use 1-based column, but `@babel/code-frame` uses 0-based column // https://github.com/babel/babel/pull/17849 let { start, end } = loc; - if (start) { - start = { line: start.line, column: start.column - 1 }; - } - if (end) { - end = { line: end.line, column: end.column - 1 }; - } + + start &&= { line: start.line, column: start.column - 1 }; + end &&= { line: end.line, column: end.column - 1 }; const codeFrame = codeFrameColumns( text, diff --git a/website/static/worker.mjs b/website/static/worker.mjs index d08439b5a..ed2d2de65 100644 --- a/website/static/worker.mjs +++ b/website/static/worker.mjs @@ -25,18 +25,14 @@ let prettierPluginDocExplorerCache; let pluginsCache; async function loadPrettier() { - if (!prettierCache) { - prettierCache = import(`./lib/${version}/prettier/standalone.mjs`); - } + prettierCache ??= import(`./lib/${version}/prettier/standalone.mjs`); return await prettierCache; } async function loadPrettierPackageManifest() { - if (!prettierPackageManifestCache) { - prettierPackageManifestCache = import( - `./lib/${version}/package-manifest.mjs` - ).then((m) => m.default); - } + prettierPackageManifestCache ??= import( + `./lib/${version}/package-manifest.mjs` + ).then((m) => m.default); return await prettierPackageManifestCache; }