Visitar URL original
Stabilize Markdown formatting (#27018) · astral-sh/ruff@c6519be · GitHub
Skip to content

Commit c6519be

Browse files
authored
Stabilize Markdown formatting (#27018)
Summary -- This PR stabilizes the Markdown formatting initially added in #22470. It also reverts much of the error plumbing in the LSP that was added in #24150. I considered keeping the `FormatResult::PreviewOnly` variant but went ahead and dropped it since it was unused. Closes #26866. Test Plan -- Updated existing snapshots, dropping `--preview` in some cases
1 parent 3ec7d59 commit c6519be

20 files changed

Lines changed: 41 additions & 130 deletions

‎crates/ruff/src/commands/format.rs‎

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -489,12 +489,6 @@ pub(crate) fn format_source(
489489
)))
490490
}
491491
SourceKind::Markdown(unformatted_document) => {
492-
if !settings.preview.is_enabled() {
493-
return Err(FormatCommandError::MarkdownExperimental(
494-
path.map(Path::to_path_buf),
495-
));
496-
}
497-
498492
if range.is_some() {
499493
return Err(FormatCommandError::RangeFormatNotSupported(
500494
path.map(Path::to_path_buf),
@@ -829,7 +823,6 @@ pub(crate) enum FormatCommandError {
829823
Format(Option<PathBuf>, FormatModuleError),
830824
Write(Option<PathBuf>, SourceError),
831825
RangeFormatNotSupported(Option<PathBuf>),
832-
MarkdownExperimental(Option<PathBuf>),
833826
}
834827

835828
impl FormatCommandError {
@@ -847,8 +840,7 @@ impl FormatCommandError {
847840
| Self::Read(path, _)
848841
| Self::Format(path, _)
849842
| Self::Write(path, _)
850-
| Self::RangeFormatNotSupported(path)
851-
| Self::MarkdownExperimental(path) => path.as_deref(),
843+
| Self::RangeFormatNotSupported(path) => path.as_deref(),
852844
}
853845
}
854846
}
@@ -885,11 +877,6 @@ impl From<&FormatCommandError> for Diagnostic {
885877
Severity::Error,
886878
"Range formatting is only supported for Python files.",
887879
),
888-
FormatCommandError::MarkdownExperimental(_) => Diagnostic::new(
889-
DiagnosticId::PreviewFeature,
890-
Severity::Warning,
891-
"Markdown formatting is experimental, enable preview mode.",
892-
),
893880
};
894881

895882
if let Some(annotation) = annotation {
@@ -984,23 +971,6 @@ impl Display for FormatCommandError {
984971
)
985972
}
986973
}
987-
Self::MarkdownExperimental(path) => {
988-
if let Some(path) = path {
989-
write!(
990-
f,
991-
"{header}{path}{colon} Markdown formatting is experimental, enable preview mode.",
992-
header = "Failed to format ".bold(),
993-
path = fs::relativize_path(path).bold(),
994-
colon = ":".bold()
995-
)
996-
} else {
997-
write!(
998-
f,
999-
"{header} Markdown formatting is experimental, enable preview mode",
1000-
header = "Failed to format:".bold()
1001-
)
1002-
}
1003-
}
1004974
Self::Panic(path, err) => {
1005975
let message = r"This indicates a bug in Ruff. If you could open an issue at:
1006976

‎crates/ruff/tests/cli/format.rs‎

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2504,31 +2504,12 @@ fn cookiecutter_globbing() -> Result<()> {
25042504
}
25052505

25062506
#[test]
2507-
fn markdown_formatting_preview_disabled() -> Result<()> {
2507+
fn markdown_formatting() -> Result<()> {
25082508
let test = CliTest::new()?;
25092509
let unformatted = test.fixture_path("unformatted.md");
25102510

25112511
assert_cmd_snapshot!(test.format_command()
2512-
.args(["--isolated", "--no-preview", "--diff"])
2513-
.arg(unformatted),
2514-
@"
2515-
success: false
2516-
exit_code: 2
2517-
----- stdout -----
2518-
2519-
----- stderr -----
2520-
error: Failed to format CRATE_ROOT/resources/test/fixtures/unformatted.md: Markdown formatting is experimental, enable preview mode.
2521-
");
2522-
Ok(())
2523-
}
2524-
2525-
#[test]
2526-
fn markdown_formatting_preview_enabled() -> Result<()> {
2527-
let test = CliTest::new()?;
2528-
let unformatted = test.fixture_path("unformatted.md");
2529-
2530-
assert_cmd_snapshot!(test.format_command()
2531-
.args(["--isolated", "--preview", "--check"])
2512+
.args(["--isolated", "--check"])
25322513
.arg(unformatted),
25332514
@r#"
25342515
success: false
@@ -2570,7 +2551,7 @@ fn markdown_formatting_stdin() -> Result<()> {
25702551
let unformatted = fs::read(test.fixture_path("unformatted.md")).unwrap();
25712552

25722553
assert_cmd_snapshot!(test.format_command()
2573-
.args(["--isolated", "--preview", "--stdin-filename", "unformatted.md"])
2554+
.args(["--isolated", "--stdin-filename", "unformatted.md"])
25742555
.arg("-")
25752556
.pass_stdin(unformatted), @r#"
25762557
success: true
@@ -2613,7 +2594,7 @@ print( 'hello' )
26132594
])?;
26142595

26152596
assert_cmd_snapshot!(
2616-
test.format_command().args(["--preview", "--diff", "test.qmd"]),
2597+
test.format_command().args(["--diff", "test.qmd"]),
26172598
@r#"
26182599
success: false
26192600
exit_code: 1
@@ -2666,14 +2647,11 @@ print( 'hello' )
26662647

26672648
assert_cmd_snapshot!(
26682649
test.format_command()
2669-
.args(["format", "--preview", "--check", "."]),
2650+
.args(["--check", "."]),
26702651
@r#"
26712652
success: false
2672-
exit_code: 2
2653+
exit_code: 1
26732654
----- stdout -----
2674-
io: [TMP]/format: No such file or directory (os error 2)
2675-
--> format:1:1
2676-
26772655
unformatted: File would be reformatted
26782656
--> test.bar:1:1
26792657
|

‎crates/ruff/tests/cli/snapshots/cli__lint__requires_python_extend_from_shared_config.snap‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ file_resolver.include = [
6161
"**/pyproject.toml",
6262
"**/ruff.toml",
6363
"**/.ruff.toml",
64+
"*.md",
6465
]
6566
file_resolver.extend_include = []
6667
file_resolver.respect_gitignore = true

‎crates/ruff/tests/cli/snapshots/cli__lint__requires_python_no_tool.snap‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ file_resolver.include = [
6363
"**/pyproject.toml",
6464
"**/ruff.toml",
6565
"**/.ruff.toml",
66+
"*.md",
6667
]
6768
file_resolver.extend_include = []
6869
file_resolver.respect_gitignore = true

‎crates/ruff/tests/cli/snapshots/cli__lint__requires_python_no_tool_target_version_override.snap‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ file_resolver.include = [
6565
"**/pyproject.toml",
6666
"**/ruff.toml",
6767
"**/.ruff.toml",
68+
"*.md",
6869
]
6970
file_resolver.extend_include = []
7071
file_resolver.respect_gitignore = true

‎crates/ruff/tests/cli/snapshots/cli__lint__requires_python_pyproject_toml_above.snap‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ file_resolver.include = [
6262
"**/pyproject.toml",
6363
"**/ruff.toml",
6464
"**/.ruff.toml",
65+
"*.md",
6566
]
6667
file_resolver.extend_include = []
6768
file_resolver.respect_gitignore = true

‎crates/ruff/tests/cli/snapshots/cli__lint__requires_python_pyproject_toml_above_with_tool.snap‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ file_resolver.include = [
6363
"**/pyproject.toml",
6464
"**/ruff.toml",
6565
"**/.ruff.toml",
66+
"*.md",
6667
]
6768
file_resolver.extend_include = []
6869
file_resolver.respect_gitignore = true

‎crates/ruff/tests/cli/snapshots/cli__lint__requires_python_ruff_toml_above-2.snap‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ file_resolver.include = [
6161
"**/pyproject.toml",
6262
"**/ruff.toml",
6363
"**/.ruff.toml",
64+
"*.md",
6465
]
6566
file_resolver.extend_include = []
6667
file_resolver.respect_gitignore = true

‎crates/ruff/tests/cli/snapshots/cli__lint__requires_python_ruff_toml_above.snap‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ file_resolver.include = [
6161
"**/pyproject.toml",
6262
"**/ruff.toml",
6363
"**/.ruff.toml",
64+
"*.md",
6465
]
6566
file_resolver.extend_include = []
6667
file_resolver.respect_gitignore = true

‎crates/ruff/tests/cli/snapshots/cli__lint__requires_python_ruff_toml_no_target_fallback.snap‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ file_resolver.include = [
6161
"**/pyproject.toml",
6262
"**/ruff.toml",
6363
"**/.ruff.toml",
64+
"*.md",
6465
]
6566
file_resolver.extend_include = []
6667
file_resolver.respect_gitignore = true

0 commit comments

Comments
 (0)