mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 12:29:28 +00:00
Introduce FormatterSettings
(#7545)
This commit is contained in:
parent
87a0cd219f
commit
f8f1cd5016
16 changed files with 159 additions and 75 deletions
|
@ -1,21 +1,20 @@
|
|||
use std::num::NonZeroU16;
|
||||
use std::path::Path;
|
||||
|
||||
use js_sys::Error;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
use ruff_formatter::{FormatResult, Formatted, LineWidth};
|
||||
use ruff_formatter::{FormatResult, Formatted};
|
||||
use ruff_linter::directives;
|
||||
use ruff_linter::line_width::{LineLength, TabSize};
|
||||
use ruff_linter::linter::{check_path, LinterResult};
|
||||
use ruff_linter::registry::AsRule;
|
||||
use ruff_linter::settings::types::{PreviewMode, PythonVersion};
|
||||
use ruff_linter::settings::types::PythonVersion;
|
||||
use ruff_linter::settings::{flags, DUMMY_VARIABLE_RGX, PREFIXES};
|
||||
use ruff_linter::source_kind::SourceKind;
|
||||
use ruff_python_ast::{Mod, PySourceType};
|
||||
use ruff_python_codegen::Stylist;
|
||||
use ruff_python_formatter::{format_node, pretty_comments, PyFormatContext, PyFormatOptions};
|
||||
use ruff_python_formatter::{format_node, pretty_comments, PyFormatContext};
|
||||
use ruff_python_index::{CommentRangesBuilder, Indexer};
|
||||
use ruff_python_parser::lexer::LexResult;
|
||||
use ruff_python_parser::{parse_tokens, AsMode, Mode};
|
||||
|
@ -302,15 +301,9 @@ impl<'a> ParsedModule<'a> {
|
|||
|
||||
fn format(&self, settings: &Settings) -> FormatResult<Formatted<PyFormatContext>> {
|
||||
// TODO(konstin): Add an options for py/pyi to the UI (2/2)
|
||||
// TODO(micha): Use formatter settings instead
|
||||
let options = PyFormatOptions::from_source_type(PySourceType::default())
|
||||
.with_preview(match settings.linter.preview {
|
||||
PreviewMode::Disabled => ruff_python_formatter::PreviewMode::Disabled,
|
||||
PreviewMode::Enabled => ruff_python_formatter::PreviewMode::Enabled,
|
||||
})
|
||||
.with_line_width(LineWidth::from(NonZeroU16::from(
|
||||
settings.linter.line_length,
|
||||
)));
|
||||
let options = settings
|
||||
.formatter
|
||||
.to_format_options(PySourceType::default());
|
||||
|
||||
format_node(
|
||||
&self.module,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue