Skip to content

Commit

Permalink
Add pycodestyle::settings
Browse files Browse the repository at this point in the history
This step is split up into a separate commit so
that the following commit has a cleaner diff.
  • Loading branch information
not-my-profile authored and charliermarsh committed Jan 5, 2023
1 parent 8d56e41 commit 78c9056
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -3035,6 +3035,8 @@ staticmethod-decorators = ["staticmethod", "stcmthd"]
---
### `pycodestyle`
### `pydocstyle`
#### [`convention`](#convention)
Expand Down
7 changes: 7 additions & 0 deletions flake8_to_ruff/src/converter.rs
Expand Up @@ -404,6 +404,7 @@ mod tests {
isort: None,
mccabe: None,
pep8_naming: None,
pycodestyle: None,
pydocstyle: None,
pyupgrade: None,
});
Expand Down Expand Up @@ -466,6 +467,7 @@ mod tests {
isort: None,
mccabe: None,
pep8_naming: None,
pycodestyle: None,
pydocstyle: None,
pyupgrade: None,
});
Expand Down Expand Up @@ -528,6 +530,7 @@ mod tests {
isort: None,
mccabe: None,
pep8_naming: None,
pycodestyle: None,
pydocstyle: None,
pyupgrade: None,
});
Expand Down Expand Up @@ -590,6 +593,7 @@ mod tests {
isort: None,
mccabe: None,
pep8_naming: None,
pycodestyle: None,
pydocstyle: None,
pyupgrade: None,
});
Expand Down Expand Up @@ -657,6 +661,7 @@ mod tests {
isort: None,
mccabe: None,
pep8_naming: None,
pycodestyle: None,
pydocstyle: None,
pyupgrade: None,
});
Expand Down Expand Up @@ -723,6 +728,7 @@ mod tests {
isort: None,
mccabe: None,
pep8_naming: None,
pycodestyle: None,
pydocstyle: Some(pydocstyle::settings::Options {
convention: Some(Convention::Numpy),
}),
Expand Down Expand Up @@ -793,6 +799,7 @@ mod tests {
isort: None,
mccabe: None,
pep8_naming: None,
pycodestyle: None,
pydocstyle: None,
pyupgrade: None,
});
Expand Down
15 changes: 15 additions & 0 deletions ruff.schema.json
Expand Up @@ -299,6 +299,17 @@
}
}
},
"pycodestyle": {
"description": "Options for the `pycodestyle` plugin.",
"anyOf": [
{
"$ref": "#/definitions/Pycodestyle"
},
{
"type": "null"
}
]
},
"pydocstyle": {
"description": "Options for the `pydocstyle` plugin.",
"anyOf": [
Expand Down Expand Up @@ -1497,6 +1508,10 @@
},
"additionalProperties": false
},
"Pycodestyle": {
"type": "object",
"additionalProperties": false
},
"Pydocstyle": {
"type": "object",
"properties": {
Expand Down
3 changes: 2 additions & 1 deletion src/lib_wasm.rs
Expand Up @@ -18,7 +18,7 @@ use crate::source_code_style::SourceCodeStyleDetector;
use crate::{
directives, flake8_annotations, flake8_bandit, flake8_bugbear, flake8_errmsg,
flake8_import_conventions, flake8_pytest_style, flake8_quotes, flake8_tidy_imports,
flake8_unused_arguments, isort, mccabe, pep8_naming, pydocstyle, pyupgrade,
flake8_unused_arguments, isort, mccabe, pep8_naming, pycodestyle, pydocstyle, pyupgrade,
};

const VERSION: &str = env!("CARGO_PKG_VERSION");
Expand Down Expand Up @@ -131,6 +131,7 @@ pub fn defaultSettings() -> Result<JsValue, JsValue> {
isort: Some(isort::settings::Settings::default().into()),
mccabe: Some(mccabe::settings::Settings::default().into()),
pep8_naming: Some(pep8_naming::settings::Settings::default().into()),
pycodestyle: Some(pycodestyle::settings::Settings::default().into()),
pydocstyle: Some(pydocstyle::settings::Settings::default().into()),
pyupgrade: Some(pyupgrade::settings::Settings::default().into()),
})?)
Expand Down
1 change: 1 addition & 0 deletions src/pycodestyle/mod.rs
@@ -1,5 +1,6 @@
pub mod checks;
pub mod plugins;
pub mod settings;

