@inthedark/dxlint 0.0.0-stage → 0.1.1

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 (183) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +84 -2
  3. package/bin/dxlint +15 -0
  4. package/bin/dxlint-linux-x64 +0 -0
  5. package/bin/dxlint-win32-x64.exe +0 -0
  6. package/package.json +40 -4
  7. package/rules/conventions.dx +34 -0
  8. package/rules/correctness.dx +33 -0
  9. package/rules/es-no-semi.dx +11 -0
  10. package/rules/format.dx +49 -0
  11. package/rules/recommended.dx +51 -0
  12. package/rules/suspicious.dx +31 -0
  13. package/rules/types.dx +21 -0
  14. package/std/c.dx +23 -0
  15. package/std/core/lines.dx +51 -0
  16. package/std/core/lists.dx +76 -0
  17. package/std/core.dx +30 -0
  18. package/std/css.dx +17 -0
  19. package/std/dx.dx +31 -0
  20. package/std/json.dx +104 -0
  21. package/std/markdown.dx +11 -0
  22. package/std/python.dx +21 -0
  23. package/std/rust/format.dx +316 -0
  24. package/std/rust.dx +34 -0
  25. package/std/toml.dx +19 -0
  26. package/std/ts/arithmetic.dx +87 -0
  27. package/std/ts/assertions.dx +477 -0
  28. package/std/ts/calls.dx +246 -0
  29. package/std/ts/comments.dx +10 -0
  30. package/std/ts/conditions.dx +531 -0
  31. package/std/ts/constants.dx +335 -0
  32. package/std/ts/deprecation.dx +185 -0
  33. package/std/ts/directives.dx +60 -0
  34. package/std/ts/effects.dx +219 -0
  35. package/std/ts/enums.dx +233 -0
  36. package/std/ts/expression-fixes.dx +67 -0
  37. package/std/ts/expressions.dx +270 -0
  38. package/std/ts/flow.dx +2 -0
  39. package/std/ts/format.dx +755 -0
  40. package/std/ts/globals.dx +106 -0
  41. package/std/ts/grammar.dx +488 -0
  42. package/std/ts/helpers.dx +102 -0
  43. package/std/ts/import-attributes.dx +88 -0
  44. package/std/ts/import-no-deprecated.dx +73 -0
  45. package/std/ts/indentation.dx +442 -0
  46. package/std/ts/jsx.dx +646 -0
  47. package/std/ts/layout/blocks.dx +281 -0
  48. package/std/ts/layout/calls.dx +79 -0
  49. package/std/ts/layout/expressions.dx +213 -0
  50. package/std/ts/layout/literals.dx +114 -0
  51. package/std/ts/layout/separators.dx +184 -0
  52. package/std/ts/layout/shared.dx +203 -0
  53. package/std/ts/layout/text.dx +142 -0
  54. package/std/ts/layout/types.dx +182 -0
  55. package/std/ts/layout.dx +9 -0
  56. package/std/ts/license.dx +54 -0
  57. package/std/ts/literal-text.dx +3 -0
  58. package/std/ts/literals.dx +95 -0
  59. package/std/ts/methods.dx +69 -0
  60. package/std/ts/modules.dx +268 -0
  61. package/std/ts/names.dx +348 -0
  62. package/std/ts/naming.dx +169 -0
  63. package/std/ts/narrowing.dx +96 -0
  64. package/std/ts/parentheses.dx +262 -0
  65. package/std/ts/precedence.dx +25 -0
  66. package/std/ts/problems/calls.dx +34 -0
  67. package/std/ts/problems/classes.dx +39 -0
  68. package/std/ts/problems/control-flow.dx +257 -0
  69. package/std/ts/problems/declarations.dx +67 -0
  70. package/std/ts/problems/duplicates.dx +70 -0
  71. package/std/ts/problems/expressions.dx +154 -0
  72. package/std/ts/problems/helpers.dx +22 -0
  73. package/std/ts/problems/imports.dx +43 -0
  74. package/std/ts/problems/non-null.dx +78 -0
  75. package/std/ts/problems/numeric-precision.dx +66 -0
  76. package/std/ts/problems/regexp.dx +66 -0
  77. package/std/ts/problems/statements.dx +36 -0
  78. package/std/ts/problems/typescript.dx +55 -0
  79. package/std/ts/problems/whitespace.dx +40 -0
  80. package/std/ts/problems.dx +20 -0
  81. package/std/ts/regex/checks.dx +249 -0
  82. package/std/ts/regex/findings.dx +209 -0
  83. package/std/ts/regex/grammar.dx +80 -0
  84. package/std/ts/regex/suggestions.dx +94 -0
  85. package/std/ts/regex/values.dx +378 -0
  86. package/std/ts/regex.dx +5 -0
  87. package/std/ts/restrictions/comments.dx +76 -0
  88. package/std/ts/restrictions.dx +811 -0
  89. package/std/ts/scopes.dx +68 -0
  90. package/std/ts/scoping/atomic.dx +40 -0
  91. package/std/ts/scoping/bindings.dx +126 -0
  92. package/std/ts/scoping/constness.dx +72 -0
  93. package/std/ts/scoping/globals.dx +52 -0
  94. package/std/ts/scoping/loops.dx +86 -0
  95. package/std/ts/scoping/member-uses.dx +111 -0
  96. package/std/ts/scoping/receivers.dx +107 -0
  97. package/std/ts/scoping/shadowing.dx +202 -0
  98. package/std/ts/scoping/usage.dx +393 -0
  99. package/std/ts/scoping.dx +842 -0
  100. package/std/ts/selectors.dx +10 -0
  101. package/std/ts/spreads.dx +97 -0
  102. package/std/ts/structure/declarations.dx +52 -0
  103. package/std/ts/structure/lines.dx +79 -0
  104. package/std/ts/structure/lists.dx +144 -0
  105. package/std/ts/structure/padding.dx +258 -0
  106. package/std/ts/structure.dx +963 -0
  107. package/std/ts/style/classes.dx +157 -0
  108. package/std/ts/style/comments.dx +75 -0
  109. package/std/ts/style/declarations.dx +82 -0
  110. package/std/ts/style/expressions.dx +125 -0
  111. package/std/ts/style/imports.dx +44 -0
  112. package/std/ts/style/ordering.dx +192 -0
  113. package/std/ts/style/returns.dx +152 -0
  114. package/std/ts/style/signatures.dx +308 -0
  115. package/std/ts/style/type-exports.dx +62 -0
  116. package/std/ts/style/type-imports.dx +166 -0
  117. package/std/ts/style/types.dx +474 -0
  118. package/std/ts/style.dx +29 -0
  119. package/std/ts/suggestions/accessors.dx +138 -0
  120. package/std/ts/suggestions/builtins.dx +110 -0
  121. package/std/ts/suggestions/comparisons.dx +41 -0
  122. package/std/ts/suggestions/computed-keys.dx +20 -0
  123. package/std/ts/suggestions/constructors.dx +54 -0
  124. package/std/ts/suggestions/control-flow.dx +204 -0
  125. package/std/ts/suggestions/curly.dx +124 -0
  126. package/std/ts/suggestions/directives.dx +79 -0
  127. package/std/ts/suggestions/errors.dx +106 -0
  128. package/std/ts/suggestions/expressions.dx +230 -0
  129. package/std/ts/suggestions/functions.dx +260 -0
  130. package/std/ts/suggestions/globals.dx +187 -0
  131. package/std/ts/suggestions/helpers.dx +17 -0
  132. package/std/ts/suggestions/object-shorthand.dx +148 -0
  133. package/std/ts/suggestions/object-spread.dx +96 -0
  134. package/std/ts/suggestions/regexp.dx +59 -0
  135. package/std/ts/suggestions/renames.dx +50 -0
  136. package/std/ts/suggestions/strings.dx +47 -0
  137. package/std/ts/suggestions/templates.dx +104 -0
  138. package/std/ts/suggestions.dx +24 -0
  139. package/std/ts/template-fixes.dx +22 -0
  140. package/std/ts/tokens.dx +124 -0
  141. package/std/ts/type-specifiers.dx +93 -0
  142. package/std/ts/typed/assignments.dx +154 -0
  143. package/std/ts/typed/awaitability.dx +157 -0
  144. package/std/ts/typed/boolean-comparisons.dx +82 -0
  145. package/std/ts/typed/defaults.dx +97 -0
  146. package/std/ts/typed/enum-consistency.dx +68 -0
  147. package/std/ts/typed/enums.dx +52 -0
  148. package/std/ts/typed/errors.dx +32 -0
  149. package/std/ts/typed/floating-promises.dx +147 -0
  150. package/std/ts/typed/for-in-arrays.dx +21 -0
  151. package/std/ts/typed/includes.dx +102 -0
  152. package/std/ts/typed/nullish-coalescing.dx +149 -0
  153. package/std/ts/typed/optional-chains.dx +317 -0
  154. package/std/ts/typed/promises.dx +205 -0
  155. package/std/ts/typed/qualifiers.dx +108 -0
  156. package/std/ts/typed/readonly-members.dx +159 -0
  157. package/std/ts/typed/readonly-parameters.dx +121 -0
  158. package/std/ts/typed/redundant-constituents.dx +171 -0
  159. package/std/ts/typed/regexp-exec.dx +79 -0
  160. package/std/ts/typed/rejection-handlers.dx +91 -0
  161. package/std/ts/typed/return-await.dx +116 -0
  162. package/std/ts/typed/return-this.dx +67 -0
  163. package/std/ts/typed/strict-void-return.dx +121 -0
  164. package/std/ts/typed/string-boundaries.dx +153 -0
  165. package/std/ts/typed/switches.dx +147 -0
  166. package/std/ts/typed/template-expressions.dx +127 -0
  167. package/std/ts/typed/template-values.dx +88 -0
  168. package/std/ts/typed/transfers.dx +106 -0
  169. package/std/ts/typed/type-arguments.dx +337 -0
  170. package/std/ts/typed/type-constituents.dx +143 -0
  171. package/std/ts/typed/type-conversions.dx +82 -0
  172. package/std/ts/typed/type-parameters.dx +280 -0
  173. package/std/ts/typed/unbound-method.dx +167 -0
  174. package/std/ts/typed/unsafe-calls.dx +73 -0
  175. package/std/ts/typed/unsafe-members.dx +36 -0
  176. package/std/ts/typed/void-expressions.dx +101 -0
  177. package/std/ts/typed.dx +585 -0
  178. package/std/ts/values/arguments.dx +13 -0
  179. package/std/ts/values/enums.dx +104 -0
  180. package/std/ts/values/inspection.dx +274 -0
  181. package/std/ts/values.dx +1217 -0
  182. package/std/ts.dx +77 -0
  183. package/std/whitespace.dx +37 -0
