@@ -3,6 +3,7 @@ use rustc_hash::FxHashMap;
33
44use crate :: { FixKind , Rule , RuleKey } ;
55use std:: any:: { Any , TypeId } ;
6+ use std:: borrow:: Cow ;
67use std:: sync:: Arc ;
78
89/// A convenient new type data structure to store the options that belong to a rule
@@ -68,6 +69,9 @@ pub struct AnalyzerConfiguration {
6869 /// Allows choosing a different JSX quote when applying fixes inside the lint rules
6970 pub preferred_jsx_quote : PreferredQuote ,
7071
72+ /// Allows applying the right indentation in fix suggestions.
73+ preferred_indentation : PreferredIndentation ,
74+
7175 /// Indicates the type of runtime or transformation used for interpreting JSX.
7276 jsx_runtime : Option < JsxRuntime > ,
7377
@@ -101,6 +105,14 @@ impl AnalyzerConfiguration {
101105 self
102106 }
103107
108+ pub fn with_preferred_indentation (
109+ mut self ,
110+ preferred_indentation : PreferredIndentation ,
111+ ) -> Self {
112+ self . preferred_indentation = preferred_indentation;
113+ self
114+ }
115+
104116 pub fn with_css_modules ( mut self , css_modules : bool ) -> Self {
105117 self . css_modules = css_modules;
106118 self
@@ -171,20 +183,45 @@ impl AnalyzerOptions {
171183 . get_rule_fix_kind ( & RuleKey :: rule :: < R > ( ) )
172184 }
173185
174- pub fn preferred_quote ( & self ) -> & PreferredQuote {
175- & self . configuration . preferred_quote
186+ pub fn preferred_quote ( & self ) -> PreferredQuote {
187+ self . configuration . preferred_quote
176188 }
177189
178- pub fn preferred_jsx_quote ( & self ) -> & PreferredQuote {
179- & self . configuration . preferred_jsx_quote
190+ pub fn preferred_jsx_quote ( & self ) -> PreferredQuote {
191+ self . configuration . preferred_jsx_quote
192+ }
193+
194+ pub fn preferred_indentation ( & self ) -> PreferredIndentation {
195+ self . configuration . preferred_indentation
180196 }
181197
182198 pub fn css_modules ( & self ) -> bool {
183199 self . configuration . css_modules
184200 }
185201}
186202
187- #[ derive( Debug , Default ) ]
203+ #[ derive( Clone , Copy , Debug , Default ) ]
204+ pub enum PreferredIndentation {
205+ /// Use tabs for indentation.
206+ #[ default]
207+ Tab ,
208+ /// Use the given amount of spaces for indentation.
209+ Spaces ( u8 ) ,
210+ }
211+
212+ impl PreferredIndentation {
213+ /// Returns the indentation in its string form.
214+ pub fn to_string ( self ) -> Cow < ' static , str > {
215+ match self {
216+ Self :: Tab => Cow :: Borrowed ( "\t " ) ,
217+ Self :: Spaces ( tab_width) => {
218+ Cow :: Owned ( std:: iter:: repeat_n ( ' ' , tab_width as usize ) . collect ( ) )
219+ }
220+ }
221+ }
222+ }
223+
224+ #[ derive( Clone , Copy , Debug , Default ) ]
188225pub enum PreferredQuote {
189226 /// Double quotes
190227 #[ default]
0 commit comments