@ttsc/lint 0.19.3 → 0.20.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.
Files changed (63) hide show
  1. package/README.md +1 -1
  2. package/lib/index.js +26 -4
  3. package/lib/index.js.map +1 -1
  4. package/lib/structures/format/ITtscLintFormat.d.ts +14 -10
  5. package/lib/structures/rules/ITtscLintRegexpRules.d.ts +24 -9
  6. package/lib/structures/rules/ITtscLintSecurityRules.d.ts +18 -0
  7. package/lib/structures/rules/ITtscLintSolidRules.d.ts +22 -2
  8. package/lib/structures/rules/ITtscLintStorybookRules.d.ts +21 -0
  9. package/lib/structures/rules/ITtscLintTypeScriptRuleOptions.d.ts +10 -1
  10. package/lib/structures/rules/ITtscLintTypeScriptRules.d.ts +13 -2
  11. package/linthost/compile.go +9 -4
  12. package/linthost/config.go +18 -14
  13. package/linthost/contrib_adapter.go +57 -0
  14. package/linthost/dispatch.go +5 -1
  15. package/linthost/display_width.go +179 -41
  16. package/linthost/engine.go +120 -4
  17. package/linthost/flags_gen.go +4 -4
  18. package/linthost/hints.go +207 -0
  19. package/linthost/host.go +68 -0
  20. package/linthost/lsp.go +148 -29
  21. package/linthost/print_dispatch.go +24 -0
  22. package/linthost/print_nodes_array.go +88 -15
  23. package/linthost/print_nodes_call.go +38 -31
  24. package/linthost/print_nodes_control_flow.go +319 -0
  25. package/linthost/print_nodes_function.go +140 -13
  26. package/linthost/print_nodes_list.go +22 -10
  27. package/linthost/project_engine.go +18 -1
  28. package/linthost/project_rules.go +47 -0
  29. package/linthost/rule_docs.go +114 -0
  30. package/linthost/rules_boundaries.go +80 -2
  31. package/linthost/rules_format_bracket_spacing.go +18 -6
  32. package/linthost/rules_format_clause_join.go +11 -8
  33. package/linthost/rules_format_indent.go +155 -4
  34. package/linthost/rules_format_print_width.go +12 -35
  35. package/linthost/rules_format_quote_props.go +88 -27
  36. package/linthost/rules_format_statement_split.go +81 -0
  37. package/linthost/rules_format_trailing_comma.go +62 -94
  38. package/linthost/rules_gap.go +26 -17
  39. package/linthost/rules_jsdoc.go +54 -0
  40. package/linthost/rules_logic.go +30 -15
  41. package/linthost/rules_no_redeclare.go +12 -3
  42. package/linthost/rules_promise.go +37 -15
  43. package/linthost/rules_regexp.go +443 -49
  44. package/linthost/rules_security.go +243 -4
  45. package/linthost/rules_solid.go +430 -10
  46. package/linthost/rules_storybook.go +255 -10
  47. package/linthost/rules_suggestions.go +60 -39
  48. package/linthost/rules_ts.go +7 -0
  49. package/linthost/rules_ts_async.go +80 -2
  50. package/linthost/rules_ts_extra.go +21 -7
  51. package/linthost/serve.go +318 -0
  52. package/linthost/width_tables_gen.go +219 -0
  53. package/package.json +2 -2
  54. package/rule/hint.go +142 -0
  55. package/rule/rule.go +197 -1
  56. package/src/index.ts +35 -4
  57. package/src/structures/format/ITtscLintFormat.ts +14 -10
  58. package/src/structures/rules/ITtscLintRegexpRules.ts +24 -9
  59. package/src/structures/rules/ITtscLintSecurityRules.ts +18 -0
  60. package/src/structures/rules/ITtscLintSolidRules.ts +22 -2
  61. package/src/structures/rules/ITtscLintStorybookRules.ts +21 -0
  62. package/src/structures/rules/ITtscLintTypeScriptRuleOptions.ts +10 -1
  63. package/src/structures/rules/ITtscLintTypeScriptRules.ts +13 -2
