@ttsc/lint 0.10.2 → 0.11.0-dev.20260518

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.
Files changed (113) hide show
  1. package/README.md +172 -33
  2. package/lib/defineConfig.d.ts +55 -0
  3. package/lib/defineConfig.js +39 -0
  4. package/lib/defineConfig.js.map +1 -0
  5. package/lib/index.d.ts +25 -1
  6. package/lib/index.js +622 -2
  7. package/lib/index.js.map +1 -1
  8. package/lib/structures/ITtscLintPlugin.d.ts +53 -0
  9. package/lib/structures/ITtscLintPlugin.js +3 -0
  10. package/lib/structures/ITtscLintPlugin.js.map +1 -0
  11. package/lib/structures/ITtscLintPluginConfig.d.ts +82 -5
  12. package/lib/structures/ITtscLintPluginMeta.d.ts +12 -0
  13. package/lib/structures/ITtscLintPluginMeta.js +3 -0
  14. package/lib/structures/ITtscLintPluginMeta.js.map +1 -0
  15. package/lib/structures/PluginRuleNames.d.ts +14 -0
  16. package/lib/structures/PluginRuleNames.js +3 -0
  17. package/lib/structures/PluginRuleNames.js.map +1 -0
  18. package/lib/structures/TtscLintConfig.d.ts +24 -8
  19. package/lib/structures/TtscLintConfigEntry.d.ts +39 -0
  20. package/lib/structures/TtscLintConfigEntry.js +3 -0
  21. package/lib/structures/TtscLintConfigEntry.js.map +1 -0
  22. package/lib/structures/TtscLintFormatConfig.d.ts +154 -0
  23. package/lib/structures/TtscLintFormatConfig.js +3 -0
  24. package/lib/structures/TtscLintFormatConfig.js.map +1 -0
  25. package/lib/structures/TtscLintPlugins.d.ts +9 -0
  26. package/lib/structures/TtscLintPlugins.js +3 -0
  27. package/lib/structures/TtscLintPlugins.js.map +1 -0
  28. package/lib/structures/TtscLintRule.d.ts +1 -1
  29. package/lib/structures/TtscLintRuleEntry.d.ts +22 -0
  30. package/lib/structures/TtscLintRuleEntry.js +3 -0
  31. package/lib/structures/TtscLintRuleEntry.js.map +1 -0
  32. package/lib/structures/TtscLintRuleMap.d.ts +44 -0
  33. package/lib/structures/TtscLintRuleMap.js +3 -0
  34. package/lib/structures/TtscLintRuleMap.js.map +1 -0
  35. package/lib/structures/TtscLintRuleOptions.d.ts +149 -0
  36. package/lib/structures/TtscLintRuleOptions.js +3 -0
  37. package/lib/structures/TtscLintRuleOptions.js.map +1 -0
  38. package/lib/structures/defaultFormat.d.ts +31 -0
  39. package/lib/structures/defaultFormat.js +35 -0
  40. package/lib/structures/defaultFormat.js.map +1 -0
  41. package/lib/structures/index.d.ts +10 -0
  42. package/lib/structures/index.js +10 -0
  43. package/lib/structures/index.js.map +1 -1
  44. package/{plugin → linthost}/ast_helpers.go +92 -1
  45. package/{plugin → linthost}/compile.go +1 -1
  46. package/{plugin → linthost}/config.go +583 -66
  47. package/linthost/config_format.go +360 -0
  48. package/linthost/contrib_adapter.go +134 -0
  49. package/{plugin → linthost}/directives.go +1 -1
  50. package/linthost/dispatch.go +65 -0
  51. package/{plugin → linthost}/engine.go +156 -11
  52. package/{plugin → linthost}/eslint_runtime.go +76 -2
  53. package/linthost/fix.go +249 -0
  54. package/linthost/format.go +107 -0
  55. package/{plugin → linthost}/host.go +1 -1
  56. package/linthost/print_dispatch.go +118 -0
  57. package/linthost/print_doc.go +168 -0
  58. package/linthost/print_engine.go +343 -0
  59. package/linthost/print_nodes_array.go +46 -0
  60. package/linthost/print_nodes_call.go +180 -0
  61. package/linthost/print_nodes_imports.go +171 -0
  62. package/linthost/print_nodes_list.go +64 -0
  63. package/linthost/print_nodes_object.go +51 -0
  64. package/{plugin → linthost}/rules_arrays.go +1 -1
  65. package/{plugin → linthost}/rules_console.go +1 -1
  66. package/{plugin → linthost}/rules_debugger.go +1 -1
  67. package/{plugin → linthost}/rules_dupes.go +1 -1
  68. package/{plugin → linthost}/rules_empty.go +1 -1
  69. package/linthost/rules_escape.go +238 -0
  70. package/{plugin → linthost}/rules_eval.go +1 -1
  71. package/{plugin → linthost}/rules_finally.go +1 -1
  72. package/linthost/rules_format_jsdoc.go +230 -0
  73. package/linthost/rules_format_print_width.go +332 -0
  74. package/linthost/rules_format_quotes.go +219 -0
  75. package/linthost/rules_format_semi.go +190 -0
  76. package/linthost/rules_format_sort_imports.go +462 -0
  77. package/linthost/rules_format_trailing_comma.go +460 -0
  78. package/{plugin → linthost}/rules_gap.go +101 -6
  79. package/linthost/rules_imports.go +101 -0
  80. package/{plugin → linthost}/rules_logic.go +55 -3
  81. package/{plugin → linthost}/rules_loops.go +1 -1
  82. package/{plugin → linthost}/rules_misc.go +1 -1
  83. package/linthost/rules_params.go +64 -0
  84. package/{plugin → linthost}/rules_problems.go +10 -2
  85. package/linthost/rules_promise.go +111 -0
  86. package/{plugin → linthost}/rules_protos.go +1 -1
  87. package/{plugin → linthost}/rules_self.go +1 -1
  88. package/{plugin → linthost}/rules_strings.go +1 -1
  89. package/{plugin → linthost}/rules_suggestions.go +51 -9
  90. package/{plugin → linthost}/rules_throw.go +1 -1
  91. package/{plugin → linthost}/rules_ts.go +12 -2
  92. package/{plugin → linthost}/rules_ts_extra.go +90 -4
  93. package/{plugin → linthost}/rules_var.go +36 -5
  94. package/package.json +8 -6
  95. package/plugin/main.go +14 -27
  96. package/rule/astutil/astutil.go +148 -0
  97. package/rule/rule.go +291 -0
  98. package/src/defineConfig.ts +69 -0
  99. package/src/index.ts +807 -3
  100. package/src/structures/ITtscLintPlugin.ts +56 -0
  101. package/src/structures/ITtscLintPluginConfig.ts +86 -5
  102. package/src/structures/ITtscLintPluginMeta.ts +14 -0
  103. package/src/structures/PluginRuleNames.ts +19 -0
  104. package/src/structures/TtscLintConfig.ts +27 -8
  105. package/src/structures/TtscLintConfigEntry.ts +50 -0
  106. package/src/structures/TtscLintFormatConfig.ts +169 -0
  107. package/src/structures/TtscLintPlugins.ts +10 -0
  108. package/src/structures/TtscLintRule.ts +14 -1
  109. package/src/structures/TtscLintRuleEntry.ts +28 -0
  110. package/src/structures/TtscLintRuleMap.ts +52 -0
  111. package/src/structures/TtscLintRuleOptions.ts +162 -0
  112. package/src/structures/defaultFormat.ts +33 -0
  113. package/src/structures/index.ts +10 -0