#[cfg(test)]
mod tests {
Expand Down
26 changes: 26 additions & 0 deletions src/pycodestyle/settings.rs
@@ -0,0 +1,26 @@
//! Settings for the `pycodestyle` plugin.

use ruff_macros::ConfigurationOptions;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

#[derive(
Debug, PartialEq, Eq, Serialize, Deserialize, Default, ConfigurationOptions, JsonSchema,
)]
#[serde(deny_unknown_fields, rename_all = "kebab-case", rename = "Pycodestyle")]
pub struct Options {}

#[derive(Debug, Default, Hash)]
pub struct Settings {}

impl From<Options> for Settings {
fn from(options: Options) -> Self {
Self {}
}
}

impl From<Settings> for Options {
fn from(settings: Settings) -> Self {
Self {}
}
}
5 changes: 4 additions & 1 deletion src/settings/configuration.rs
Expand Up @@ -22,7 +22,7 @@ use crate::settings::types::{
use crate::{
flake8_annotations, flake8_bandit, flake8_bugbear, flake8_errmsg, flake8_import_conventions,
flake8_pytest_style, flake8_quotes, flake8_tidy_imports, flake8_unused_arguments, fs, isort,
mccabe, pep8_naming, pydocstyle, pyupgrade,
mccabe, pep8_naming, pycodestyle, pydocstyle, pyupgrade,
};

#[derive(Debug, Default)]
Expand Down Expand Up @@ -67,6 +67,7 @@ pub struct Configuration {
pub isort: Option<isort::settings::Options>,
pub mccabe: Option<mccabe::settings::Options>,
pub pep8_naming: Option<pep8_naming::settings::Options>,
pub pycodestyle: Option<pycodestyle::settings::Options>,
pub pydocstyle: Option<pydocstyle::settings::Options>,
pub pyupgrade: Option<pyupgrade::settings::Options>,
}
Expand Down Expand Up @@ -166,6 +167,7 @@ impl Configuration {
isort: options.isort,
mccabe: options.mccabe,
pep8_naming: options.pep8_naming,
pycodestyle: options.pycodestyle,
pydocstyle: options.pydocstyle,
pyupgrade: options.pyupgrade,
})
Expand Down Expand Up @@ -232,6 +234,7 @@ impl Configuration {
isort: self.isort.or(config.isort),
mccabe: self.mccabe.or(config.mccabe),
pep8_naming: self.pep8_naming.or(config.pep8_naming),
pycodestyle: self.pycodestyle.or(config.pycodestyle),
pydocstyle: self.pydocstyle.or(config.pydocstyle),
pyupgrade: self.pyupgrade.or(config.pyupgrade),
}
Expand Down
9 changes: 8 additions & 1 deletion src/settings/mod.rs
Expand Up @@ -26,7 +26,7 @@ use crate::settings::types::{
use crate::{
flake8_annotations, flake8_bandit, flake8_bugbear, flake8_errmsg, flake8_import_conventions,
flake8_pytest_style, flake8_quotes, flake8_tidy_imports, flake8_unused_arguments, isort,
mccabe, one_time_warning, pep8_naming, pydocstyle, pyupgrade,
mccabe, one_time_warning, pep8_naming, pycodestyle, pydocstyle, pyupgrade,
};

pub mod configuration;
Expand Down Expand Up @@ -75,6 +75,7 @@ pub struct Settings {
pub isort: isort::settings::Settings,
pub mccabe: mccabe::settings::Settings,
pub pep8_naming: pep8_naming::settings::Settings,
pub pycodestyle: pycodestyle::settings::Settings,
pub pydocstyle: pydocstyle::settings::Settings,
pub pyupgrade: pyupgrade::settings::Settings,
}
Expand Down Expand Up @@ -228,6 +229,10 @@ impl Settings {
.pep8_naming
.map(std::convert::Into::into)
.unwrap_or_default(),
pycodestyle: config
.pycodestyle
.map(std::convert::Into::into)
.unwrap_or_default(),
pydocstyle: config
.pydocstyle
.map(std::convert::Into::into)
Expand Down Expand Up @@ -275,6 +280,7 @@ impl Settings {
isort: isort::settings::Settings::default(),
mccabe: mccabe::settings::Settings::default(),
pep8_naming: pep8_naming::settings::Settings::default(),
pycodestyle: pycodestyle::settings::Settings::default(),
pydocstyle: pydocstyle::settings::Settings::default(),
pyupgrade: pyupgrade::settings::Settings::default(),
}
Expand Down Expand Up @@ -316,6 +322,7 @@ impl Settings {
isort: isort::settings::Settings::default(),
mccabe: mccabe::settings::Settings::default(),
pep8_naming: pep8_naming::settings::Settings::default(),
pycodestyle: pycodestyle::settings::Settings::default(),
pydocstyle: pydocstyle::settings::Settings::default(),
pyupgrade: pyupgrade::settings::Settings::default(),
}
Expand Down
5 changes: 4 additions & 1 deletion src/settings/options.rs
Expand Up @@ -10,7 +10,7 @@ use crate::settings::types::{PythonVersion, SerializationFormat, Version};
use crate::{
flake8_annotations, flake8_bandit, flake8_bugbear, flake8_errmsg, flake8_import_conventions,
flake8_pytest_style, flake8_quotes, flake8_tidy_imports, flake8_unused_arguments, isort,
mccabe, pep8_naming, pydocstyle, pyupgrade,
mccabe, pep8_naming, pycodestyle, pydocstyle, pyupgrade,
};

#[derive(
Expand Down Expand Up @@ -394,6 +394,9 @@ pub struct Options {
/// Options for the `pep8-naming` plugin.
pub pep8_naming: Option<pep8_naming::settings::Options>,
#[option_group]
/// Options for the `pycodestyle` plugin.
pub pycodestyle: Option<pycodestyle::settings::Options>,
#[option_group]
/// Options for the `pydocstyle` plugin.
pub pydocstyle: Option<pydocstyle::settings::Options>,
#[option_group]
Expand Down
6 changes: 6 additions & 0 deletions src/settings/pyproject.rs
Expand Up @@ -202,6 +202,7 @@ mod tests {
isort: None,
mccabe: None,
pep8_naming: None,
pycodestyle: None,
pydocstyle: None,
pyupgrade: None,
})
Expand Down Expand Up @@ -258,6 +259,7 @@ line-length = 79
isort: None,
mccabe: None,
pep8_naming: None,
pycodestyle: None,
pydocstyle: None,
pyupgrade: None,
})
Expand Down Expand Up @@ -314,6 +316,7 @@ exclude = ["foo.py"]
isort: None,
mccabe: None,
pep8_naming: None,
pycodestyle: None,
pydocstyle: None,
pyupgrade: None,
})
Expand Down Expand Up @@ -370,6 +373,7 @@ select = ["E501"]
isort: None,
mccabe: None,
pep8_naming: None,
pycodestyle: None,
pydocstyle: None,
pyupgrade: None,
})
Expand Down Expand Up @@ -427,6 +431,7 @@ ignore = ["E501"]
isort: None,
mccabe: None,
pep8_naming: None,
pycodestyle: None,
pydocstyle: None,
pyupgrade: None,
})
Expand Down Expand Up @@ -604,6 +609,7 @@ other-attribute = 1
]),
staticmethod_decorators: Some(vec!["staticmethod".to_string()]),
}),
pycodestyle: None,
pydocstyle: None,
pyupgrade: None,
}
Expand Down

0 comments on commit 78c9056

Please sign in to comment.