@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.
- package/README.md +1 -1
- package/lib/index.js +26 -4
- package/lib/index.js.map +1 -1
- package/lib/structures/format/ITtscLintFormat.d.ts +14 -10
- package/lib/structures/rules/ITtscLintRegexpRules.d.ts +24 -9
- package/lib/structures/rules/ITtscLintSecurityRules.d.ts +18 -0
- package/lib/structures/rules/ITtscLintSolidRules.d.ts +22 -2
- package/lib/structures/rules/ITtscLintStorybookRules.d.ts +21 -0
- package/lib/structures/rules/ITtscLintTypeScriptRuleOptions.d.ts +10 -1
- package/lib/structures/rules/ITtscLintTypeScriptRules.d.ts +13 -2
- package/linthost/compile.go +9 -4
- package/linthost/config.go +18 -14
- package/linthost/contrib_adapter.go +57 -0
- package/linthost/dispatch.go +5 -1
- package/linthost/display_width.go +179 -41
- package/linthost/engine.go +120 -4
- package/linthost/flags_gen.go +4 -4
- package/linthost/hints.go +207 -0
- package/linthost/host.go +68 -0
- package/linthost/lsp.go +148 -29
- package/linthost/print_dispatch.go +24 -0
- package/linthost/print_nodes_array.go +88 -15
- package/linthost/print_nodes_call.go +38 -31
- package/linthost/print_nodes_control_flow.go +319 -0
- package/linthost/print_nodes_function.go +140 -13
- package/linthost/print_nodes_list.go +22 -10
- package/linthost/project_engine.go +18 -1
- package/linthost/project_rules.go +47 -0
- package/linthost/rule_docs.go +114 -0
- package/linthost/rules_boundaries.go +80 -2
- package/linthost/rules_format_bracket_spacing.go +18 -6
- package/linthost/rules_format_clause_join.go +11 -8
- package/linthost/rules_format_indent.go +155 -4
- package/linthost/rules_format_print_width.go +12 -35
- package/linthost/rules_format_quote_props.go +88 -27
- package/linthost/rules_format_statement_split.go +81 -0
- package/linthost/rules_format_trailing_comma.go +62 -94
- package/linthost/rules_gap.go +26 -17
- package/linthost/rules_jsdoc.go +54 -0
- package/linthost/rules_logic.go +30 -15
- package/linthost/rules_no_redeclare.go +12 -3
- package/linthost/rules_promise.go +37 -15
- package/linthost/rules_regexp.go +443 -49
- package/linthost/rules_security.go +243 -4
- package/linthost/rules_solid.go +430 -10
- package/linthost/rules_storybook.go +255 -10
- package/linthost/rules_suggestions.go +60 -39
- package/linthost/rules_ts.go +7 -0
- package/linthost/rules_ts_async.go +80 -2
- package/linthost/rules_ts_extra.go +21 -7
- package/linthost/serve.go +318 -0
- package/linthost/width_tables_gen.go +219 -0
- package/package.json +2 -2
- package/rule/hint.go +142 -0
- package/rule/rule.go +197 -1
- package/src/index.ts +35 -4
- package/src/structures/format/ITtscLintFormat.ts +14 -10
- package/src/structures/rules/ITtscLintRegexpRules.ts +24 -9
- package/src/structures/rules/ITtscLintSecurityRules.ts +18 -0
- package/src/structures/rules/ITtscLintSolidRules.ts +22 -2
- package/src/structures/rules/ITtscLintStorybookRules.ts +21 -0
- package/src/structures/rules/ITtscLintTypeScriptRuleOptions.ts +10 -1
- 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
|
-
|
|
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
|