-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathsettings.rs
94 lines (83 loc) · 2.27 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
//! Settings for the `flake8-quotes` plugin.
use serde::{Deserialize, Serialize};
use std::fmt::{Display, Formatter};
use crate::display_settings;
use ruff_macros::CacheKey;
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, CacheKey)]
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub enum Quote {
/// Use double quotes.
Double,
/// Use single quotes.
Single,
}
impl Default for Quote {
fn default() -> Self {
Self::Double
}
}
impl From<ruff_python_parser::QuoteStyle> for Quote {
fn from(value: ruff_python_parser::QuoteStyle) -> Self {
match value {
ruff_python_parser::QuoteStyle::Double => Self::Double,
ruff_python_parser::QuoteStyle::Single => Self::Single,
}
}
}
#[derive(Debug, CacheKey)]
pub struct Settings {
pub inline_quotes: Quote,
pub multiline_quotes: Quote,
pub docstring_quotes: Quote,
pub avoid_escape: bool,
}
impl Default for Settings {
fn default() -> Self {
Self {
inline_quotes: Quote::default(),
multiline_quotes: Quote::default(),
docstring_quotes: Quote::default(),
avoid_escape: true,
}
}
}
impl Display for Settings {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
display_settings! {
formatter = f,
namespace = "linter.flake8_quotes",
fields = [
self.inline_quotes,
self.multiline_quotes,
self.docstring_quotes,
self.avoid_escape
]
}
Ok(())
}
}
impl Quote {
#[must_use]
pub const fn opposite(self) -> Self {
match self {
Self::Double => Self::Single,
Self::Single => Self::Double,
}
}
/// Get the character used to represent this quote.
pub const fn as_char(self) -> char {
match self {
Self::Double => '"',
Self::Single => '\'',
}
}
}
impl Display for Quote {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::Double => write!(f, "double"),
Self::Single => write!(f, "single"),
}
}
}