Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hidden --preview / --no-preview options to ruff check #7009

Merged
merged 7 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/ruff/src/settings/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ impl Default for Settings {
line_length: LineLength::default(),
logger_objects: vec![],
namespace_packages: vec![],
preview_mode: false,
per_file_ignores: vec![],
project_root: path_dedot::CWD.clone(),
respect_gitignore: true,
Expand Down
1 change: 1 addition & 0 deletions crates/ruff/src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub struct Settings {
pub per_file_ignores: Vec<(GlobMatcher, GlobMatcher, RuleSet)>,

pub target_version: PythonVersion,
pub preview_mode: bool,

// Resolver settings
pub exclude: FilePatternSet,
Expand Down
10 changes: 10 additions & 0 deletions crates/ruff_cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ pub struct CheckCommand {
/// The minimum Python version that should be supported.
#[arg(long, value_enum)]
pub target_version: Option<PythonVersion>,
/// Enable preview mode
#[arg(long, overrides_with("no_preview"), hide = true)]
preview: bool,
#[clap(long, overrides_with("preview"), hide = true)]
no_preview: bool,
/// Path to the `pyproject.toml` or `ruff.toml` file to use for
/// configuration.
#[arg(long, conflicts_with = "isolated")]
Expand Down Expand Up @@ -458,6 +463,7 @@ impl CheckCommand {
ignore: self.ignore,
line_length: self.line_length,
per_file_ignores: self.per_file_ignores,
preview_mode: resolve_bool_arg(self.preview, self.no_preview),
respect_gitignore: resolve_bool_arg(
self.respect_gitignore,
self.no_respect_gitignore,
Expand Down Expand Up @@ -569,6 +575,7 @@ pub struct Overrides {
pub ignore: Option<Vec<RuleSelector>>,
pub line_length: Option<LineLength>,
pub per_file_ignores: Option<Vec<PatternPrefixPair>>,
pub preview_mode: Option<bool>,
pub respect_gitignore: Option<bool>,
pub select: Option<Vec<RuleSelector>>,
pub show_source: Option<bool>,
Expand Down Expand Up @@ -632,6 +639,9 @@ impl ConfigProcessor for Overrides {
if let Some(line_length) = &self.line_length {
config.line_length = Some(*line_length);
}
if let Some(preview_mode) = &self.preview_mode {
config.preview_mode = Some(*preview_mode);
}
if let Some(per_file_ignores) = &self.per_file_ignores {
config.per_file_ignores = Some(collect_per_file_ignores(per_file_ignores.clone()));
}
Expand Down
1 change: 1 addition & 0 deletions crates/ruff_wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ impl Workspace {
external: Some(Vec::default()),
ignore: Some(Vec::default()),
line_length: Some(LineLength::default()),
preview_mode: Some(false),
select: Some(defaults::PREFIXES.to_vec()),
tab_size: Some(TabSize::default()),
target_version: Some(PythonVersion::default()),
Expand Down
4 changes: 4 additions & 0 deletions crates/ruff_workspace/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub struct Configuration {
pub line_length: Option<LineLength>,
pub logger_objects: Option<Vec<String>>,
pub namespace_packages: Option<Vec<PathBuf>>,
pub preview_mode: Option<bool>,
pub required_version: Option<Version>,
pub respect_gitignore: Option<bool>,
pub show_fixes: Option<bool>,
Expand Down Expand Up @@ -174,6 +175,7 @@ impl Configuration {
.collect()
}),
logger_objects: self.logger_objects.unwrap_or_default(),
preview_mode: self.preview_mode.unwrap_or_default(),
typing_modules: self.typing_modules.unwrap_or_default(),
// Plugins
flake8_annotations: self
Expand Down Expand Up @@ -387,6 +389,7 @@ impl Configuration {
.namespace_packages
.map(|namespace_package| resolve_src(&namespace_package, project_root))
.transpose()?,
preview_mode: options.preview_mode,
per_file_ignores: options.per_file_ignores.map(|per_file_ignores| {
per_file_ignores
.into_iter()
Expand Down Expand Up @@ -676,6 +679,7 @@ impl Configuration {
show_fixes: self.show_fixes.or(config.show_fixes),
src: self.src.or(config.src),
target_version: self.target_version.or(config.target_version),
preview_mode: self.preview_mode.or(config.preview_mode),
task_tags: self.task_tags.or(config.task_tags),
typing_modules: self.typing_modules.or(config.typing_modules),
// Plugins
Expand Down
11 changes: 11 additions & 0 deletions crates/ruff_workspace/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,17 @@ pub struct Options {
/// field (e.g., `requires-python = ">=3.8"`). If Ruff is configured via
/// `ruff.toml` or `.ruff.toml`, no such inference will be performed.
pub target_version: Option<PythonVersion>,
#[option(
default = "false",
value_type = "bool",
example = r#"
# Enable preview mode
preview-mode = true
"#
)]
/// Whether to enable preview mode. When preview mode is enabled, Ruff will
/// use unstable rules and fixes.
pub preview_mode: Option<bool>,
#[option(
default = r#"["TODO", "FIXME", "XXX"]"#,
value_type = "list[str]",
Expand Down
7 changes: 7 additions & 0 deletions ruff.schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.