@@ -862,6 +862,14 @@ func analyzeFloatingPromiseCall(
862
862
  var nonPromiseReceivers []*shimchecker.Type
863
863
  sawPromiseReceiver := false
864
864
  sawUnsafePromiseReceiver := false
865
+ // A thenable receiver the option leaves out of scope is not the same as a
866
+ // receiver that is not promise-like at all. Upstream's `checkThenables`
867
+ // decides which types the rule examines — "whether to check all Thenables,
868
+ // not just the built-in Promise type" — so with the option off a thenable is
869
+ // outside the rule, not an unhandled promise. Collapsing the two is what made
870
+ // `false` the strict setting here and `true` the lenient one, the exact
871
+ // inversion of the option this borrows its name from.
872
+ sawOutOfScopeThenable := false
865
873
  receiverIsOptional := floatingPromisePropertyAccessIsOptional(call.Expression)
866
874
  for _, part := range promiseUnionParts(apparent) {
867
875
  if part == nil {
@@ -875,15 +883,26 @@ func analyzeFloatingPromiseCall(
875
883
  sawPromiseReceiver = true
876
884
  continue
877
885
  }
878
- if isNativePromiseInstanceLike(ctx.Checker, part) ||
879
- (options.CheckThenables && isCatchableThenableAtLocation(ctx.Checker, receiver, part)) {
886
+ if isNativePromiseInstanceLike(ctx.Checker, part) {
880
887
  sawPromiseReceiver = true
881
888
  sawUnsafePromiseReceiver = true
882
889
  continue
883
890
  }
891
+ if isCatchableThenableAtLocation(ctx.Checker, receiver, part) {
892
+ if options.CheckThenables {
893
+ sawPromiseReceiver = true
894
+ sawUnsafePromiseReceiver = true
895
+ continue
896
+ }
897
+ sawOutOfScopeThenable = true
898
+ continue
899
+ }
884
900
  nonPromiseReceivers = append(nonPromiseReceivers, part)
885
901
  }
886
902
  if !sawPromiseReceiver {
903
+ if sawOutOfScopeThenable && len(nonPromiseReceivers) == 0 {
904
+ return floatingPromiseResult{}
905
+ }
887
906
  return floatingPromiseResult{unhandled: callResultIsFloating}
888
907
  }
889
908
 
@@ -959,20 +978,23 @@ func floatingPromiseMethodCall(call *shimast.CallExpression) (*shimast.Node, str
959
978
  return receiver, method, true
960
979
  }
961
980
 
981
+ // floatingPromisePropertyAccessIsOptional reports whether a null or undefined
982
+ // branch of the receiver's type is unreachable at this access.
983
+ //
984
+ // The guard is not only the access's own `?.`. An optional chain short-circuits
985
+ // as a whole, so in `maybe?.run().catch(handler)` the `.catch` access is never
986
+ // evaluated when `maybe` is nullish, even though it carries no `?.` of its own.
987
+ // Reading only the outermost token left the `undefined` branch of
988
+ // `Promise<void> | undefined` looking like a real receiver, and the rule
989
+ // reported a chain that ends in a callable rejection handler.
990
+ //
991
+ // `containsOptionalChain` already walks exactly this shape for
992
+ // `no-non-null-asserted-optional-chain`: it descends property, element, and
993
+ // call links, and stops at any other node kind. Stopping there is what makes a
994
+ // parenthesized sub-expression end the chain — `(maybe?.run()).catch(handler)`
995
+ // really can throw, so that shape must keep its nullish branch.
962
996
  func floatingPromisePropertyAccessIsOptional(node *shimast.Node) bool {
963
- node = stripParens(node)
964
- if node == nil {
965
- return false
966
- }
967
- switch node.Kind {
968
- case shimast.KindPropertyAccessExpression:
969
- access := node.AsPropertyAccessExpression()
970
- return access != nil && access.QuestionDotToken != nil
971
- case shimast.KindElementAccessExpression:
972
- access := node.AsElementAccessExpression()
973
- return access != nil && access.QuestionDotToken != nil
974
- }
975
- return false
997
+ return containsOptionalChain(stripParens(node))
976
998
  }
977
999
 
978
1000
  // floatingPromiseMethodReturnIsUnhandled determines what a non-Promise