@@ -0,0 +1,56 @@
1
+ import type { ITtscLintPluginMeta } from "./ITtscLintPluginMeta";
2
+
3
+ /**
4
+ * Plugin descriptor exported by a `@ttsc/lint` contributor package.
5
+ *
6
+ * The shape intentionally mirrors ESLint's flat-config plugin object so a
7
+ * contributor can read like an ESLint plugin at a glance:
8
+ *
9
+ * ```ts
10
+ * // ttsc-lint-plugin-demo/src/index.ts
11
+ * import type { ITtscLintPlugin } from "@ttsc/lint";
12
+ * import path from "node:path";
13
+ *
14
+ * const plugin: ITtscLintPlugin = {
15
+ * meta: {
16
+ * name: "ttsc-lint-plugin-demo",
17
+ * version: "0.1.0",
18
+ * namespace: "demo",
19
+ * },
20
+ * rules: ["no-todo-comment"],
21
+ * source: path.resolve(__dirname, "..", "rules"),
22
+ * };
23
+ *
24
+ * export default plugin;
25
+ * ```
26
+ *
27
+ * The only field with runtime semantics is `source`: it points at the
28
+ * contributor's Go source directory. `@ttsc/lint`'s factory passes that path to
29
+ * ttsc's plugin builder, which links the contributor into the host binary at
30
+ * build time. `meta.namespace` and `rules` are advisory (used for type
31
+ * inference and diagnostic messages); the authoritative rule registration
32
+ * happens in the Go `init()` of the contributor module.
33
+ */
34
+ export interface ITtscLintPlugin {
35
+ /**
36
+ * Plugin metadata. Optional, but `meta.namespace` is the conventional source
37
+ * for the rule-name prefix; when absent, the tsconfig `plugins` map key fills
38
+ * that role.
39
+ */
40
+ meta?: ITtscLintPluginMeta;
41
+
42
+ /**
43
+ * Rule names exported by the Go side, used for TypeScript autocomplete in
44
+ * user configs. Purely advisory — the Go `init()` is the registration
45
+ * authority. Missing entries will not be flagged at runtime.
46
+ */
47
+ rules?: readonly string[];
48
+
49
+ /**
50
+ * Absolute path to the contributor's Go source directory.
51
+ *
52
+ * Resolve with `path.resolve(__dirname, ...)` so the path stays valid
53
+ * regardless of where the consumer's `node_modules` lives.
54
+ */
55
+ source: string;
56
+ }
@@ -1,4 +1,5 @@
1
- import type { TtscLintConfig } from "./TtscLintConfig";
1
+ import type { TtscLintFormatConfig } from "./TtscLintFormatConfig";
2
+ import type { TtscLintRuleMap } from "./TtscLintRuleMap";
2
3
 
