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

Remove min and max range on line-length JSON schema #7875

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 2 additions & 3 deletions crates/ruff_workspace/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ use std::collections::BTreeSet;
use std::hash::BuildHasherDefault;

use regex::Regex;
use ruff_formatter::IndentStyle;
use rustc_hash::{FxHashMap, FxHashSet};
use serde::{Deserialize, Serialize};
use strum::IntoEnumIterator;

use crate::options_base::{OptionsMetadata, Visit};
use ruff_formatter::IndentStyle;
use ruff_linter::line_width::{LineLength, TabSize};
use ruff_linter::rules::flake8_pytest_style::settings::SettingsError;
use ruff_linter::rules::flake8_pytest_style::types;
Expand All @@ -30,6 +29,7 @@ use ruff_linter::{warn_user_once, RuleSelector};
use ruff_macros::{CombineOptions, OptionsMetadata};
use ruff_python_formatter::QuoteStyle;

use crate::options_base::{OptionsMetadata, Visit};
use crate::settings::LineEnding;

#[derive(Debug, PartialEq, Eq, Default, OptionsMetadata, Serialize, Deserialize)]
Expand Down Expand Up @@ -362,7 +362,6 @@ pub struct Options {
line-length = 120
"#
)]
#[cfg_attr(feature = "schemars", schemars(range(min = 1, max = 320)))]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWICT, it looks like this is applying to the Option<LineLength>, rather than the LineLength inside the Option?

Copy link
Contributor

@henryiii henryiii Oct 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I can replicate it with a MWE:

use schemars::{schema_for, JsonSchema};

#[derive(JsonSchema)]
pub struct MyStruct {
    pub my_int: i32,
}

#[derive(JsonSchema)]
pub struct MyConfig {
    #[schemars(range(min = 1, max = 320))]
    my_struct: Option<MyStruct>,
}

fn main() {
    let schema = schema_for!(MyConfig);
    println!("{}", serde_json::to_string_pretty(&schema).unwrap());
}

And one fix is to move the location of the attribute:

use schemars::{schema_for, JsonSchema};

#[derive(JsonSchema)]
pub struct MyStruct {
    #[schemars(range(min = 1, max = 320))]
    pub my_int: i32,
}

#[derive(JsonSchema)]
pub struct MyConfig {
    my_struct: Option<MyStruct>,
}

fn main() {
    let schema = schema_for!(MyConfig);
    println!("{}", serde_json::to_string_pretty(&schema).unwrap());
}

But not sure how that works from the outer location, and not sure what cfg_attrs is (nevermind, I do). I see an inner(), but it seems to only apply to things like Vector, not to Enums.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, I know what that is, and how to fix it (I think).

pub line_length: Option<LineLength>,

/// The tabulation size to calculate line length.
Expand Down
4 changes: 1 addition & 3 deletions ruff.schema.json

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

Loading