@ttsc/lint 0.5.0-dev.20260429 → 0.5.0-dev.20260429-4

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 (28) hide show
  1. package/{go-plugin/go.mod → go.mod} +3 -3
  2. package/package.json +6 -7
  3. package/{go-plugin/lint → plugin}/ast_helpers.go +1 -1
  4. package/{go-plugin/lint → plugin}/compile.go +1 -1
  5. package/{go-plugin/lint → plugin}/config.go +1 -1
  6. package/{go-plugin/lint → plugin}/engine.go +6 -6
  7. package/{go-plugin/lint → plugin}/host.go +1 -1
  8. package/{go-plugin → plugin}/main.go +3 -5
  9. package/{go-plugin/lint → plugin}/rules_arrays.go +5 -3
  10. package/{go-plugin/lint → plugin}/rules_console.go +3 -3
  11. package/{go-plugin/lint → plugin}/rules_debugger.go +5 -5
  12. package/{go-plugin/lint → plugin}/rules_dupes.go +5 -5
  13. package/{go-plugin/lint → plugin}/rules_empty.go +4 -4
  14. package/{go-plugin/lint → plugin}/rules_eval.go +7 -5
  15. package/{go-plugin/lint → plugin}/rules_finally.go +3 -3
  16. package/{go-plugin/lint → plugin}/rules_logic.go +11 -11
  17. package/{go-plugin/lint → plugin}/rules_loops.go +3 -3
  18. package/{go-plugin/lint → plugin}/rules_misc.go +5 -5
  19. package/{go-plugin/lint → plugin}/rules_problems.go +41 -29
  20. package/{go-plugin/lint → plugin}/rules_protos.go +7 -5
  21. package/{go-plugin/lint → plugin}/rules_self.go +5 -5
  22. package/{go-plugin/lint → plugin}/rules_strings.go +11 -9
  23. package/{go-plugin/lint → plugin}/rules_suggestions.go +83 -61
  24. package/{go-plugin/lint → plugin}/rules_throw.go +3 -3
  25. package/{go-plugin/lint → plugin}/rules_ts.go +29 -19
  26. package/{go-plugin/lint → plugin}/rules_ts_extra.go +57 -35
  27. package/{go-plugin/lint → plugin}/rules_var.go +3 -3
  28. package/{index.cjs → src/index.cjs} +3 -2
@@ -3,7 +3,7 @@
3
3
  // match the rules `eslint-plugin-typescript`'s recommended preset relies
4
4
  // on most heavily — the rest of that plugin's catalog is type-aware and
5
5
  // out of scope for v0.
6
- package lint
6
+ package main
7
7
 
