Use configured extension mapping to select code block language#22934
Use configured extension mapping to select code block language#22934
Conversation
|
35ed3d0 to
3eebdf9
Compare
Typing conformance resultsNo changes detected ✅ |
|
ntBre
left a comment
There was a problem hiding this comment.
Looks good to me, just a couple of small questions/suggestions.
crates/ruff_markdown/src/lib.rs
Outdated
| // map code block to source type, accounting for configured extension mappings | ||
| let py_source_type = match settings | ||
| .extension | ||
| .get_extension(&language.to_ascii_lowercase()) | ||
| { | ||
| None => PySourceType::from_extension(language), |
There was a problem hiding this comment.
Do we want to pass the lowercased version to PySourceType::from_extension? We may be able to use make_ascii_lowercase if so. It also seems reasonable to accept the input case like we had before, but I'll defer to you.
| // map code block to source type, accounting for configured extension mappings | |
| let py_source_type = match settings | |
| .extension | |
| .get_extension(&language.to_ascii_lowercase()) | |
| { | |
| None => PySourceType::from_extension(language), | |
| language.make_ascii_lowercase(); | |
| // map code block to source type, accounting for configured extension mappings | |
| let py_source_type = match settings | |
| .extension | |
| .get_extension(&language) | |
| { | |
| None => PySourceType::from_extension(language), |
There was a problem hiding this comment.
Updated version passes the lowercased version to both. My main concern with make_ascii_lowercase is that language is already sliced from the original source text that we're eventually pushing onto the stack, so that would end up modifying the language string rather than just the contents of the code block.
crates/ruff_markdown/Cargo.toml
Outdated
| license = { workspace = true } | ||
|
|
||
| [dependencies] | ||
| ruff_linter = { workspace = true } |
There was a problem hiding this comment.
This scared me for a second because I assumed that the formatter depended on ruff_markdown, but that's not the case, right? I just wanted to make sure the formatter doesn't now depend on the linter.
I guess this and insta could actually be [dev-dependencies] too.
There was a problem hiding this comment.
Moved both to dev-dependencies.
There was a problem hiding this comment.
IIUC this won't make the formatter depend on the linter or vice versa, because right now the only crate that depends on ruff_markdown is the main ruff CLI crate.
3eebdf9 to
cefa871
Compare
cefa871 to
b32cf11
Compare
Language::get_extensionto look up extension mappings without aPathobjectformat_code_blocksto obey any configured extension mapping when determining the source type of a code blockpycode block as if it waspyiby using the configured extension mapThis will allow ty run ruff formatting on md test files while force-mapping
pyblocks topyifor condensed formatting results.Issue #22639