-
Notifications
You must be signed in to change notification settings - Fork 882
/
settings.rs
112 lines (104 loc) · 3.5 KB
/
settings.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//! Settings for the `pydocstyle` plugin.
use ruff_macros::ConfigurationOptions;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use crate::registry_gen::CheckCodePrefix;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Hash, JsonSchema)]
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
pub enum Convention {
/// Use Google-style docstrings.
Google,
/// Use NumPy-style docstrings.
Numpy,
/// Use PEP257-style docstrings.
Pep257,
}
impl Convention {
pub fn codes(&self) -> &'static [CheckCodePrefix] {
match self {
Convention::Google => &[
// All errors except D203, D204, D213, D215, D400, D401, D404, D406, D407, D408,
// D409 and D413.
CheckCodePrefix::D203,
CheckCodePrefix::D204,
CheckCodePrefix::D213,
CheckCodePrefix::D215,
CheckCodePrefix::D400,
CheckCodePrefix::D404,
CheckCodePrefix::D406,
CheckCodePrefix::D407,
CheckCodePrefix::D408,
CheckCodePrefix::D409,
CheckCodePrefix::D413,
],
Convention::Numpy => &[
// All errors except D107, D203, D212, D213, D402, D413, D415, D416, and D417.
CheckCodePrefix::D107,
CheckCodePrefix::D203,
CheckCodePrefix::D212,
CheckCodePrefix::D213,
CheckCodePrefix::D402,
CheckCodePrefix::D413,
CheckCodePrefix::D415,
CheckCodePrefix::D416,
CheckCodePrefix::D417,
],
Convention::Pep257 => &[
// All errors except D203, D212, D213, D214, D215, D404, D405, D406, D407, D408,
// D409, D410, D411, D413, D415, D416 and D417.
CheckCodePrefix::D203,
CheckCodePrefix::D212,
CheckCodePrefix::D213,
CheckCodePrefix::D214,
CheckCodePrefix::D215,
CheckCodePrefix::D404,
CheckCodePrefix::D405,
CheckCodePrefix::D406,
CheckCodePrefix::D407,
CheckCodePrefix::D408,
CheckCodePrefix::D409,
CheckCodePrefix::D410,
CheckCodePrefix::D411,
CheckCodePrefix::D413,
CheckCodePrefix::D415,
CheckCodePrefix::D416,
CheckCodePrefix::D417,
],
}
}
}
#[derive(
Debug, PartialEq, Eq, Serialize, Deserialize, Default, ConfigurationOptions, JsonSchema,
)]
#[serde(deny_unknown_fields, rename_all = "kebab-case", rename = "Pydocstyle")]
pub struct Options {
#[option(
default = r#"None"#,
value_type = "Convention",
example = r#"
# Use Google-style docstrings.
convention = "google"
"#
)]
/// Whether to use Google-style or NumPy-style conventions or the PEP257
/// defaults when analyzing docstring sections.
pub convention: Option<Convention>,
}
#[derive(Debug, Default, Hash)]
pub struct Settings {
pub convention: Option<Convention>,
}
impl From<Options> for Settings {
fn from(options: Options) -> Self {
Self {
convention: options.convention,
}
}
}
impl From<Settings> for Options {
fn from(settings: Settings) -> Self {
Self {
convention: settings.convention,
}
}
}