@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.
@@ -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.