@@ -0,0 +1,246 @@
1
+ # .ts/calls: signatures and invocation syntax.
2
+ import .ts/effects
3
+
4
+ define {
5
+ in ts_member, ts_index let in_optional_chain optional != null || object.in_optional_chain == true
6
+ in ts_call let in_optional_chain optional != null || callee.in_optional_chain == true
7
+ in ts_non_null let in_optional_chain expression.in_optional_chain == true
8
+ in ts_parenthesized let wraps_optional_chain expression.in_optional_chain == true || expression.wraps_optional_chain == true
9
+
10
+ fn ts_calls_return_candidate(n) = {
11
+ value bare: unparenthesised_node(n)
12
+ value when {
13
+ bare is (ts_number, ts_string, ts_boolean, ts_bigint) then true
14
+ bare is ts_identifier then {
15
+ value declaration: bare.scope_declaration.parent.node
16
+ value declaration is ts_declarator && declaration.type == null
17
+ && declaration.parent.kind == "const"
18
+ }
19
+ else then bare is (ts_unary, ts_conditional, ts_logical, ts_sequence, ts_satisfies)
20
+ }
21
+ }
22
+
23
+ fn ts_calls_return_arguments(owner) = if owner.body is ts_block then {
24
+ value flow_declared_effects(owner.body.node, "returned")
25
+ filter (effect) effect.site is ts_return
26
+ map (effect) effect.site.argument.node
27
+ } else [owner.body.node]
28
+
29
+ fn ts_calls_widens_return(owner) = {
30
+ value if (contains([] owner.modifier, "async") || contains([] owner.modifier, "*"))
31
+ && value_has_expected(owner) != false then false else {
32
+ value arguments: ts_calls_return_arguments(owner)
33
+ value if count(arguments) == 0 || !all(arguments, argument => argument != null
34
+ && ts_calls_return_candidate(argument))
35
+ || owner.body is ts_block && flow_normal(owner.body.node) != false then false else {
36
+ value rows: map(arguments, argument => value_constituents(argument))
37
+ value parts: { value rows; flat_map (row) row; unique }
38
+ value part: if all(rows, row => row != null) && count(parts) == 1
39
+ && count(first(parts)) == 1 then first(first(parts)) else null
40
+ value part != null && contains(part.traits, "literal")
41
+ && all(arguments, argument => ts_value_fresh_literal(argument, part)
42
+ && !ts_value_contextual_literal(argument, part))
43
+ }
44
+ }
45
+ }
46
+
47
+ in ts_function, ts_arrow, ts_method, ts_function_type, ts_method_signature, ts_call_signature {
48
+ overloads infer last
49
+ let calls_overload_implementation node.body != null && (
50
+ node is ts_function && any(name_binding(node.name.node).declarations, declaration =>
51
+ declaration.parent.node is ts_function && declaration.parent.node.body == null)
52
+ || node is ts_method && parent is ts_class && ts_value_key(key.node) != null
53
+ && any(parent.member.nodes, declaration => declaration is ts_method && declaration.body == null
54
+ && ts_value_key(declaration.key.node) == ts_value_key(key.node)
55
+ && ts_value_static(declaration.modifier.nodes) == ts_value_static(modifier.nodes)))
56
+ let calls_receivers filter(parameter.nodes, p => p.name is ts_this || p.name is ts_identifier && p.name == "this")
57
+ let calls_parameters filter(parameter.nodes, p => !(p.name is ts_this || p.name is ts_identifier && p.name == "this"))
58
+ let calls_concise_result if node is ts_arrow && node.body not ts_block then node.body.node else null
59
+ let calls_inferred_widen if node is (ts_function, ts_arrow, ts_method) && node.body != null && return_type == null
60
+ then ts_calls_widens_return(node) else false
61
+ let calls_generator_yields {
62
+ value descendants(ts_yield)
63
+ filter (yielded) ts_effects_function_owner(yielded) == node
64
+ }
65
+ let calls_generator_delegates any(calls_generator_yields, yielded => yielded.operator == "*")
66
+ let calls_discards_result if return_type is ts_type_keyword then return_type.text == "void" else {
67
+ # Asking for the one trait is much cheaper than building every constituent.
68
+ value parts: if ts_value_has_trait(return_type.node, "void") == false then null else value_constituents(return_type.node)
69
+ value parts != null && count(parts) > 0
70
+ && all(parts, arm => any(arm, part => contains(part.traits, "void")))
71
+ }
72
+ when node is ts_method && calls_constructor { generics parent.type_parameter }
73
+ when !(node is ts_method && calls_constructor) { generics type_parameter }
74
+ when !calls_overload_implementation && !contains([] node.modifier, "async") && !contains([] node.modifier, "*")
75
+ && !(node is ts_method && node.calls_constructor) {
76
+ when calls_concise_result != null && calls_inferred_widen {
77
+ signature calls_parameters receiver calls_receivers returns calls_concise_result.widened
78
+ }
79
+ when calls_concise_result == null || !calls_inferred_widen {
80
+ signature calls_parameters receiver calls_receivers returns return_type ?? calls_concise_result ?? (returned default trait void, undefined, nullable, falsy, nonthenable)
81
+ }
82
+ }
83
+ when !calls_overload_implementation && contains([] node.modifier, "async") && !contains([] node.modifier, "*") {
84
+ when calls_concise_result != null && calls_inferred_widen {
85
+ signature calls_parameters receiver calls_receivers returns instance "Promise" of calls_concise_result.widened
86
+ }
87
+ when calls_concise_result == null || !calls_inferred_widen {
88
+ signature calls_parameters receiver calls_receivers returns return_type ?? instance "Promise" of (calls_concise_result ?? (returned default trait void, undefined, nullable, falsy, nonthenable))
89
+ }
90
+ }
91
+ when !calls_overload_implementation && contains([] node.modifier, "*") {
92
+ when return_type != null {
93
+ signature calls_parameters receiver calls_receivers returns return_type
94
+ }
95
+ when return_type == null {
96
+ when !contains([] node.modifier, "async") && !calls_generator_delegates {
97
+ signature calls_parameters receiver calls_receivers returns instance "Generator" of (...calls_generator_yields using (argument ?? trait undefined, nullable, falsy, nonthenable)), (returned default trait void, undefined, nullable, falsy, nonthenable), (trait unknown)
98
+ }
99
+ when !contains([] node.modifier, "async") && calls_generator_delegates {
100
+ signature calls_parameters receiver calls_receivers returns instance "Generator" of (trait unknown), (returned default trait void, undefined, nullable, falsy, nonthenable), (trait unknown)
101
+ }
102
+ when contains([] node.modifier, "async") && !calls_generator_delegates {
103
+ signature calls_parameters receiver calls_receivers returns instance "AsyncGenerator" of (...calls_generator_yields using (instance "Awaited" of (argument ?? trait undefined, nullable, falsy, nonthenable))), (instance "Awaited" of (returned default trait void, undefined, nullable, falsy, nonthenable)), (trait unknown)
104
+ }
105
+ when contains([] node.modifier, "async") && calls_generator_delegates {
106
+ signature calls_parameters receiver calls_receivers returns instance "AsyncGenerator" of (trait unknown), (instance "Awaited" of (returned default trait void, undefined, nullable, falsy, nonthenable)), (trait unknown)
107
+ }
108
+ }
109
+ }
110
+ discards result when calls_discards_result
111
+ }
112
+
113
+ in ts_function, ts_arrow { fits callable }
114
+ in ts_function_type, ts_call_signature {
115
+ fits callable when kind != "new"
116
+ fits constructible when kind == "new"
117
+ }
118
+
119
+ in ts_method {
120
+ let calls_constructor parent is ts_class && kind == null && !contains([] modifier, "static") && (
121
+ key is ts_identifier && key == "constructor" || key is ts_string && js_string(key.text) == "constructor"
122
+ )
123
+ fits callable when kind != "get" && kind != "set" && !calls_constructor
124
+ fits constructible when calls_constructor
125
+ when calls_constructor && !calls_overload_implementation {
126
+ signature calls_parameters receiver calls_receivers returns scope members from parent
127
+ }
128
+ variance parameters bivariant
129
+ }
130
+ in ts_method_signature {
131
+ fits callable when kind != "get" && kind != "set"
132
+ variance parameters bivariant
133
+ }
134
+
135
+ in ts_interface, ts_type_literal {
136
+ let calls_headers filter(member.nodes, h => h is ts_call_signature)
137
+ signatures calls_headers
138
+ fits callable when any(calls_headers, h => h.kind != "new")
139
+ fits constructible when any(calls_headers, h => h.kind == "new")
140
+ }
141
+ in ts_class {
142
+ let calls_constructor_headers filter(member.nodes, h => h is ts_method && h.calls_constructor)
143
+ when count(calls_constructor_headers) > 0 { signatures calls_constructor_headers }
144
+ when count(calls_constructor_headers) == 0 && extends == null {
145
+ signature calls_constructor_headers returns scope members from it
146
+ }
147
+ when count(calls_constructor_headers) == 0 && extends != null {
148
+ signatures extends returns scope members from it
149
+ }
150
+ }
151
+
152
+ in ts_parameter {
153
+ optional when optional != null || init != null
154
+ fits rest when name is ts_rest
155
+ }
156
+ in ts_type_parameter { optional when default != null }
157
+ in ts_rest, ts_spread { fits rest }
158
+
159
+ in ts_call {
160
+ when in_optional_chain == true { calls (callee \ nullable, undefined) with argument }
161
+ # A bare call's `this` is void: a signature declaring `this: object` does not apply.
162
+ when in_optional_chain != true && callee is ts_identifier {
163
+ calls callee with argument this (trait void, undefined, nullable, falsy, nonthenable)
164
+ }
165
+ when in_optional_chain != true && !(callee is ts_identifier) { calls callee with argument }
166
+ }
167
+ in ts_new { constructs callee with argument }
168
+ # Overload resolution tries the subtype relation (where `any` fits only
169
+ # `any`/`unknown`) before assignability.
170
+ in ts_call, ts_new { overloads exact first }
171
+ in ts_tagged_template {
172
+ let calls_arguments [] quasi.node quasi.expression.nodes
173
+ calls tag with calls_arguments
174
+ }
175
+
176
+ in ts_declarator {
177
+ when type != null { in init expects type }
178
+ }
179
+ in ts_class_property { in init expects type ?? it.expected }
180
+ in ts_assignment { in right expects left }
181
+ in ts_parenthesized { in expression expects it.expected }
182
+ in ts_as, ts_type_assertion { in expression expects type }
183
+ in ts_array { in element expects each (parent.expected \ nullable).[position] }
184
+ in ts_method, ts_class_property, ts_property {
185
+ let calls_member_key if key is ts_computed_key then key.expression.node else ts_value_key(key.node)
186
+ when parent is ts_object || parent is ts_class && contains([] modifier, "static") {
187
+ in it expects parent.expected.[calls_member_key]
188
+ }
189
+ when parent is ts_class && parent.extends != null {
190
+ when !contains([] modifier, "static") {
191
+ in it expects parent.extends.["prototype"].[calls_member_key]
192
+ }
193
+ when contains([] modifier, "static") {
194
+ in it expects parent.extends.[calls_member_key]
195
+ }
196
+ }
197
+ when parent is ts_class && parent.implements != null && !contains([] modifier, "static") {
198
+ in it expects (...parent.implements).[calls_member_key]
199
+ }
200
+ }
201
+ in ts_property { in value expects it.expected }
202
+ in ts_jsx_attribute {
203
+ let calls_jsx_key ts_value_key(name.node)
204
+ in value expects parent.name.first_parameter.[calls_jsx_key]
205
+ }
206
+ in ts_jsx_expression { in expression expects it.expected }
207
+ in ts_arrow {
208
+ when body not ts_block { in body expects return_type ?? it.expected.result }
209
+ }
210
+ in ts_return {
211
+ let calls_return_function ts_effects_function_owner(node)
212
+ when calls_return_function is ts_method && calls_return_function.kind == "get" {
213
+ in argument expects calls_return_function.return_type
214
+ }
215
+ when !(calls_return_function is ts_method && calls_return_function.kind == "get") {
216
+ in argument expects calls_return_function.return_type ?? calls_return_function.expected.result
217
+ }
218
+ }
219
+ # Wrappers pass their own context to the operand that produces their value.
220
+ fn ts_calls_context_scalar(n) = {
221
+ value operand: unparenthesised_node(n)
222
+ value annotation: if operand is ts_identifier then name_binding(operand).node.parent.type.node else null
223
+ value operand is (ts_number, ts_string, ts_boolean, ts_bigint, ts_null)
224
+ || annotation is ts_type_keyword && ts_value_nonthenable(annotation) == true
225
+ }
226
+ in ts_non_null { in expression expects it.expected }
227
+ in ts_satisfies { in expression expects type }
228
+ in ts_conditional {
229
+ in consequent expects it.expected
230
+ in alternate expects it.expected
231
+ }
232
+ in ts_logical {
233
+ in left expects it.expected
234
+ in right expects it.expected
235
+ }
236
+ in ts_sequence {
237
+ let calls_sequence_result last(expression.nodes)
238
+ in calls_sequence_result expects it.expected
239
+ }
240
+ in ts_await {
241
+ when ts_calls_context_scalar(argument.node) { in argument expects it.expected }
242
+ when !ts_calls_context_scalar(argument.node) {
243
+ in argument expects it.expected | instance "PromiseLike" of it.expected
244
+ }
245
+ }
246
+ }
@@ -0,0 +1,10 @@
1
+ import .core
2
+
3
+ define {
4
+ in ts_code {
5
+ match ts_line_comment like core_line_comment @core_line_comment_pattern
6
+ match ts_block_comment like core_block_comment @core_block_comment_pattern
7
+ }
8
+ }
9
+
10
+ group ts_comment ts_line_comment, ts_block_comment