@codelaw/rules-ts 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +23 -0
- package/NOTICE +6 -0
- package/README.md +38 -2
- package/codelaw-pack.toml +6 -0
- package/corpus.toml +25 -0
- package/package.json +14 -4
- package/presets/ts/conventions.toml +4 -0
- package/presets/ts/recommended.toml +23 -0
- package/rules/ts/ban-ts-comment.md +64 -0
- package/rules/ts/no-array-constructor.md +58 -0
- package/rules/ts/no-duplicate-enum-values.md +65 -0
- package/rules/ts/no-empty-object-type.md +65 -0
- package/rules/ts/no-explicit-any.md +61 -0
- package/rules/ts/no-extra-non-null-assertion.md +50 -0
- package/rules/ts/no-misused-new.md +70 -0
- package/rules/ts/no-namespace.md +65 -0
- package/rules/ts/no-non-null-asserted-optional-chain.md +55 -0
- package/rules/ts/no-require-imports.md +54 -0
- package/rules/ts/no-this-alias.md +68 -0
- package/rules/ts/no-unnecessary-type-constraint.md +64 -0
- package/rules/ts/no-unsafe-declaration-merging.md +73 -0
- package/rules/ts/no-unsafe-function-type.md +57 -0
- package/rules/ts/no-unused-expressions.md +61 -0
- package/rules/ts/no-unused-vars.md +68 -0
- package/rules/ts/no-wrapper-object-types.md +49 -0
- package/rules/ts/prefer-as-const.md +47 -0
- package/rules/ts/prefer-namespace-keyword.md +63 -0
- package/rules/ts/triple-slash-reference.md +60 -0
- package/rules/ts/type-only-imports.md +57 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: ts/triple-slash-reference
|
|
3
|
+
title: "No /// <reference path> directives"
|
|
4
|
+
languages: [typescript, tsx]
|
|
5
|
+
fix: manual
|
|
6
|
+
fix_reason: "the matching import needs the module path and what it provides"
|
|
7
|
+
stability: preview
|
|
8
|
+
ported_from: [typescript-eslint/triple-slash-reference]
|
|
9
|
+
since: 0.1.0
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
Files are connected with `import`, not `/// <reference path="…" />`.
|
|
13
|
+
|
|
14
|
+
**Why:** Reference directives predate ES modules and hide dependencies from bundlers and other
|
|
15
|
+
tools.
|
|
16
|
+
|
|
17
|
+
```codelaw
|
|
18
|
+
match:
|
|
19
|
+
kind: comment
|
|
20
|
+
regex: ^///\s*<reference\s+path=
|
|
21
|
+
message: "Use an `import` instead of a `/// <reference path>` directive"
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## How to fix
|
|
25
|
+
|
|
26
|
+
1. Replace the directive with an `import` of the module it pointed to.
|
|
27
|
+
|
|
28
|
+
## Examples
|
|
29
|
+
|
|
30
|
+
### TypeScript
|
|
31
|
+
|
|
32
|
+
#### Don't
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
/// <reference path="./globals.d.ts" />
|
|
36
|
+
export const x = 1;
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
#### Do
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import "./globals";
|
|
43
|
+
export const x = 1;
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### TSX
|
|
47
|
+
|
|
48
|
+
#### Don't
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
/// <reference path="./globals.d.ts" />
|
|
52
|
+
export const x = 1;
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
#### Do
|
|
56
|
+
|
|
57
|
+
```tsx
|
|
58
|
+
import "./globals";
|
|
59
|
+
export const x = 1;
|
|
60
|
+
```
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: ts/type-only-imports
|
|
3
|
+
title: "Names used only as types are imported with type"
|
|
4
|
+
languages: [typescript, tsx]
|
|
5
|
+
fix: suggest
|
|
6
|
+
fix_reason: "a type-only import is erased, so code that relied on the module's side effects changes"
|
|
7
|
+
stability: preview
|
|
8
|
+
since: 0.1.0
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
An imported name that the file uses only in type positions is marked `type`.
|
|
12
|
+
|
|
13
|
+
**Why:** Type-only imports are erased at compile time, which keeps runtime imports honest and helps
|
|
14
|
+
bundlers drop unused modules.
|
|
15
|
+
|
|
16
|
+
```codelaw
|
|
17
|
+
native: ts/type-only-imports
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Examples
|
|
21
|
+
|
|
22
|
+
### TypeScript
|
|
23
|
+
|
|
24
|
+
#### Don't
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { Config, load } from "./config";
|
|
28
|
+
export const c: Config = load();
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
#### Do
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { type Config, load } from "./config";
|
|
35
|
+
export const c: Config = load();
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### TSX
|
|
39
|
+
|
|
40
|
+
#### Don't
|
|
41
|
+
|
|
42
|
+
```tsx
|
|
43
|
+
import { Config, load } from "./config";
|
|
44
|
+
export const c: Config = load();
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
#### Do
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
import { type Config, load } from "./config";
|
|
51
|
+
export const c: Config = load();
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Differences from the source
|
|
55
|
+
|
|
56
|
+
Only within the file, without type information: a name used as a value anywhere is left alone.
|
|
57
|
+
Default and namespace imports are reported without a fix.
|