Add --extension support to the formatter (#9483)

## Summary

We added `--extension` to `ruff check`, but it's equally applicable to
`ruff format`.

Closes https://github.com/astral-sh/ruff/issues/9482.

Resolves https://github.com/astral-sh/ruff/discussions/9481.

## Test Plan

`cargo test`
This commit is contained in:
Charlie Marsh 2024-01-12 13:53:25 -05:00 committed by GitHub
parent d16c4a2d25
commit 3261d16e61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 221 additions and 51 deletions

View file

@ -1,7 +1,9 @@
use path_absolutize::path_dedot;
use ruff_cache::cache_dir;
use ruff_formatter::{FormatOptions, IndentStyle, IndentWidth, LineWidth};
use ruff_linter::settings::types::{FilePattern, FilePatternSet, SerializationFormat, UnsafeFixes};
use ruff_linter::settings::types::{
ExtensionMapping, FilePattern, FilePatternSet, SerializationFormat, UnsafeFixes,
};
use ruff_linter::settings::LinterSettings;
use ruff_macros::CacheKey;
use ruff_python_ast::PySourceType;
@ -116,6 +118,7 @@ impl FileResolverSettings {
#[derive(CacheKey, Clone, Debug)]
pub struct FormatterSettings {
pub exclude: FilePatternSet,
pub extension: ExtensionMapping,
pub preview: PreviewMode,
pub target_version: ruff_python_formatter::PythonVersion,
@ -177,6 +180,7 @@ impl Default for FormatterSettings {
Self {
exclude: FilePatternSet::default(),
extension: ExtensionMapping::default(),
target_version: default_options.target_version(),
preview: PreviewMode::Disabled,
line_width: default_options.line_width(),