@@ -132,55 +132,47 @@ impl Rule for FilenameCase {
132
132
fn from_configuration ( value : serde_json:: Value ) -> Self {
133
133
let mut config = FilenameCaseConfig :: default ( ) ;
134
134
135
- let Some ( case_type) = value. get ( 0 ) else {
136
- config. kebab_case = true ;
137
- return Self ( Box :: new ( config) ) ;
138
- } ;
139
-
140
- if let Some ( Value :: String ( pat) ) = case_type. get ( "ignore" ) {
141
- config. ignore = RegexBuilder :: new ( pat) . build ( ) . ok ( ) ;
142
- }
143
-
144
- if let Some ( Value :: String ( s) ) = case_type. get ( "case" ) {
145
- match s. as_str ( ) {
146
- "camelCase" => config. camel_case = true ,
147
- "snakeCase" => config. snake_case = true ,
148
- "pascalCase" => config. pascal_case = true ,
149
- _ => config. kebab_case = true ,
135
+ if let Some ( value) = value. get ( 0 ) {
136
+ if let Some ( Value :: String ( pat) ) = value. get ( "ignore" ) {
137
+ config. ignore = RegexBuilder :: new ( pat) . build ( ) . ok ( ) ;
150
138
}
151
139
152
- return Self ( Box :: new ( config) ) ;
153
- }
140
+ if let Some ( Value :: String ( s) ) = value. get ( "case" ) {
141
+ match s. as_str ( ) {
142
+ "camelCase" => config. camel_case = true ,
143
+ "snakeCase" => config. snake_case = true ,
144
+ "pascalCase" => config. pascal_case = true ,
145
+ _ => config. kebab_case = true ,
146
+ }
147
+ return Self ( Box :: new ( config) ) ;
148
+ }
154
149
155
- if let Some ( Value :: Object ( map) ) = case_type. get ( "cases" ) {
156
- for ( key, value) in map {
157
- match ( key. as_str ( ) , value) {
158
- ( "kebabCase" , Value :: Bool ( b) ) => config. kebab_case = * b,
159
- ( "camelCase" , Value :: Bool ( b) ) => config. camel_case = * b,
160
- ( "snakeCase" , Value :: Bool ( b) ) => config. snake_case = * b,
161
- ( "pascalCase" , Value :: Bool ( b) ) => config. pascal_case = * b,
162
- _ => ( ) ,
150
+ if let Some ( Value :: Object ( map) ) = value. get ( "cases" ) {
151
+ for ( key, value) in map {
152
+ match ( key. as_str ( ) , value) {
153
+ ( "kebabCase" , Value :: Bool ( b) ) => config. kebab_case = * b,
154
+ ( "camelCase" , Value :: Bool ( b) ) => config. camel_case = * b,
155
+ ( "snakeCase" , Value :: Bool ( b) ) => config. snake_case = * b,
156
+ ( "pascalCase" , Value :: Bool ( b) ) => config. pascal_case = * b,
157
+ _ => ( ) ,
158
+ }
163
159
}
160
+ return Self ( Box :: new ( config) ) ;
164
161
}
165
- return Self ( Box :: new ( config) ) ;
166
162
}
167
163
168
164
config. kebab_case = true ;
169
165
Self ( Box :: new ( config) )
170
166
}
171
167
172
168
fn run_once < ' a > ( & self , ctx : & LintContext < ' _ > ) {
173
- let file_path = ctx. file_path ( ) ;
174
- let Some ( raw_filename) = file_path. file_name ( ) . and_then ( |s| s. to_str ( ) ) else {
169
+ let Some ( raw_filename) = ctx. file_path ( ) . file_name ( ) . and_then ( |s| s. to_str ( ) ) else {
175
170
return ;
176
171
} ;
177
172
178
- if self . ignore . as_ref ( ) . is_some_and ( |regex| regex. is_match ( raw_filename) ) {
179
- return ;
180
- }
181
-
182
- // Get valid filename
183
- if raw_filename. as_bytes ( ) == b".." || raw_filename. starts_with ( '.' ) {
173
+ if raw_filename. starts_with ( '.' )
174
+ || self . ignore . as_ref ( ) . is_some_and ( |r| r. is_match ( raw_filename) )
175
+ {
184
176
return ;
185
177
}
186
178
0 commit comments