8
8
  import (
9
9
  "strings"
@@ -14,8 +14,10 @@ import (
14
14
  // no-confusing-non-null-assertion: `a! == b` reads ambiguously.
15
15
  type noConfusingNonNullAssertion struct{}
16
16
 
17
- func (noConfusingNonNullAssertion) Name() string { return "no-confusing-non-null-assertion" }
18
- func (noConfusingNonNullAssertion) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindBinaryExpression} }
17
+ func (noConfusingNonNullAssertion) Name() string { return "no-confusing-non-null-assertion" }
18
+ func (noConfusingNonNullAssertion) Visits() []shimast.Kind {
19
+ return []shimast.Kind{shimast.KindBinaryExpression}
20
+ }
19
21
  func (noConfusingNonNullAssertion) Check(ctx *Context, node *shimast.Node) {
20
22
  expr := node.AsBinaryExpression()
21
23
  if expr == nil || expr.OperatorToken == nil || expr.Left == nil {
@@ -39,8 +41,10 @@ func (noConfusingNonNullAssertion) Check(ctx *Context, node *shimast.Node) {
39
41
  // silently collapse.
40
42
  type noDuplicateEnumValues struct{}
41
43
 
42
- func (noDuplicateEnumValues) Name() string { return "no-duplicate-enum-values" }
43
- func (noDuplicateEnumValues) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindEnumDeclaration} }
44
+ func (noDuplicateEnumValues) Name() string { return "no-duplicate-enum-values" }
45
+ func (noDuplicateEnumValues) Visits() []shimast.Kind {
46
+ return []shimast.Kind{shimast.KindEnumDeclaration}
47
+ }
44
48
  func (noDuplicateEnumValues) Check(ctx *Context, node *shimast.Node) {
45
49
  decl := node.AsEnumDeclaration()
46
50
  if decl == nil || decl.Members == nil {
@@ -76,8 +80,10 @@ func (noDuplicateEnumValues) Check(ctx *Context, node *shimast.Node) {
76
80
  // no-extra-non-null-assertion: `a!!` / `a!?.b` collapses two assertions.
77
81
  type noExtraNonNullAssertion struct{}
78
82
 
79
- func (noExtraNonNullAssertion) Name() string { return "no-extra-non-null-assertion" }
80
- func (noExtraNonNullAssertion) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindNonNullExpression} }
83
+ func (noExtraNonNullAssertion) Name() string { return "no-extra-non-null-assertion" }
84
+ func (noExtraNonNullAssertion) Visits() []shimast.Kind {
85
+ return []shimast.Kind{shimast.KindNonNullExpression}
86
+ }
81
87
  func (noExtraNonNullAssertion) Check(ctx *Context, node *shimast.Node) {
82
88
  parent := node.Parent
83
89
  if parent == nil {
@@ -92,8 +98,10 @@ func (noExtraNonNullAssertion) Check(ctx *Context, node *shimast.Node) {
92
98
  // undefined; asserting non-null on the whole chain defeats the chain.
93
99
  type noNonNullAssertedOptionalChain struct{}
94
100
 
95
- func (noNonNullAssertedOptionalChain) Name() string { return "no-non-null-asserted-optional-chain" }
96
- func (noNonNullAssertedOptionalChain) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindNonNullExpression} }
101
+ func (noNonNullAssertedOptionalChain) Name() string { return "no-non-null-asserted-optional-chain" }
102
+ func (noNonNullAssertedOptionalChain) Visits() []shimast.Kind {
103
+ return []shimast.Kind{shimast.KindNonNullExpression}
104
+ }
97
105
  func (noNonNullAssertedOptionalChain) Check(ctx *Context, node *shimast.Node) {
98
106
  inner := node.AsNonNullExpression()
99
107
  if inner == nil || inner.Expression == nil {
@@ -142,8 +150,10 @@ func containsOptionalChain(node *shimast.Node) bool {
142
150
  // authors expect.
143
151
  type noMisusedNew struct{}
144
152
 
145
- func (noMisusedNew) Name() string { return "no-misused-new" }
146
- func (noMisusedNew) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindInterfaceDeclaration, shimast.KindTypeAliasDeclaration} }
153
+ func (noMisusedNew) Name() string { return "no-misused-new" }
154
+ func (noMisusedNew) Visits() []shimast.Kind {
155
+ return []shimast.Kind{shimast.KindInterfaceDeclaration, shimast.KindTypeAliasDeclaration}
156
+ }
147
157
  func (noMisusedNew) Check(ctx *Context, node *shimast.Node) {
148
158
  if node.Kind != shimast.KindInterfaceDeclaration {
149
159
  return
@@ -172,8 +182,10 @@ func (noMisusedNew) Check(ctx *Context, node *shimast.Node) {
172
182
  // initializer (avoids order-dependent values).
173
183
  type preferEnumInitializers struct{}
174
184
 
175
- func (preferEnumInitializers) Name() string { return "prefer-enum-initializers" }
176
- func (preferEnumInitializers) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindEnumDeclaration} }
185
+ func (preferEnumInitializers) Name() string { return "prefer-enum-initializers" }
186
+ func (preferEnumInitializers) Visits() []shimast.Kind {
187
+ return []shimast.Kind{shimast.KindEnumDeclaration}
188
+ }
177
189
  func (preferEnumInitializers) Check(ctx *Context, node *shimast.Node) {
178
190
  decl := node.AsEnumDeclaration()
179
191
  if decl == nil || decl.Members == nil {
@@ -194,8 +206,8 @@ func (preferEnumInitializers) Check(ctx *Context, node *shimast.Node) {
194
206
  // can usually be replaced with `for (const x of arr) { use(x); }`.
195
207
  type preferForOf struct{}
196
208
 
197
- func (preferForOf) Name() string { return "prefer-for-of" }
198
- func (preferForOf) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindForStatement} }
209
+ func (preferForOf) Name() string { return "prefer-for-of" }
210
+ func (preferForOf) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindForStatement} }
199
211
  func (preferForOf) Check(ctx *Context, node *shimast.Node) {
200
212
  loop := node.AsForStatement()
201
213
  if loop == nil || loop.Initializer == nil || loop.Condition == nil || loop.Incrementor == nil {
@@ -264,8 +276,10 @@ func isCounterIncrement(node *shimast.Node, counter string) bool {
264
276
  // interface F { (x: number): string } -> type F = (x: number) => string
265
277
  type preferFunctionType struct{}
266
278
 
267
- func (preferFunctionType) Name() string { return "prefer-function-type" }
268
- func (preferFunctionType) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindInterfaceDeclaration} }
279
+ func (preferFunctionType) Name() string { return "prefer-function-type" }
280
+ func (preferFunctionType) Visits() []shimast.Kind {
281
+ return []shimast.Kind{shimast.KindInterfaceDeclaration}
282
+ }
269
283
  func (preferFunctionType) Check(ctx *Context, node *shimast.Node) {
270
284
  decl := node.AsInterfaceDeclaration()
271
285
  if decl == nil || decl.Members == nil || len(decl.Members.Nodes) != 1 {
@@ -285,8 +299,10 @@ func (preferFunctionType) Check(ctx *Context, node *shimast.Node) {
285
299
  // keyword) → `namespace Foo {}`.
286
300
  type preferNamespaceKeyword struct{}
287
301
 
288
- func (preferNamespaceKeyword) Name() string { return "prefer-namespace-keyword" }
289
- func (preferNamespaceKeyword) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindModuleDeclaration} }
302
+ func (preferNamespaceKeyword) Name() string { return "prefer-namespace-keyword" }
303
+ func (preferNamespaceKeyword) Visits() []shimast.Kind {
304
+ return []shimast.Kind{shimast.KindModuleDeclaration}
305
+ }
290
306
  func (preferNamespaceKeyword) Check(ctx *Context, node *shimast.Node) {
291
307
  decl := node.AsModuleDeclaration()
292
308
  if decl == nil || decl.Name() == nil {
@@ -305,8 +321,8 @@ func (preferNamespaceKeyword) Check(ctx *Context, node *shimast.Node) {
305
321
  // Discouraged in modern code in favor of `import`.
306
322
  type tripleSlashReference struct{}
307
323
 
308
- func (tripleSlashReference) Name() string { return "triple-slash-reference" }
309
- func (tripleSlashReference) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindSourceFile} }
324
+ func (tripleSlashReference) Name() string { return "triple-slash-reference" }
325
+ func (tripleSlashReference) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindSourceFile} }
310
326
  func (tripleSlashReference) Check(ctx *Context, node *shimast.Node) {
311
327
  if ctx.File == nil {
312
328
  return
@@ -322,8 +338,8 @@ func (tripleSlashReference) Check(ctx *Context, node *shimast.Node) {
322
338
  // no-array-delete: `delete arr[0]` leaves a sparse hole. Use `splice`.
323
339
  type noArrayDelete struct{}
324
340
 
325
- func (noArrayDelete) Name() string { return "no-array-delete" }
326
- func (noArrayDelete) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindDeleteExpression} }
341
+ func (noArrayDelete) Name() string { return "no-array-delete" }
342
+ func (noArrayDelete) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindDeleteExpression} }
327
343
  func (noArrayDelete) Check(ctx *Context, node *shimast.Node) {
328
344
  del := node.AsDeleteExpression()
329
345
  if del == nil || del.Expression == nil {
@@ -355,8 +371,10 @@ func (noArrayDelete) Check(ctx *Context, node *shimast.Node) {
355
371
  // common case.
356
372
  type consistentTypeImports struct{}
357
373
 
358
- func (consistentTypeImports) Name() string { return "consistent-type-imports" }
359
- func (consistentTypeImports) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindImportDeclaration} }
374
+ func (consistentTypeImports) Name() string { return "consistent-type-imports" }
375
+ func (consistentTypeImports) Visits() []shimast.Kind {
376
+ return []shimast.Kind{shimast.KindImportDeclaration}
377
+ }
360
378
  func (consistentTypeImports) Check(ctx *Context, node *shimast.Node) {
361
379
  decl := node.AsImportDeclaration()
362
380
  if decl == nil || decl.ImportClause == nil {
@@ -440,8 +458,8 @@ func allUsesAreTypeOnly(root *shimast.Node, names []string) bool {
440
458
  // satisfies `{}`).
441
459
  type noEmptyObjectType struct{}
442
460
 
443
- func (noEmptyObjectType) Name() string { return "no-empty-object-type" }
444
- func (noEmptyObjectType) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindTypeLiteral} }
461
+ func (noEmptyObjectType) Name() string { return "no-empty-object-type" }
462
+ func (noEmptyObjectType) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindTypeLiteral} }
445
463
  func (noEmptyObjectType) Check(ctx *Context, node *shimast.Node) {
446
464
  lit := node.AsTypeLiteralNode()
447
465
  if lit == nil || lit.Members == nil {
@@ -455,8 +473,8 @@ func (noEmptyObjectType) Check(ctx *Context, node *shimast.Node) {
455
473
  // array-type: `Array<T>` vs `T[]`. ESLint default mode prefers `T[]`.
456
474
  type arrayType struct{}
457
475
 
458
- func (arrayType) Name() string { return "array-type" }
459
- func (arrayType) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindTypeReference} }
476
+ func (arrayType) Name() string { return "array-type" }
477
+ func (arrayType) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindTypeReference} }
460
478
  func (arrayType) Check(ctx *Context, node *shimast.Node) {
461
479
  ref := node.AsTypeReferenceNode()
462
480
  if ref == nil || ref.TypeName == nil {
@@ -480,8 +498,10 @@ func (arrayType) Check(ctx *Context, node *shimast.Node) {
480
498
  // `Record<string, T>`. ESLint default prefers `Record`.
481
499
  type consistentIndexedObjectStyle struct{}
482
500
 
483
- func (consistentIndexedObjectStyle) Name() string { return "consistent-indexed-object-style" }
484
- func (consistentIndexedObjectStyle) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindTypeLiteral} }
501
+ func (consistentIndexedObjectStyle) Name() string { return "consistent-indexed-object-style" }
502
+ func (consistentIndexedObjectStyle) Visits() []shimast.Kind {
503
+ return []shimast.Kind{shimast.KindTypeLiteral}
504
+ }
485
505
  func (consistentIndexedObjectStyle) Check(ctx *Context, node *shimast.Node) {
486
506
  lit := node.AsTypeLiteralNode()
487
507
  if lit == nil || lit.Members == nil || len(lit.Members.Nodes) != 1 {
@@ -505,8 +525,8 @@ func (consistentIndexedObjectStyle) Check(ctx *Context, node *shimast.Node) {
505
525
  // referencing it should be cleaned up.
506
526
  type banTslintComment struct{}
507
527
 
508
- func (banTslintComment) Name() string { return "ban-tslint-comment" }
509
- func (banTslintComment) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindSourceFile} }
528
+ func (banTslintComment) Name() string { return "ban-tslint-comment" }
529
+ func (banTslintComment) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindSourceFile} }
510
530
  func (banTslintComment) Check(ctx *Context, node *shimast.Node) {
511
531
  if ctx.File == nil {
512
532
  return
@@ -533,8 +553,10 @@ func (banTslintComment) Check(ctx *Context, node *shimast.Node) {
533
553
  // when overloads are interleaved with other members.
534
554
  type adjacentOverloadSignatures struct{}
535
555
 
536
- func (adjacentOverloadSignatures) Name() string { return "adjacent-overload-signatures" }
537
- func (adjacentOverloadSignatures) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindInterfaceDeclaration, shimast.KindTypeLiteral, shimast.KindClassDeclaration, shimast.KindClassExpression, shimast.KindModuleBlock, shimast.KindSourceFile} }
556
+ func (adjacentOverloadSignatures) Name() string { return "adjacent-overload-signatures" }
557
+ func (adjacentOverloadSignatures) Visits() []shimast.Kind {
558
+ return []shimast.Kind{shimast.KindInterfaceDeclaration, shimast.KindTypeLiteral, shimast.KindClassDeclaration, shimast.KindClassExpression, shimast.KindModuleBlock, shimast.KindSourceFile}
559
+ }
538
560
  func (adjacentOverloadSignatures) Check(ctx *Context, node *shimast.Node) {
539
561
  members := containerMembers(node)
540
562
  if len(members) == 0 {
@@ -1,4 +1,4 @@
1
- package lint
1
+ package main
2
2
 
3
3
  import shimast "github.com/microsoft/typescript-go/shim/ast"
4
4
 
@@ -6,8 +6,8 @@ import shimast "github.com/microsoft/typescript-go/shim/ast"
6
6
  // https://eslint.org/docs/latest/rules/no-var
7
7
  type noVar struct{}
8
8
 
9
- func (noVar) Name() string { return "no-var" }
10
- func (noVar) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindVariableStatement} }
9
+ func (noVar) Name() string { return "no-var" }
10
+ func (noVar) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindVariableStatement} }
11
11
  func (noVar) Check(ctx *Context, node *shimast.Node) {
12
12
  stmt := node.AsVariableStatement()
13
13
  if stmt == nil || stmt.DeclarationList == nil {
@@ -11,7 +11,7 @@ const path = require("node:path");
11
11
  * `"off"`, `"warning"`, or `"error"`.
12
12
  *
13
13
  * @param {Record<string, unknown>} _config
14
- * @returns {{ name: string; native: { mode: string; source: { dir: string }; contractVersion: 1; capabilities: string[] } }}
14
+ * @returns {{ name: string; native: { mode: string; source: { dir: string; entry: string }; contractVersion: 1; capabilities: string[] } }}
15
15
  */
16
16
  module.exports = function createTtscLint(_config) {
17
17
  return {
@@ -19,7 +19,8 @@ module.exports = function createTtscLint(_config) {
19
19
  native: {
20
20
  mode: "ttsc-lint",
21
21
  source: {
22
- dir: path.resolve(__dirname, "go-plugin"),
22
+ dir: path.resolve(__dirname, ".."),
23
+ entry: "./plugin",
23
24
  },
24
25
  contractVersion: 1,
25
26
  capabilities: ["check"],