3
4
  /** `compilerOptions.plugins[]` entry shape consumed by `@ttsc/lint`. */
4
5
  export interface ITtscLintPluginConfig {
@@ -8,14 +9,94 @@ export interface ITtscLintPluginConfig {
8
9
  /** Plugin module specifier. */
9
10
  transform?: string;
10
11
 
12
+ /**
13
+ * Inline rule severity map applied to the project.
14
+ *
15
+ * Mirrors the `rules` field of an ESLint flat-config entry. When set, the
16
+ * sidecar uses this map directly and does NOT consult any `lint.config.*`
17
+ * file (use `extends` for that). Combine with `plugins` to register
18
+ * contributor rule namespaces in the same entry.
19
+ *
20
+ * ```jsonc
21
+ * {
22
+ * "transform": "@ttsc/lint",
23
+ * "rules": { "no-var": "error", "prefer-const": "warning" }
24
+ * }
25
+ * ```
26
+ */
27
+ rules?: TtscLintRuleMap;
28
+
29
+ /**
30
+ * Path to a standalone lint config file whose rules should be applied to this
31
+ * project. Relative paths are resolved from the tsconfig directory. Accepts
32
+ * the usual `lint.config.*` / `ttsc-lint.config.*` / `eslint.config.*`
33
+ * extensions.
34
+ *
35
+ * Mirrors the `extends` field of an ESLint flat-config entry — "inherit this
36
+ * file's configuration".
37
+ *
38
+ * ```jsonc
39
+ * {
40
+ * "transform": "@ttsc/lint",
41
+ * "extends": "./lint.config.ts"
42
+ * }
43
+ * ```
44
+ *
45
+ * `rules` and `extends` are mutually exclusive on a single plugin entry; the
46
+ * sidecar surfaces a loud error when both are set.
47
+ */
48
+ extends?: string;
49
+
50
+ /**
51
+ * Contributor lint plugins to compile into the `@ttsc/lint` binary.
52
+ *
53
+ * Each entry maps a namespace (rule-name prefix) to an npm specifier or
54
+ * relative path. The factory resolves the package, reads its exported
55
+ * `ITtscLintPlugin` descriptor, and forwards the Go source directory to
56
+ * ttsc's plugin builder via the `contributors` field.
57
+ *
58
+ * ```jsonc
59
+ * {
60
+ * "transform": "@ttsc/lint",
61
+ * "plugins": { "demo": "ttsc-lint-plugin-demo" },
62
+ * "rules": { "demo/no-todo-comment": "error" }
63
+ * }
64
+ * ```
65
+ */
66
+ plugins?: Record<string, string>;
67
+
68
+ /**
69
+ * Prettier-style flat configuration for the `format/*` rules. Sibling of
70
+ * `rules`. See {@link TtscLintFormatConfig} for the full surface.
71
+ *
72
+ * ```jsonc
73
+ * {
74
+ * "transform": "@ttsc/lint",
75
+ * "format": { "printWidth": 100, "singleQuote": true }
76
+ * }
77
+ * ```
78
+ *
79
+ * Combines with `rules` (per-rule overrides win on collision). Cannot be
80
+ * combined with `extends` on the same plugin entry — put format options
81
+ * inside the extends-target lint.config.ts instead.
82
+ */
83
+ format?: TtscLintFormatConfig;
84
+
11
85
  /**
12
86
  * Inline rule map or path to a standalone lint config file.
13
87
  *
14
- * Inline maps are passed to the native sidecar through `--plugins-json`.
15
- * String values are resolved by the sidecar from the owning tsconfig
16
- * directory and may point at JSON, JavaScript, or TypeScript config files.
88
+ * @deprecated Use `rules` for inline severity maps or `extends` for a config
89
+ * file path. The sidecar maps a legacy `config` entry onto the appropriate
90
+ * new field and emits a one-time stderr deprecation notice. Removed in a
91
+ * future minor.
92
+ *
93
+ * The legacy shape is intentionally narrower than `rules`/`extends`: a string
94
+ * (file path) or a flat rule-name → severity map. The Go-side parser only
95
+ * accepts those two shapes; widening the TS type to the new
96
+ * `TtscLintConfig` union would silently let `config: [{ rules: {...} }]`
97
+ * pass type-checking and fail at runtime.
17
98
  */
18
- config?: string | TtscLintConfig;
99
+ config?: string | TtscLintRuleMap;
19
100
 
20
101
  /** Extra plugin-owned fields are passed through unchanged. */
21
102
  [key: string]: unknown;
@@ -0,0 +1,14 @@
1
+ /** Plugin-level metadata shared with the diagnostic surface. */
2
+ export interface ITtscLintPluginMeta {
3
+ /** Plugin package name as published on npm. */
4
+ name?: string;
5
+
6
+ /** Plugin package version. */
7
+ version?: string;
8
+
9
+ /**
10
+ * Rule namespace prefix (e.g. "import" → "import/no-cycle"). When omitted,
11
+ * `@ttsc/lint` uses the key from the tsconfig `plugins` map.
12
+ */
13
+ namespace?: string;
14
+ }
@@ -0,0 +1,19 @@
1
+ import type { TtscLintPlugins } from "./TtscLintPlugins";
2
+
3
+ /**
4
+ * Builds the union of `${namespace}/${rule}` strings from a plugins map.
5
+ *
6
+ * Each plugin's `rules` tuple is read literally: an `as const` tuple
7
+ * (`["no-cycle", "order"] as const`) provides exact autocomplete, while a plain
8
+ * `string[]` collapses to `${namespace}/${string}` and disables rule-level typo
9
+ * detection for that namespace.
10
+ */
11
+ export type PluginRuleNames<P extends TtscLintPlugins> = {
12
+ [Ns in keyof P]: P[Ns] extends { rules?: infer R }
13
+ ? R extends readonly (infer N)[]
14
+ ? N extends string
15
+ ? `${Ns & string}/${N}`
16
+ : never
17
+ : never
18
+ : never;
19
+ }[keyof P];
@@ -1,12 +1,31 @@
1
- import type { TtscLintRule } from "./TtscLintRule";
2
- import type { TtscLintSeverity } from "./TtscLintSeverity";
1
+ import type { TtscLintConfigEntry } from "./TtscLintConfigEntry";
2
+ import type { TtscLintPlugins } from "./TtscLintPlugins";
3
+ import type { TtscLintRuleMap } from "./TtscLintRuleMap";
3
4
 
4
5
  /**
5
- * Inline rule map accepted by the `@ttsc/lint` tsconfig plugin entry.
6
+ * Top-level config accepted by `@ttsc/lint`.
6
7
  *
7
- * Each property key is a native lint rule name. Omitted rules are disabled,
8
- * while present rules enable or disable that rule for the current project.
8
+ * Three accepted forms, listed in expected order of preference:
9
+ *
10
+ * 1. **Flat-config array** — mirrors ESLint flat config exactly. Each entry can
11
+ * scope by `files` / `ignores`, declare a `plugins` map of contributors,
12
+ * configure `rules`, and configure formatting through the Prettier-style
13
+ * {@link TtscLintFormatConfig | `format`} block. Multiple entries layer in
14
+ * order.
15
+ * 2. **Single config object** — same shape as one flat-config entry. Useful when
16
+ * the project has no per-file scoping. Pass `format: { … }` here for the
17
+ * smallest "describe my style" config.
18
+ * 3. **Rules-only map** — historical shape kept for backward compat with
19
+ * single-file projects. `{"no-var":"error"}` is interpreted as `[{rules:
20
+ * {"no-var":"error"}}]`. The shorthand intentionally has no slot for the
21
+ * `format` block — use form (1) or (2) to enable formatting.
22
+ *
23
+ * The generic parameter `P` lets `defineConfig` capture the literal plugin
24
+ * object types declared in `plugins`. When non-empty, rule-name keys
25
+ * autocomplete as `BuiltInRule | "<ns>/<rule>"` where the namespace-rule
26
+ * combinations come from each plugin's `rules` tuple.
9
27
  */
10
- export type TtscLintConfig = {
11
- [P in TtscLintRule]?: TtscLintSeverity;
12
- };
28
+ export type TtscLintConfig<P extends TtscLintPlugins = Record<string, never>> =
29
+ | TtscLintRuleMap<P>
30
+ | TtscLintConfigEntry<P>
31
+ | readonly TtscLintConfigEntry<P>[];
@@ -0,0 +1,50 @@
1
+ import type { TtscLintFormatConfig } from "./TtscLintFormatConfig";
2
+ import type { TtscLintPlugins } from "./TtscLintPlugins";
3
+ import type { TtscLintRuleMap } from "./TtscLintRuleMap";
4
+
5
+ /**
6
+ * One flat-config entry. ESLint-style `files` / `ignores` glob scoping, a
7
+ * `plugins` namespace map of contributor plugin objects, an `extends` list of
8
+ * child entries to fold in first, and a severity-keyed `rules` map applied
9
+ * after the extends chain.
10
+ *
11
+ * Prettier-style formatting opts in through a sibling `format` block — see
12
+ * `TtscLintFormatConfig`. The block can scope per-entry (e.g. wider
13
+ * `printWidth` for `legacy/**`) just like `rules` does.
14
+ */
15
+ export interface TtscLintConfigEntry<
16
+ P extends TtscLintPlugins = Record<string, never>,
17
+ > {
18
+ /** Globs that select the files this entry applies to. */
19
+ files?: string | readonly string[];
20
+
21
+ /** Globs that exclude files this entry would otherwise match. */
22
+ ignores?: string | readonly string[];
23
+
24
+ /**
25
+ * Nested entries (or arrays of entries) folded in before this entry's own
26
+ * rules apply. Mirrors ESLint flat config's `extends`: each child's rules
27
+ * layer first, with `this.rules` taking precedence on key collisions.
28
+ */
29
+ extends?:
30
+ | TtscLintConfigEntry<P>
31
+ | readonly TtscLintConfigEntry<P>[]
32
+ | readonly (TtscLintConfigEntry<P> | readonly TtscLintConfigEntry<P>[])[];
33
+
34
+ /**
35
+ * Contributor plugin objects keyed by namespace. Each value is the default
36
+ * export of a `@ttsc/lint` contributor package (an `ITtscLintPlugin`).
37
+ */
38
+ plugins?: P;
39
+
40
+ /** Rule-name → severity map. Supports severity tuples with options. */
41
+ rules?: TtscLintRuleMap<P>;
42
+
43
+ /**
44
+ * Prettier-style flat configuration for the `format/*` rules. Presence
45
+ * (even an empty `format: {}`) enables format-class rules at Prettier
46
+ * defaults; absence keeps them all off. Per-rule overrides go through
47
+ * the `rules` map — the `rules` entry wins on conflict.
48
+ */
49
+ format?: TtscLintFormatConfig;
50
+ }
@@ -0,0 +1,169 @@
1
+ import type { TtscLintSeverity } from "./TtscLintSeverity";
2
+
3
+ /**
4
+ * Prettier-style flat configuration for the `format/*` rules.
5
+ *
6
+ * The `format` block is the recommended way to enable formatting in
7
+ * `@ttsc/lint`. Each key mirrors a Prettier option of the same name —
8
+ * users coming from a `.prettierrc` can copy their config almost
9
+ * verbatim. The block is opt-in by presence: a `lint.config.ts` with no
10
+ * `format` field keeps every format rule off, exactly as before.
11
+ *
12
+ * Once present, the block enables a curated set of format rules at
13
+ * Prettier-aligned defaults. Individual rules can be overridden or
14
+ * disabled through the `rules` map (the `rules` entry wins on conflict).
15
+ *
16
+ * @example
17
+ * import type { TtscLintConfig } from "@ttsc/lint";
18
+ *
19
+ * export default {
20
+ * rules: { "no-var": "error" },
21
+ * format: {
22
+ * printWidth: 100,
23
+ * singleQuote: true,
24
+ * importOrder: ["<THIRD_PARTY_MODULES>", "^[./]"],
25
+ * },
26
+ * } satisfies TtscLintConfig;
27
+ *
28
+ * Deviations from Prettier:
29
+ * - `endOfLine` is restricted to `"lf"` and `"crlf"`. Prettier's
30
+ * `"cr"` and `"auto"` modes are intentionally unsupported — the
31
+ * printer does not auto-detect terminators.
32
+ * - Many Prettier knobs (`bracketSpacing`, `arrowParens`,
33
+ * `quoteProps`, JSX-specific switches) are not yet implemented.
34
+ * See `docs/14-prettier-migration.md` for the full gap list.
35
+ *
36
+ * Rule enablement matrix (when the `format` block is present):
37
+ *
38
+ * - `format/semi` — always on. `semi: false` flips it to `prefer:
39
+ * "never"`.
40
+ * - `format/quotes` — always on. `singleQuote: true` flips to
41
+ * `prefer: "single"`.
42
+ * - `format/trailing-comma` — always on. `trailingComma: "none"`
43
+ * disables the rule's edits without removing the surface.
44
+ * - `format/print-width` — always on, driven by `printWidth`,
45
+ * `tabWidth`, `useTabs`, `endOfLine`.
46
+ * - `format/sort-imports` — opt-in. Setting `importOrder` enables it.
47
+ * - `format/jsdoc` — opt-in. Setting `jsdoc` enables it.
48
+ *
49
+ * For per-rule severity overrides, drop a `rules` entry alongside:
50
+ *
51
+ * format: { semi: true, severity: "warning" },
52
+ * rules: { "format/semi": "error" },
53
+ */
54
+ export interface TtscLintFormatConfig {
55
+ /**
56
+ * Severity for every format diagnostic emitted by `ttsc check`. The
57
+ * same vocabulary as the `rules` map (`"off" | "warn" | "warning" |
58
+ * "error"` plus numeric 0/1/2). `"off"` disables both the diagnostic
59
+ * and the `ttsc format` / `ttsc fix` rewrite for every format rule.
60
+ *
61
+ * @default "warning"
62
+ */
63
+ severity?: TtscLintSeverity;
64
+
65
+ /**
66
+ * Insert trailing semicolons on ASI-terminated statements. Mirrors
67
+ * Prettier's `semi`. `false` flips the rule to require *no*
68
+ * trailing semicolon (rare; matches prettier's `semi: false`).
69
+ *
70
+ * @default true
71
+ */
72
+ semi?: boolean;
73
+
74
+ /**
75
+ * Prefer single-quoted strings. Mirrors Prettier's `singleQuote`.
76
+ * `false` means double quotes (Prettier's default).
77
+ *
78
+ * @default false
79
+ */
80
+ singleQuote?: boolean;
81
+
82
+ /**
83
+ * Trailing-comma policy. Mirrors Prettier's `trailingComma`. The
84
+ * `"none"` mode disables the rule's edits.
85
+ *
86
+ * @default "all"
87
+ */
88
+ trailingComma?: "all" | "es5" | "none";
89
+
90
+ /**
91
+ * Maximum column width before broken-form layout is chosen.
92
+ * Mirrors Prettier's `printWidth`.
93
+ *
94
+ * @default 80
95
+ */
96
+ printWidth?: number;
97
+
98
+ /**
99
+ * Indentation increment in columns. Mirrors Prettier's `tabWidth`.
100
+ *
101
+ * @default 2
102
+ */
103
+ tabWidth?: number;
104
+
105
+ /**
106
+ * Emit indentation as tab characters. Mirrors Prettier's `useTabs`.
107
+ *
108
+ * @default false
109
+ */
110
+ useTabs?: boolean;
111
+
112
+ /**
113
+ * Line terminator the printer emits on reflow. `@ttsc/lint`
114
+ * supports `"lf"` and `"crlf"`. Prettier's `"cr"` and `"auto"` are
115
+ * intentionally unsupported because the printer does not
116
+ * auto-detect line endings.
117
+ *
118
+ * @default "lf"
119
+ */
120
+ endOfLine?: "lf" | "crlf";
121
+
122
+ /**
123
+ * Group order for `format/sort-imports`. Setting this enables the
124
+ * rule; mirrors `@trivago/prettier-plugin-sort-imports`'
125
+ * `importOrder`. The `<THIRD_PARTY_MODULES>` literal is the
126
+ * catch-all placeholder for specifiers that match no other group.
127
+ */
128
+ importOrder?: readonly ("<THIRD_PARTY_MODULES>" | (string & {}))[];
129
+
130
+ /**
131
+ * Insert blank line between sort-imports groups.
132
+ *
133
+ * @default true
134
+ */
135
+ importOrderSeparation?: boolean;
136
+
137
+ /**
138
+ * Sort named import specifiers alphabetically within each
139
+ * declaration.
140
+ *
141
+ * @default true
142
+ */
143
+ importOrderSortSpecifiers?: boolean;
144
+
145
+ /**
146
+ * Case-insensitive comparison for sort-imports.
147
+ *
148
+ * @default false
149
+ */
150
+ importOrderCaseInsensitive?: boolean;
151
+
152
+ /**
153
+ * Enable `format/jsdoc`. Pass `true` to turn it on with built-in
154
+ * defaults, or an object to customize:
155
+ *
156
+ * - `tagSynonyms` — extra `from → to` rewrites layered on the
157
+ * built-in synonym table.
158
+ * - `sortTags` — sort JSDoc tags into canonical order (reserved;
159
+ * today's MVP only rewrites tag names).
160
+ *
161
+ * @default false (off)
162
+ */
163
+ jsdoc?:
164
+ | boolean
165
+ | {
166
+ tagSynonyms?: Record<string, string>;
167
+ sortTags?: boolean;
168
+ };
169
+ }
@@ -0,0 +1,10 @@
1
+ import type { ITtscLintPlugin } from "./ITtscLintPlugin";
2
+
3
+ /**
4
+ * Map of contributor plugins, keyed by their namespace prefix.
5
+ *
6
+ * The key (e.g. `"import"`) is what `@ttsc/lint`'s rule-name union joins with
7
+ * each plugin's exported `rules` tuple (`"no-cycle"`) to produce the namespaced
8
+ * rule names a user writes in `rules` (`"import/no-cycle"`).
9
+ */
10
+ export type TtscLintPlugins = Record<string, ITtscLintPlugin>;
@@ -8,12 +8,14 @@
8
8
  export type TtscLintRule =
9
9
  | "adjacent-overload-signatures"
10
10
  | "array-type"
11
+ | "await-thenable"
11
12
  | "ban-ts-comment"
12
13
  | "ban-tslint-comment"
13
14
  | "consistent-indexed-object-style"
14
15
  | "consistent-type-assertions"
15
16
  | "consistent-type-definitions"
16
17
  | "consistent-type-imports"
18
+ | "default-param-last"
17
19
  | "dot-notation"
18
20
  | "eqeqeq"
19
21
  | "for-direction"
@@ -56,6 +58,7 @@ export type TtscLintRule =
56
58
  | "no-extra-non-null-assertion"
57
59
  | "no-fallthrough"
58
60
  | "no-func-assign"
61
+ | "no-import-type-side-effects"
59
62
  | "no-inferrable-types"
60
63
  | "no-inner-declarations"
61
64
  | "no-irregular-whitespace"
@@ -66,6 +69,7 @@ export type TtscLintRule =
66
69
  | "no-loss-of-precision"
67
70
  | "no-misleading-character-class"
68
71
  | "no-misused-new"
72
+ | "no-mixed-enums"
69
73
  | "no-multi-assign"
70
74
  | "no-multi-str"
71
75
  | "no-namespace"
@@ -113,6 +117,7 @@ export type TtscLintRule =
113
117
  | "no-useless-computed-key"
114
118
  | "no-useless-concat"
115
119
  | "no-useless-constructor"
120
+ | "no-useless-escape"
116
121
  | "no-useless-rename"
117
122
  | "no-var"
118
123
  | "no-with"
@@ -135,4 +140,12 @@ export type TtscLintRule =
135
140
  | "use-isnan"
136
141
  | "valid-typeof"
137
142
  | "vars-on-top"
138
- | "yoda";
143
+ | "yoda"
144
+ // Format rules — applied by `ttsc format`. Severity also controls
145
+ // whether `ttsc check` surfaces unformatted code as a diagnostic.
146
+ | "format/semi"
147
+ | "format/quotes"
148
+ | "format/trailing-comma"
149
+ | "format/sort-imports"
150
+ | "format/jsdoc"
151
+ | "format/print-width";
@@ -0,0 +1,28 @@
1
+ import type { TtscLintRuleOptionsMap } from "./TtscLintRuleOptions";
2
+ import type { TtscLintSeverity } from "./TtscLintSeverity";
3
+
4
+ /**
5
+ * One rule's configuration entry.
6
+ *
7
+ * Accepts either a bare severity literal or a `[severity, options]` tuple. The
8
+ * options slot's type is _picked per rule name_ via `TtscLintRuleOptionsMap` —
9
+ * so a user writing
10
+ *
11
+ * "format/sort-imports": ["error", { importOrder: [...] }]
12
+ *
13
+ * Inside `TtscLintRuleMap` gets exact autocomplete and typo detection on the
14
+ * options object. The rule name is the object key; the `[severity, options]`
15
+ * tuple is the value.
16
+ *
17
+ * Rules that do not appear in `TtscLintRuleOptionsMap` accept only the severity
18
+ * literal (or the bare `[severity]` tuple): the conditional arm collapses to
19
+ * `never`, removing the options-tuple branch from the union for those rules.
20
+ * This keeps `no-var` and friends from silently accepting unrecognized option
21
+ * blobs.
22
+ */
23
+ export type TtscLintRuleEntry<R extends string = string> =
24
+ | TtscLintSeverity
25
+ | readonly [TtscLintSeverity]
26
+ | (R extends keyof TtscLintRuleOptionsMap
27
+ ? readonly [TtscLintSeverity, TtscLintRuleOptionsMap[R]]
28
+ : never);
@@ -0,0 +1,52 @@
1
+ import type { PluginRuleNames } from "./PluginRuleNames";
2
+ import type { TtscLintPlugins } from "./TtscLintPlugins";
3
+ import type { TtscLintRule } from "./TtscLintRule";
4
+ import type { TtscLintRuleOptionsMap } from "./TtscLintRuleOptions";
5
+ import type { TtscLintSeverity } from "./TtscLintSeverity";
6
+
7
+ /**
8
+ * Rule-name → severity or severity-tuple map.
9
+ *
10
+ * Built from two independent mapped types intersected together:
11
+ *
12
+ * - Rules listed in `TtscLintRuleOptionsMap` accept `severity`, `[severity]`, or
13
+ * `[severity, options]`, with the options type picked per rule key.
14
+ * - Every other built-in rule plus any contributor plugin rule accepts `severity`
15
+ * or `[severity]`.
16
+ *
17
+ * Splitting the two halves (instead of folding them into one mapped type with a
18
+ * conditional value) keeps TypeScript's contextual typing intact inside the
19
+ * options object literal: typing
20
+ *
21
+ * ```ts
22
+ * rules: {
23
+ * "format/sort-imports": ["warning", { importOrder: [...] }],
24
+ * "no-var": "error",
25
+ * }
26
+ * ```
27
+ *
28
+ * Yields exact autocomplete on `importOrder`, `importOrderSeparation`, etc.,
29
+ * while `no-var` rejects any tuple beyond a bare severity.
30
+ *
31
+ * The `(string & {})` widener is intentionally absent: typos in rule names
32
+ * produce a `TS2353` excess-property error when the literal is checked in
33
+ * isolation (e.g. one negative-case-per-const). When the literal also carries
34
+ * other shape-incompatible entries — e.g. `prefre` typo on `format/quotes` next
35
+ * to the rule-name typo — TS sometimes elides the rule-name error after
36
+ * reporting the option-key error first. The test at
37
+ * `tests/test-lint/.../test_lib_index_d_ts_rule_options_autocomplete_per_rule.ts`
38
+ * splits each negative case into its own const to keep every branch
39
+ * load-bearing.
40
+ */
41
+ export type TtscLintRuleMap<P extends TtscLintPlugins = Record<string, never>> =
42
+ {
43
+ [K in keyof TtscLintRuleOptionsMap]?:
44
+ | TtscLintSeverity
45
+ | readonly [TtscLintSeverity]
46
+ | readonly [TtscLintSeverity, TtscLintRuleOptionsMap[K]];
47
+ } & {
48
+ [K in Exclude<
49
+ TtscLintRule | PluginRuleNames<P>,
50
+ keyof TtscLintRuleOptionsMap
51
+ >]?: TtscLintSeverity | readonly [TtscLintSeverity];
52
+ };