дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 01:01:17 +02:00
fix(python): say which formatter wins when both are selected (#7658)
Selecting Ruff and Black as the formatting provider at the same time was accepted silently, with Black formatting Python. While both are selected, the Ruff and Black formatter pages now show a note under the provider select saying Black wins, and the Ruff page says how to go back to Ruff. Other formatter pages are unchanged. Strings in en, zh and zh-TW. Co-authored-by: muutot <[email protected]>
Цей коміт міститься в:
1 джерело
ceb020857a
коміт
e08e455fe5
5 files changed
+62
-2
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { act, fireEvent, render, screen, within } from "@testing-library/react";
|
||||
import { act, cleanup, fireEvent, render, screen, within } from "@testing-library/react";
|
||||
import { DEFAULT_SSH_CONFIG } from "@/platform/remoteSettings";
|
||||
import { commands, type Settings } from "@/platform/ipc";
|
||||
|
||||
@@ -304,6 +304,38 @@ describe("Settings dialog", () => {
|
||||
expect(settingsSet).toHaveBeenCalledExactlyOnceWith("project", "languages.ruff.fixOnSave", "true");
|
||||
});
|
||||
|
||||
it("notes on both pages that a selected Black wins when Ruff is selected too", async () => {
|
||||
useProject.setState({ project: { root: "/project" } as never });
|
||||
useProject.setState({
|
||||
settings: setAt(setAt(current, "languages.ruff.prefer", true), "languages.black.prefer", true),
|
||||
});
|
||||
// The Ruff page names Black as the winner and the way out.
|
||||
const ruff = await openDialog("python.ruff");
|
||||
expect(within(ruff).getByRole("note")).toHaveTextContent(
|
||||
/Black is selected on its page too\. When both are selected, Black formats Python; switch/,
|
||||
);
|
||||
// The Black page states the same outcome without the switch instruction.
|
||||
cleanup();
|
||||
const black = await openDialog("python.black");
|
||||
expect(within(black).getByRole("note")).toHaveTextContent(
|
||||
/Black is selected here and Ruff is selected on its page too\. When both are selected, Black formats Python\./,
|
||||
);
|
||||
});
|
||||
|
||||
it("shows no overlap note while only one of the tools is selected", async () => {
|
||||
useProject.setState({ project: { root: "/project" } as never });
|
||||
useProject.setState({ settings: setAt(current, "languages.ruff.prefer", true) });
|
||||
const ruff = await openDialog("python.ruff");
|
||||
expect(within(ruff).queryByRole("note")).not.toBeInTheDocument();
|
||||
// An unrelated formatter page never grows the note, even with both Python tools selected.
|
||||
useProject.setState({
|
||||
settings: setAt(setAt(current, "languages.ruff.prefer", true), "languages.black.prefer", true),
|
||||
});
|
||||
cleanup();
|
||||
const prettier = await openDialog("languages.prettier");
|
||||
expect(within(prettier).queryByRole("note")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("offers Ruff safe fixes as a distinct before-commit modification", async () => {
|
||||
const dialog = await openDialog("vcs.commit");
|
||||
const fix = within(dialog).getByRole("checkbox", { name: "Fix Ruff safe lint issues" });
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useId, type ReactNode } from "react";
|
||||
import type { ExternalFormatter } from "@/bindings";
|
||||
import { IconButton, Input } from "@/ui";
|
||||
import { IconButton, Input, T } from "@/ui";
|
||||
import { Row, Section, Select, Toggle } from "../components/Form";
|
||||
import { useSetting } from "../components/context";
|
||||
import { DEFAULT_LANGUAGES } from "@/platform/languageSettings";
|
||||
@@ -55,6 +55,13 @@ function FormatterPage({
|
||||
const [languages, setLanguages] = useSetting<string[]>(`languages.${tool}.languages`);
|
||||
const [prefer, setPrefer] = useSetting<boolean>(`languages.${tool}.prefer`);
|
||||
const [save, setSave] = useSetting<boolean>(`languages.${tool}.runOnSave`);
|
||||
// Ruff and Black format the same language: when both are selected, Black wins
|
||||
// (external_tool's explicit-selection order). Only these two pages have a peer
|
||||
// that can shadow them, and only the losing page needs to say so.
|
||||
const blackPrefer = useSetting<boolean>("languages.black.prefer")[0];
|
||||
const ruffPrefer = useSetting<boolean>("languages.ruff.prefer")[0];
|
||||
const otherSelected = tool === "ruff" ? blackPrefer : tool === "black" ? ruffPrefer : false;
|
||||
const bothSelected = prefer && otherSelected;
|
||||
return (
|
||||
<>
|
||||
<Section title={name}>
|
||||
@@ -73,6 +80,21 @@ function FormatterPage({
|
||||
]}
|
||||
/>
|
||||
</Row>
|
||||
{bothSelected && (
|
||||
<div className={styles.note} role="note">
|
||||
{tool === "black" ? (
|
||||
<T>
|
||||
Black is selected here and Ruff is selected on its page too. When both are selected, Black formats
|
||||
Python.
|
||||
</T>
|
||||
) : (
|
||||
<T>
|
||||
Ruff is selected here and Black is selected on its page too. When both are selected, Black formats
|
||||
Python; switch this page's formatting provider back to Automatic to format with Ruff.
|
||||
</T>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<Toggle label={saveLabel} checked={save} onChange={setSave} hint={saveHint} />
|
||||
{children}
|
||||
</Section>
|
||||
|
||||
@@ -1299,6 +1299,8 @@
|
||||
"Select Ruff Configuration Directory": "Select Ruff Configuration Directory",
|
||||
"Empty uses the nearest project pyproject.toml ([tool.ruff]), ruff.toml, or .ruff.toml. A configured directory must contain one of them.": "Empty uses the nearest project pyproject.toml ([tool.ruff]), ruff.toml, or .ruff.toml. A configured directory must contain one of them.",
|
||||
"Ruff reads the nearest pyproject.toml ([tool.ruff]), ruff.toml, or .ruff.toml. When selected, Ruff formats Python before the language server, even below a pyproject.toml with [tool.black].": "Ruff reads the nearest pyproject.toml ([tool.ruff]), ruff.toml, or .ruff.toml. When selected, Ruff formats Python before the language server, even below a pyproject.toml with [tool.black].",
|
||||
"Ruff is selected here and Black is selected on its page too. When both are selected, Black formats Python; switch this page's formatting provider back to Automatic to format with Ruff.": "Ruff is selected here and Black is selected on its page too. When both are selected, Black formats Python; switch this page's formatting provider back to Automatic to format with Ruff.",
|
||||
"Black is selected here and Ruff is selected on its page too. When both are selected, Black formats Python.": "Black is selected here and Ruff is selected on its page too. When both are selected, Black formats Python.",
|
||||
"Run Ruff formatting on save for enabled languages when it is the selected formatting provider.": "Run Ruff formatting on save for enabled languages when it is the selected formatting provider.",
|
||||
"Format on save": "Format on save",
|
||||
"Fix safe lint issues on save": "Fix safe lint issues on save",
|
||||
|
||||
@@ -9754,5 +9754,7 @@
|
||||
"Auto uses 3.0.x for Vue 2 projects and the latest release for Vue 3.": "自動選擇時,Vue 2 專案使用 3.0.x,Vue 3 專案使用最新版本。",
|
||||
"Enter latest, 3.0.x, or an exact Vue Language Server version.": "請輸入 latest、3.0.x 或 Vue 語言伺服器的確切版本。",
|
||||
"Ruff reads the nearest pyproject.toml ([tool.ruff]), ruff.toml, or .ruff.toml. When selected, Ruff formats Python before the language server, even below a pyproject.toml with [tool.black].": "Ruff 會讀取最近的 pyproject.toml([tool.ruff])、ruff.toml 或 .ruff.toml。選擇 Ruff 後,它會先於語言伺服器格式化 Python,即使所在的 pyproject.toml 含有 [tool.black]。",
|
||||
"Ruff is selected here and Black is selected on its page too. When both are selected, Black formats Python; switch this page's formatting provider back to Automatic to format with Ruff.": "此處選擇了 Ruff,Black 頁也選擇了 Black。兩者都選擇時由 Black 格式化 Python;要將本頁的格式化改用 Ruff,請把此處的格式化工具改回自動。",
|
||||
"Black is selected here and Ruff is selected on its page too. When both are selected, Black formats Python.": "此處選擇了 Black,Ruff 頁也選擇了 Ruff。兩者都選擇時由 Black 格式化 Python。",
|
||||
"Black formats Python instead of Ruff below a pyproject.toml with [tool.black]. When selected, Black formats Python without [tool.black] too, and before a selected Ruff.": "在含 [tool.black] 的 pyproject.toml 所在目錄及其子目錄中,Black 取代 Ruff 格式化 Python。選擇 Black 後,沒有 [tool.black] 時也由它格式化,並優先於已選擇的 Ruff。"
|
||||
}
|
||||
@@ -3245,6 +3245,8 @@
|
||||
"Runs ruff check --fix-only on Python files before composing the commit. This does not format code.": "提交前对 Python 文件运行 ruff check --fix-only。此操作不会格式化代码。",
|
||||
"oxfmt formats an enabled language instead of Prettier below an oxfmt configuration file (.oxfmtrc.json, oxfmt.config.ts) or when it is the selected provider.": "在 oxfmt 配置文件(.oxfmtrc.json、oxfmt.config.ts)所在目录及其子目录中,或选择 oxfmt 作为格式化工具时,oxfmt 将代替 Prettier 格式化已启用的语言。",
|
||||
"Ruff reads the nearest pyproject.toml ([tool.ruff]), ruff.toml, or .ruff.toml. When selected, Ruff formats Python before the language server, even below a pyproject.toml with [tool.black].": "Ruff 会读取最近的 pyproject.toml([tool.ruff])、ruff.toml 或 .ruff.toml。选择 Ruff 后,它会先于语言服务器格式化 Python,即使所在的 pyproject.toml 含有 [tool.black]。",
|
||||
"Ruff is selected here and Black is selected on its page too. When both are selected, Black formats Python; switch this page's formatting provider back to Automatic to format with Ruff.": "此处选择了 Ruff,Black 页也选择了 Black。两者都选择时由 Black 格式化 Python;要将本页的格式化改用 Ruff,请把此处的格式化工具改回自动。",
|
||||
"Black is selected here and Ruff is selected on its page too. When both are selected, Black formats Python.": "此处选择了 Black,Ruff 页也选择了 Ruff。两者都选择时由 Black 格式化 Python。",
|
||||
"Enabled languages": "启用的语言",
|
||||
"Reformat Code needs {name}. Install it via {method}?": "重新格式化代码需要 {name}。是否通过 {method} 安装?",
|
||||
"{refactoring} needs {name}. Install it via {method}?": "{refactoring}需要 {name}。是否通过 {method} 安装?",
|
||||
|
||||
Reference in new issue
Заблокувати користувача