Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
docs(noExplicitAny): add a diagnostic note and info in docs (#4089)
Browse files Browse the repository at this point in the history
  • Loading branch information
Conaclos authored Dec 22, 2022
1 parent f2c8f71 commit c20d6cf
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 8 deletions.
14 changes: 12 additions & 2 deletions crates/rome_js_analyze/src/analyzers/suspicious/no_explicit_any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ use rome_js_syntax::TsAnyType;
use rome_rowan::AstNode;

declare_rule! {
/// Disallow the `any` type usage
/// Disallow the `any` type usage.
///
/// The `any` type in TypeScript is a dangerous "escape hatch" from the type system.
/// Using `any` disables many type checking rules and is generally best used only as a last resort or when prototyping code.
///
/// TypeScript's `--noImplicitAny` compiler option prevents an implied `any`,
/// but doesn't prevent `any` from being explicitly used the way this rule does.
///
/// Source: https://typescript-eslint.io/rules/no-explicit-any
///
/// ## Examples
///
Expand Down Expand Up @@ -66,7 +74,9 @@ impl Rule for NoExplicitAny {
ctx.query().range(),
markup! {"Unexpected "<Emphasis>"any"</Emphasis>". Specify a different type."}
.to_owned(),
);
).note(markup! {
<Emphasis>"any"</Emphasis>" disables many type checking rules. Its use should be avoided."
});

Some(diagnostic)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: crates/rome_js_analyze/tests/spec_tests.rs
assertion_line: 92
expression: invalidClass.ts
---
# Input
Expand Down Expand Up @@ -52,6 +53,8 @@ invalidClass.ts:2:27 lint/suspicious/noExplicitAny ━━━━━━━━━
3 │ }
4 │
i any disables many type checking rules. Its use should be avoided.
```

Expand All @@ -66,6 +69,8 @@ invalidClass.ts:6:11 lint/suspicious/noExplicitAny ━━━━━━━━━
7 │ }
8 │
i any disables many type checking rules. Its use should be avoided.
```

Expand All @@ -80,6 +85,8 @@ invalidClass.ts:10:17 lint/suspicious/noExplicitAny ━━━━━━━━━
11 │ }
12 │
i any disables many type checking rules. Its use should be avoided.
```

Expand All @@ -94,6 +101,8 @@ invalidClass.ts:14:11 lint/suspicious/noExplicitAny ━━━━━━━━━
15 │ }
16 │
i any disables many type checking rules. Its use should be avoided.
```

Expand All @@ -108,6 +117,8 @@ invalidClass.ts:18:23 lint/suspicious/noExplicitAny ━━━━━━━━━
19 │ }
20 │
i any disables many type checking rules. Its use should be avoided.
```

Expand All @@ -122,6 +133,8 @@ invalidClass.ts:22:17 lint/suspicious/noExplicitAny ━━━━━━━━━
23 │ }
24 │
i any disables many type checking rules. Its use should be avoided.
```

Expand All @@ -137,6 +150,8 @@ invalidClass.ts:25:15 lint/suspicious/noExplicitAny ━━━━━━━━━
26 │
27 │ abstract class Foo<t = any> extends Bar<any> {}
i any disables many type checking rules. Its use should be avoided.
```

Expand All @@ -152,6 +167,8 @@ invalidClass.ts:25:32 lint/suspicious/noExplicitAny ━━━━━━━━━
26 │
27 │ abstract class Foo<t = any> extends Bar<any> {}
i any disables many type checking rules. Its use should be avoided.
```

Expand All @@ -167,6 +184,8 @@ invalidClass.ts:27:24 lint/suspicious/noExplicitAny ━━━━━━━━━
28 │
29 │ abstract class Foo<t = any> implements Bar<any>, Baz<any> {}
i any disables many type checking rules. Its use should be avoided.
```

Expand All @@ -182,6 +201,8 @@ invalidClass.ts:27:41 lint/suspicious/noExplicitAny ━━━━━━━━━
28 │
29 │ abstract class Foo<t = any> implements Bar<any>, Baz<any> {}
i any disables many type checking rules. Its use should be avoided.
```

Expand All @@ -197,6 +218,8 @@ invalidClass.ts:29:24 lint/suspicious/noExplicitAny ━━━━━━━━━
30 │
31 │ new Foo<any>()
i any disables many type checking rules. Its use should be avoided.
```

Expand All @@ -212,6 +235,8 @@ invalidClass.ts:29:44 lint/suspicious/noExplicitAny ━━━━━━━━━
30 │
31 │ new Foo<any>()
i any disables many type checking rules. Its use should be avoided.
```

