diff options
author | Aleksey Kladov <[email protected]> | 2021-06-13 19:33:54 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2021-06-13 19:33:54 +0100 |
commit | 3478897f86cc1b3e3f83e9d4e7cedff41721fb04 (patch) | |
tree | 9700c178acb48fcc029f4120169f00a94d7308f0 /crates/ide/src/diagnostics/incorrect_case.rs | |
parent | fc30c5ccbeba2a102922da497809dd3f812544c4 (diff) |
internal: remove DiagnosticWithFix infra
Diffstat (limited to 'crates/ide/src/diagnostics/incorrect_case.rs')
-rw-r--r-- | crates/ide/src/diagnostics/incorrect_case.rs | 322 |
1 files changed, 322 insertions, 0 deletions
diff --git a/crates/ide/src/diagnostics/incorrect_case.rs b/crates/ide/src/diagnostics/incorrect_case.rs index 56283b58b..832394400 100644 --- a/crates/ide/src/diagnostics/incorrect_case.rs +++ b/crates/ide/src/diagnostics/incorrect_case.rs | |||
@@ -163,4 +163,326 @@ impl TestStruct { | |||
163 | 163 | ||
164 | check_fix(input, expected); | 164 | check_fix(input, expected); |
165 | } | 165 | } |
166 | |||
167 | #[test] | ||
168 | fn incorrect_function_name() { | ||
169 | check_diagnostics( | ||
170 | r#" | ||
171 | fn NonSnakeCaseName() {} | ||
172 | // ^^^^^^^^^^^^^^^^ Function `NonSnakeCaseName` should have snake_case name, e.g. `non_snake_case_name` | ||
173 | "#, | ||
174 | ); | ||
175 | } | ||
176 | |||
177 | #[test] | ||
178 | fn incorrect_function_params() { | ||
179 | check_diagnostics( | ||
180 | r#" | ||
181 | fn foo(SomeParam: u8) {} | ||
182 | // ^^^^^^^^^ Parameter `SomeParam` should have snake_case name, e.g. `some_param` | ||
183 | |||
184 | fn foo2(ok_param: &str, CAPS_PARAM: u8) {} | ||
185 | // ^^^^^^^^^^ Parameter `CAPS_PARAM` should have snake_case name, e.g. `caps_param` | ||
186 | "#, | ||
187 | ); | ||
188 | } | ||
189 | |||
190 | #[test] | ||
191 | fn incorrect_variable_names() { | ||
192 | check_diagnostics( | ||
193 | r#" | ||
194 | fn foo() { | ||
195 | let SOME_VALUE = 10; | ||
196 | // ^^^^^^^^^^ Variable `SOME_VALUE` should have snake_case name, e.g. `some_value` | ||
197 | let AnotherValue = 20; | ||
198 | // ^^^^^^^^^^^^ Variable `AnotherValue` should have snake_case name, e.g. `another_value` | ||
199 | } | ||
200 | "#, | ||
201 | ); | ||
202 | } | ||
203 | |||
204 | #[test] | ||
205 | fn incorrect_struct_names() { | ||
206 | check_diagnostics( | ||
207 | r#" | ||
208 | struct non_camel_case_name {} | ||
209 | // ^^^^^^^^^^^^^^^^^^^ Structure `non_camel_case_name` should have CamelCase name, e.g. `NonCamelCaseName` | ||
210 | |||
211 | struct SCREAMING_CASE {} | ||
212 | // ^^^^^^^^^^^^^^ Structure `SCREAMING_CASE` should have CamelCase name, e.g. `ScreamingCase` | ||
213 | "#, | ||
214 | ); | ||
215 | } | ||
216 | |||
217 | #[test] | ||
218 | fn no_diagnostic_for_camel_cased_acronyms_in_struct_name() { | ||
219 | check_diagnostics( | ||
220 | r#" | ||
221 | struct AABB {} | ||
222 | "#, | ||
223 | ); | ||
224 | } | ||
225 | |||
226 | #[test] | ||
227 | fn incorrect_struct_field() { | ||
228 | check_diagnostics( | ||
229 | r#" | ||
230 | struct SomeStruct { SomeField: u8 } | ||
231 | // ^^^^^^^^^ Field `SomeField` should have snake_case name, e.g. `some_field` | ||
232 | "#, | ||
233 | ); | ||
234 | } | ||
235 | |||
236 | #[test] | ||
237 | fn incorrect_enum_names() { | ||
238 | check_diagnostics( | ||
239 | r#" | ||
240 | enum some_enum { Val(u8) } | ||
241 | // ^^^^^^^^^ Enum `some_enum` should have CamelCase name, e.g. `SomeEnum` | ||
242 | |||
243 | enum SOME_ENUM {} | ||
244 | // ^^^^^^^^^ Enum `SOME_ENUM` should have CamelCase name, e.g. `SomeEnum` | ||
245 | "#, | ||
246 | ); | ||
247 | } | ||
248 | |||
249 | #[test] | ||
250 | fn no_diagnostic_for_camel_cased_acronyms_in_enum_name() { | ||
251 | check_diagnostics( | ||
252 | r#" | ||
253 | enum AABB {} | ||
254 | "#, | ||
255 | ); | ||
256 | } | ||
257 | |||
258 | #[test] | ||
259 | fn incorrect_enum_variant_name() { | ||
260 | check_diagnostics( | ||
261 | r#" | ||
262 | enum SomeEnum { SOME_VARIANT(u8) } | ||
263 | // ^^^^^^^^^^^^ Variant `SOME_VARIANT` should have CamelCase name, e.g. `SomeVariant` | ||
264 | "#, | ||
265 | ); | ||
266 | } | ||
267 | |||
268 | #[test] | ||
269 | fn incorrect_const_name() { | ||
270 | check_diagnostics( | ||
271 | r#" | ||
272 | const some_weird_const: u8 = 10; | ||
273 | // ^^^^^^^^^^^^^^^^ Constant `some_weird_const` should have UPPER_SNAKE_CASE name, e.g. `SOME_WEIRD_CONST` | ||
274 | "#, | ||
275 | ); | ||
276 | } | ||
277 | |||
278 | #[test] | ||
279 | fn incorrect_static_name() { | ||
280 | check_diagnostics( | ||
281 | r#" | ||
282 | static some_weird_const: u8 = 10; | ||
283 | // ^^^^^^^^^^^^^^^^ Static variable `some_weird_const` should have UPPER_SNAKE_CASE name, e.g. `SOME_WEIRD_CONST` | ||
284 | "#, | ||
285 | ); | ||
286 | } | ||
287 | |||
288 | #[test] | ||
289 | fn fn_inside_impl_struct() { | ||
290 | check_diagnostics( | ||
291 | r#" | ||
292 | struct someStruct; | ||
293 | // ^^^^^^^^^^ Structure `someStruct` should have CamelCase name, e.g. `SomeStruct` | ||
294 | |||
295 | impl someStruct { | ||
296 | fn SomeFunc(&self) { | ||
297 | // ^^^^^^^^ Function `SomeFunc` should have snake_case name, e.g. `some_func` | ||
298 | let WHY_VAR_IS_CAPS = 10; | ||
299 | // ^^^^^^^^^^^^^^^ Variable `WHY_VAR_IS_CAPS` should have snake_case name, e.g. `why_var_is_caps` | ||
300 | } | ||
301 | } | ||
302 | "#, | ||
303 | ); | ||
304 | } | ||
305 | |||
306 | #[test] | ||
307 | fn no_diagnostic_for_enum_varinats() { | ||
308 | check_diagnostics( | ||
309 | r#" | ||
310 | enum Option { Some, None } | ||
311 | |||
312 | fn main() { | ||
313 | match Option::None { | ||
314 | None => (), | ||
315 | Some => (), | ||
316 | } | ||
317 | } | ||
318 | "#, | ||
319 | ); | ||
320 | } | ||
321 | |||
322 | #[test] | ||
323 | fn non_let_bind() { | ||
324 | check_diagnostics( | ||
325 | r#" | ||
326 | enum Option { Some, None } | ||
327 | |||
328 | fn main() { | ||
329 | match Option::None { | ||
330 | SOME_VAR @ None => (), | ||
331 | // ^^^^^^^^ Variable `SOME_VAR` should have snake_case name, e.g. `some_var` | ||
332 | Some => (), | ||
333 | } | ||
334 | } | ||
335 | "#, | ||
336 | ); | ||
337 | } | ||
338 | |||
339 | #[test] | ||
340 | fn allow_attributes_crate_attr() { | ||
341 | check_diagnostics( | ||
342 | r#" | ||
343 | #![allow(non_snake_case)] | ||
344 | |||
345 | mod F { | ||
346 | fn CheckItWorksWithCrateAttr(BAD_NAME_HI: u8) {} | ||
347 | } | ||
348 | "#, | ||
349 | ); | ||
350 | } | ||
351 | |||
352 | #[test] | ||
353 | #[ignore] | ||
354 | fn bug_trait_inside_fn() { | ||
355 | // FIXME: | ||
356 | // This is broken, and in fact, should not even be looked at by this | ||
357 | // lint in the first place. There's weird stuff going on in the | ||
358 | // collection phase. | ||
359 | // It's currently being brought in by: | ||
360 | // * validate_func on `a` recursing into modules | ||
361 | // * then it finds the trait and then the function while iterating | ||
362 | // through modules | ||
363 | // * then validate_func is called on Dirty | ||
364 | // * ... which then proceeds to look at some unknown module taking no | ||
365 | // attrs from either the impl or the fn a, and then finally to the root | ||
366 | // module | ||
367 | // | ||
368 | // It should find the attribute on the trait, but it *doesn't even see | ||
369 | // the trait* as far as I can tell. | ||
370 | |||
371 | check_diagnostics( | ||
372 | r#" | ||
373 | trait T { fn a(); } | ||
374 | struct U {} | ||
375 | impl T for U { | ||
376 | fn a() { | ||
377 | // this comes out of bitflags, mostly | ||
378 | #[allow(non_snake_case)] | ||
379 | trait __BitFlags { | ||
380 | const HiImAlsoBad: u8 = 2; | ||
381 | #[inline] | ||
382 | fn Dirty(&self) -> bool { | ||
383 | false | ||
384 | } | ||
385 | } | ||
386 | |||
387 | } | ||
388 | } | ||
389 | "#, | ||
390 | ); | ||
391 | } | ||
392 | |||
393 | #[test] | ||
394 | fn infinite_loop_inner_items() { | ||
395 | check_diagnostics( | ||
396 | r#" | ||
397 | fn qualify() { | ||
398 | mod foo { | ||
399 | use super::*; | ||
400 | } | ||
401 | } | ||
402 | "#, | ||
403 | ) | ||
404 | } | ||
405 | |||
406 | #[test] // Issue #8809. | ||
407 | fn parenthesized_parameter() { | ||
408 | check_diagnostics(r#"fn f((O): _) {}"#) | ||
409 | } | ||
410 | |||
411 | #[test] | ||
412 | fn ignores_extern_items() { | ||
413 | cov_mark::check!(extern_func_incorrect_case_ignored); | ||
414 | cov_mark::check!(extern_static_incorrect_case_ignored); | ||
415 | check_diagnostics( | ||
416 | r#" | ||
417 | extern { | ||
418 | fn NonSnakeCaseName(SOME_VAR: u8) -> u8; | ||
419 | pub static SomeStatic: u8 = 10; | ||
420 | } | ||
421 | "#, | ||
422 | ); | ||
423 | } | ||
424 | |||
425 | #[test] | ||
426 | #[ignore] | ||
427 | fn bug_traits_arent_checked() { | ||
428 | // FIXME: Traits and functions in traits aren't currently checked by | ||
429 | // r-a, even though rustc will complain about them. | ||
430 | check_diagnostics( | ||
431 | r#" | ||
432 | trait BAD_TRAIT { | ||
433 | // ^^^^^^^^^ Trait `BAD_TRAIT` should have CamelCase name, e.g. `BadTrait` | ||
434 | fn BAD_FUNCTION(); | ||
435 | // ^^^^^^^^^^^^ Function `BAD_FUNCTION` should have snake_case name, e.g. `bad_function` | ||
436 | fn BadFunction(); | ||
437 | // ^^^^^^^^^^^^ Function `BadFunction` should have snake_case name, e.g. `bad_function` | ||
438 | } | ||
439 | "#, | ||
440 | ); | ||
441 | } | ||
442 | |||
443 | #[test] | ||
444 | fn allow_attributes() { | ||
445 | check_diagnostics( | ||
446 | r#" | ||
447 | #[allow(non_snake_case)] | ||
448 | fn NonSnakeCaseName(SOME_VAR: u8) -> u8{ | ||
449 | // cov_flags generated output from elsewhere in this file | ||
450 | extern "C" { | ||
451 | #[no_mangle] | ||
452 | static lower_case: u8; | ||
453 | } | ||
454 | |||
455 | let OtherVar = SOME_VAR + 1; | ||
456 | OtherVar | ||
457 | } | ||
458 | |||
459 | #[allow(nonstandard_style)] | ||
460 | mod CheckNonstandardStyle { | ||
461 | fn HiImABadFnName() {} | ||
462 | } | ||
463 | |||
464 | #[allow(bad_style)] | ||
465 | mod CheckBadStyle { | ||
466 | fn HiImABadFnName() {} | ||
467 | } | ||
468 | |||
469 | mod F { | ||
470 | #![allow(non_snake_case)] | ||
471 | fn CheckItWorksWithModAttr(BAD_NAME_HI: u8) {} | ||
472 | } | ||
473 | |||
474 | #[allow(non_snake_case, non_camel_case_types)] | ||
475 | pub struct some_type { | ||
476 | SOME_FIELD: u8, | ||
477 | SomeField: u16, | ||
478 | } | ||
479 | |||
480 | #[allow(non_upper_case_globals)] | ||
481 | pub const some_const: u8 = 10; | ||
482 | |||
483 | #[allow(non_upper_case_globals)] | ||
484 | pub static SomeStatic: u8 = 10; | ||
485 | "#, | ||
486 | ); | ||
487 | } | ||
166 | } | 488 | } |