Expand All @@ -227,6 +252,8 @@ invalidClass.ts:29:54 lint/suspicious/noExplicitAny ━━━━━━━━━
30 │
31 │ new Foo<any>()
i any disables many type checking rules. Its use should be avoided.
```

Expand All @@ -242,6 +269,8 @@ invalidClass.ts:31:9 lint/suspicious/noExplicitAny ━━━━━━━━━
32 │
33 │ Foo<any>()
i any disables many type checking rules. Its use should be avoided.
```

Expand All @@ -256,6 +285,8 @@ invalidClass.ts:33:5 lint/suspicious/noExplicitAny ━━━━━━━━━
│ ^^^
34 │
i any disables many type checking rules. Its use should be avoided.
```

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: crates/rome_js_analyze/tests/spec_tests.rs
assertion_line: 92
expression: invalidFunction.ts
---
# Input
Expand Down Expand Up @@ -47,6 +48,8 @@ invalidFunction.ts:1:21 lint/suspicious/noExplicitAny ━━━━━━━━
2
3function generic2(): Array<any> {}

i any disables many type checking rules. Its use should be avoided.


```

Expand All @@ -62,6 +65,8 @@ invalidFunction.ts:3:28 lint/suspicious/noExplicitAny ━━━━━━━━
4 │
5 │ function generic3(): any[] {}
i any disables many type checking rules. Its use should be avoided.
```

Expand All @@ -77,6 +82,8 @@ invalidFunction.ts:5:22 lint/suspicious/noExplicitAny ━━━━━━━━
6 │
7 │ function generic4(param: Array<any>): number {}
i any disables many type checking rules. Its use should be avoided.
```

Expand All @@ -92,6 +99,8 @@ invalidFunction.ts:7:32 lint/suspicious/noExplicitAny ━━━━━━━━
8 │
9 │ function generic5(param: any[]): number {}
i any disables many type checking rules. Its use should be avoided.
```

Expand All @@ -107,6 +116,8 @@ invalidFunction.ts:9:26 lint/suspicious/noExplicitAny ━━━━━━━━
10 │
11 │ function generic6(param: Array<any>): Array<any> {}
i any disables many type checking rules. Its use should be avoided.
```

Expand All @@ -122,6 +133,8 @@ invalidFunction.ts:11:32 lint/suspicious/noExplicitAny ━━━━━━━━
12 │
13 │ function generic7(): Array<Array<any>> {}
i any disables many type checking rules. Its use should be avoided.
```

Expand All @@ -137,6 +150,8 @@ invalidFunction.ts:11:45 lint/suspicious/noExplicitAny ━━━━━━━━
12 │
13 │ function generic7(): Array<Array<any>> {}
i any disables many type checking rules. Its use should be avoided.
```

Expand All @@ -152,6 +167,8 @@ invalidFunction.ts:13:34 lint/suspicious/noExplicitAny ━━━━━━━━
14 │
15 │ function generic8(): Array<any[]> {}
i any disables many type checking rules. Its use should be avoided.
```

Expand All @@ -167,6 +184,8 @@ invalidFunction.ts:15:28 lint/suspicious/noExplicitAny ━━━━━━━━
16 │
17 │ function test<T extends Partial<any>>() {}
i any disables many type checking rules. Its use should be avoided.
```

Expand All @@ -182,6 +201,8 @@ invalidFunction.ts:17:33 lint/suspicious/noExplicitAny ━━━━━━━━
18 │
19 │ function foo(a: number, ...rest: any[]): void {
i any disables many type checking rules. Its use should be avoided.
```

Expand All @@ -197,6 +218,8 @@ invalidFunction.ts:19:34 lint/suspicious/noExplicitAny ━━━━━━━━
20 │ return;
21 │ }
i any disables many type checking rules. Its use should be avoided.
```

Expand All @@ -212,6 +235,8 @@ invalidFunction.ts:23:24 lint/suspicious/noExplicitAny ━━━━━━━━
24 │
25 │ function quux5(fn: (...args: any) => void): void {}
i any disables many type checking rules. Its use should be avoided.
```

Expand All @@ -227,6 +252,8 @@ invalidFunction.ts:25:30 lint/suspicious/noExplicitAny ━━━━━━━━
26 │
27 │ function quuz5(): ((...args: any) => void) {}
i any disables many type checking rules. Its use should be avoided.
```

Expand All @@ -242,6 +269,8 @@ invalidFunction.ts:27:30 lint/suspicious/noExplicitAny ━━━━━━━━
28 │
29 │ declare function waldo5(...args: any): void;
i any disables many type checking rules. Its use should be avoided.
```

Expand All @@ -256,6 +285,8 @@ invalidFunction.ts:29:34 lint/suspicious/noExplicitAny ━━━━━━━━
│ ^^^
30 │
i any disables many type checking rules. Its use should be avoided.
```

Expand Down
Loading

0 comments on commit c20d6cf

Please sign in to comment.