@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.
- package/LICENSE +21 -0
- package/README.md +84 -2
- package/bin/dxlint +15 -0
- package/bin/dxlint-linux-x64 +0 -0
- package/bin/dxlint-win32-x64.exe +0 -0
- package/package.json +40 -4
- package/rules/conventions.dx +34 -0
- package/rules/correctness.dx +33 -0
- package/rules/es-no-semi.dx +11 -0
- package/rules/format.dx +49 -0
- package/rules/recommended.dx +51 -0
- package/rules/suspicious.dx +31 -0
- package/rules/types.dx +21 -0
- package/std/c.dx +23 -0
- package/std/core/lines.dx +51 -0
- package/std/core/lists.dx +76 -0
- package/std/core.dx +30 -0
- package/std/css.dx +17 -0
- package/std/dx.dx +31 -0
- package/std/json.dx +104 -0
- package/std/markdown.dx +11 -0
- package/std/python.dx +21 -0
- package/std/rust/format.dx +316 -0
- package/std/rust.dx +34 -0
- package/std/toml.dx +19 -0
- package/std/ts/arithmetic.dx +87 -0
- package/std/ts/assertions.dx +477 -0
- package/std/ts/calls.dx +246 -0
- package/std/ts/comments.dx +10 -0
- package/std/ts/conditions.dx +531 -0
- package/std/ts/constants.dx +335 -0
- package/std/ts/deprecation.dx +185 -0
- package/std/ts/directives.dx +60 -0
- package/std/ts/effects.dx +219 -0
- package/std/ts/enums.dx +233 -0
- package/std/ts/expression-fixes.dx +67 -0
- package/std/ts/expressions.dx +270 -0
- package/std/ts/flow.dx +2 -0
- package/std/ts/format.dx +755 -0
- package/std/ts/globals.dx +106 -0
- package/std/ts/grammar.dx +488 -0
- package/std/ts/helpers.dx +102 -0
- package/std/ts/import-attributes.dx +88 -0
- package/std/ts/import-no-deprecated.dx +73 -0
- package/std/ts/indentation.dx +442 -0
- package/std/ts/jsx.dx +646 -0
- package/std/ts/layout/blocks.dx +281 -0
- package/std/ts/layout/calls.dx +79 -0
- package/std/ts/layout/expressions.dx +213 -0
- package/std/ts/layout/literals.dx +114 -0
- package/std/ts/layout/separators.dx +184 -0
- package/std/ts/layout/shared.dx +203 -0
- package/std/ts/layout/text.dx +142 -0
- package/std/ts/layout/types.dx +182 -0
- package/std/ts/layout.dx +9 -0
- package/std/ts/license.dx +54 -0
- package/std/ts/literal-text.dx +3 -0
- package/std/ts/literals.dx +95 -0
- package/std/ts/methods.dx +69 -0
- package/std/ts/modules.dx +268 -0
- package/std/ts/names.dx +348 -0
- package/std/ts/naming.dx +169 -0
- package/std/ts/narrowing.dx +96 -0
- package/std/ts/parentheses.dx +262 -0
- package/std/ts/precedence.dx +25 -0
- package/std/ts/problems/calls.dx +34 -0
- package/std/ts/problems/classes.dx +39 -0
- package/std/ts/problems/control-flow.dx +257 -0
- package/std/ts/problems/declarations.dx +67 -0
- package/std/ts/problems/duplicates.dx +70 -0
- package/std/ts/problems/expressions.dx +154 -0
- package/std/ts/problems/helpers.dx +22 -0
- package/std/ts/problems/imports.dx +43 -0
- package/std/ts/problems/non-null.dx +78 -0
- package/std/ts/problems/numeric-precision.dx +66 -0
- package/std/ts/problems/regexp.dx +66 -0
- package/std/ts/problems/statements.dx +36 -0
- package/std/ts/problems/typescript.dx +55 -0
- package/std/ts/problems/whitespace.dx +40 -0
- package/std/ts/problems.dx +20 -0
- package/std/ts/regex/checks.dx +249 -0
- package/std/ts/regex/findings.dx +209 -0
- package/std/ts/regex/grammar.dx +80 -0
- package/std/ts/regex/suggestions.dx +94 -0
- package/std/ts/regex/values.dx +378 -0
- package/std/ts/regex.dx +5 -0
- package/std/ts/restrictions/comments.dx +76 -0
- package/std/ts/restrictions.dx +811 -0
- package/std/ts/scopes.dx +68 -0
- package/std/ts/scoping/atomic.dx +40 -0
- package/std/ts/scoping/bindings.dx +126 -0
- package/std/ts/scoping/constness.dx +72 -0
- package/std/ts/scoping/globals.dx +52 -0
- package/std/ts/scoping/loops.dx +86 -0
- package/std/ts/scoping/member-uses.dx +111 -0
- package/std/ts/scoping/receivers.dx +107 -0
- package/std/ts/scoping/shadowing.dx +202 -0
- package/std/ts/scoping/usage.dx +393 -0
- package/std/ts/scoping.dx +842 -0
- package/std/ts/selectors.dx +10 -0
- package/std/ts/spreads.dx +97 -0
- package/std/ts/structure/declarations.dx +52 -0
- package/std/ts/structure/lines.dx +79 -0
- package/std/ts/structure/lists.dx +144 -0
- package/std/ts/structure/padding.dx +258 -0
- package/std/ts/structure.dx +963 -0
- package/std/ts/style/classes.dx +157 -0
- package/std/ts/style/comments.dx +75 -0
- package/std/ts/style/declarations.dx +82 -0
- package/std/ts/style/expressions.dx +125 -0
- package/std/ts/style/imports.dx +44 -0
- package/std/ts/style/ordering.dx +192 -0
- package/std/ts/style/returns.dx +152 -0
- package/std/ts/style/signatures.dx +308 -0
- package/std/ts/style/type-exports.dx +62 -0
- package/std/ts/style/type-imports.dx +166 -0
- package/std/ts/style/types.dx +474 -0
- package/std/ts/style.dx +29 -0
- package/std/ts/suggestions/accessors.dx +138 -0
- package/std/ts/suggestions/builtins.dx +110 -0
- package/std/ts/suggestions/comparisons.dx +41 -0
- package/std/ts/suggestions/computed-keys.dx +20 -0
- package/std/ts/suggestions/constructors.dx +54 -0
- package/std/ts/suggestions/control-flow.dx +204 -0
- package/std/ts/suggestions/curly.dx +124 -0
- package/std/ts/suggestions/directives.dx +79 -0
- package/std/ts/suggestions/errors.dx +106 -0
- package/std/ts/suggestions/expressions.dx +230 -0
- package/std/ts/suggestions/functions.dx +260 -0
- package/std/ts/suggestions/globals.dx +187 -0
- package/std/ts/suggestions/helpers.dx +17 -0
- package/std/ts/suggestions/object-shorthand.dx +148 -0
- package/std/ts/suggestions/object-spread.dx +96 -0
- package/std/ts/suggestions/regexp.dx +59 -0
- package/std/ts/suggestions/renames.dx +50 -0
- package/std/ts/suggestions/strings.dx +47 -0
- package/std/ts/suggestions/templates.dx +104 -0
- package/std/ts/suggestions.dx +24 -0
- package/std/ts/template-fixes.dx +22 -0
- package/std/ts/tokens.dx +124 -0
- package/std/ts/type-specifiers.dx +93 -0
- package/std/ts/typed/assignments.dx +154 -0
- package/std/ts/typed/awaitability.dx +157 -0
- package/std/ts/typed/boolean-comparisons.dx +82 -0
- package/std/ts/typed/defaults.dx +97 -0
- package/std/ts/typed/enum-consistency.dx +68 -0
- package/std/ts/typed/enums.dx +52 -0
- package/std/ts/typed/errors.dx +32 -0
- package/std/ts/typed/floating-promises.dx +147 -0
- package/std/ts/typed/for-in-arrays.dx +21 -0
- package/std/ts/typed/includes.dx +102 -0
- package/std/ts/typed/nullish-coalescing.dx +149 -0
- package/std/ts/typed/optional-chains.dx +317 -0
- package/std/ts/typed/promises.dx +205 -0
- package/std/ts/typed/qualifiers.dx +108 -0
- package/std/ts/typed/readonly-members.dx +159 -0
- package/std/ts/typed/readonly-parameters.dx +121 -0
- package/std/ts/typed/redundant-constituents.dx +171 -0
- package/std/ts/typed/regexp-exec.dx +79 -0
- package/std/ts/typed/rejection-handlers.dx +91 -0
- package/std/ts/typed/return-await.dx +116 -0
- package/std/ts/typed/return-this.dx +67 -0
- package/std/ts/typed/strict-void-return.dx +121 -0
- package/std/ts/typed/string-boundaries.dx +153 -0
- package/std/ts/typed/switches.dx +147 -0
- package/std/ts/typed/template-expressions.dx +127 -0
- package/std/ts/typed/template-values.dx +88 -0
- package/std/ts/typed/transfers.dx +106 -0
- package/std/ts/typed/type-arguments.dx +337 -0
- package/std/ts/typed/type-constituents.dx +143 -0
- package/std/ts/typed/type-conversions.dx +82 -0
- package/std/ts/typed/type-parameters.dx +280 -0
- package/std/ts/typed/unbound-method.dx +167 -0
- package/std/ts/typed/unsafe-calls.dx +73 -0
- package/std/ts/typed/unsafe-members.dx +36 -0
- package/std/ts/typed/void-expressions.dx +101 -0
- package/std/ts/typed.dx +585 -0
- package/std/ts/values/arguments.dx +13 -0
- package/std/ts/values/enums.dx +104 -0
- package/std/ts/values/inspection.dx +274 -0
- package/std/ts/values.dx +1217 -0
- package/std/ts.dx +77 -0
- package/std/whitespace.dx +37 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# Void-expression positions and source-preserving statement fixes.
|
|
2
|
+
import .ts/expression-fixes
|
|
3
|
+
|
|
4
|
+
define {
|
|
5
|
+
|
|
6
|
+
fn void_expression_like(n) =
|
|
7
|
+
if n is (ts_call, ts_tagged_template) then n.result could undefined && n.result always undefined
|
|
8
|
+
else n could undefined && n always undefined
|
|
9
|
+
fn void_expression_fixable(n) = {
|
|
10
|
+
value n
|
|
11
|
+
walk (current) {
|
|
12
|
+
value expression: unparenthesised_node(current)
|
|
13
|
+
value if expression is ts_conditional then [expression.consequent.node, expression.alternate.node]
|
|
14
|
+
else if expression is ts_logical then [expression.left.node, expression.right.node] else null
|
|
15
|
+
}
|
|
16
|
+
all (current) {
|
|
17
|
+
value expression: unparenthesised_node(current)
|
|
18
|
+
value if expression is ts_conditional then expression.consequent != null && expression.alternate != null
|
|
19
|
+
else if expression is ts_logical then expression.left != null && expression.right != null
|
|
20
|
+
else void_expression_like(expression)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
fn void_expression_annotation_void(n) = {
|
|
24
|
+
value arms: value_trait_parts(n, ["void", "parameter"])
|
|
25
|
+
value arms != null && any(arms, arm => any(arm.parts, part => contains(part.traits, "void")
|
|
26
|
+
&& !contains(part.uncertain_traits, "void") && !contains(part.traits, "parameter")))
|
|
27
|
+
}
|
|
28
|
+
fn void_expression_function(n) = {
|
|
29
|
+
value n
|
|
30
|
+
walk (current) current.parent.node
|
|
31
|
+
find (current) current is (ts_function, ts_arrow, ts_method)
|
|
32
|
+
}
|
|
33
|
+
fn void_expression_expected_void(n) = {
|
|
34
|
+
value direct: value_has_expected(n) && n.expected could callable && n.expected.result could void
|
|
35
|
+
value signatures: expected_call_signatures(n) ?? []
|
|
36
|
+
value headers: flat_map(signatures, arm => arm)
|
|
37
|
+
value signed: any(headers, header => header.result_known && any(header.result ?? [], arm => any(arm, part => contains(part.traits, "void"))))
|
|
38
|
+
value direct || signed
|
|
39
|
+
}
|
|
40
|
+
fn void_expression_void_returning(n) = n != null && (
|
|
41
|
+
if n.return_type != null then void_expression_annotation_void(n.return_type.node)
|
|
42
|
+
else (n is ts_arrow || n is ts_function && !expression_fix_declaration(n))
|
|
43
|
+
&& void_expression_expected_void(n))
|
|
44
|
+
fn void_expression_ancestor(n, arrows, operators) = {
|
|
45
|
+
value terminal: {
|
|
46
|
+
value n
|
|
47
|
+
walk (current) {
|
|
48
|
+
value p: current.parent.node
|
|
49
|
+
value if p is ts_parenthesized || p is ts_logical && p.right.offset == current.offset
|
|
50
|
+
|| p is ts_conditional && (p.consequent.offset == current.offset || p.alternate.offset == current.offset)
|
|
51
|
+
then p else null
|
|
52
|
+
}
|
|
53
|
+
last
|
|
54
|
+
}
|
|
55
|
+
value p: terminal.parent.node
|
|
56
|
+
value if p is ts_expression_statement
|
|
57
|
+
|| p is ts_sequence && terminal.index < count(p.expression) - 1
|
|
58
|
+
|| p is ts_arrow && arrows || p is ts_unary && p.operator == "void" && operators then null
|
|
59
|
+
else p
|
|
60
|
+
}
|
|
61
|
+
fn void_expression_final_return(n) = n.parent is ts_block
|
|
62
|
+
&& n.parent.parent is (ts_function, ts_arrow, ts_method)
|
|
63
|
+
&& last(n.parent.body.nodes).offset == n.offset
|
|
64
|
+
fn void_expression_return_text(n, final) = {
|
|
65
|
+
value argument: n.argument.node
|
|
66
|
+
value statement: (if any(["(", "[", "`"], token => starts_with(argument.text, token)) then ";" else "") argument.text ";" (if final then "" else " return;")
|
|
67
|
+
value if !final && n.parent not ts_block then "{{ " statement " }}" else statement
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
in ts_await, ts_call, ts_tagged_template rule es-no-confusing-void-expression {
|
|
71
|
+
option ignoreArrowShorthand boolean = false "Allow concise arrow bodies"
|
|
72
|
+
option ignoreVoidOperator boolean = false "Allow explicit void expressions"
|
|
73
|
+
option ignoreVoidReturningFunctions boolean = false "Allow explicitly or contextually void-returning functions"
|
|
74
|
+
let ancestor void_expression_ancestor(node, ignoreArrowShorthand, ignoreVoidOperator)
|
|
75
|
+
when ancestor != null
|
|
76
|
+
when void_expression_like(node)
|
|
77
|
+
let enclosing if ignoreVoidReturningFunctions then void_expression_function(ancestor) else null
|
|
78
|
+
when !ignoreVoidReturningFunctions || ancestor not (ts_arrow, ts_return)
|
|
79
|
+
|| !void_expression_void_returning(enclosing)
|
|
80
|
+
let final ancestor is ts_return && void_expression_final_return(ancestor)
|
|
81
|
+
let mode if ancestor is ts_arrow then if ignoreVoidOperator then "arrow-void" else "arrow"
|
|
82
|
+
else if ancestor is ts_return then if ignoreVoidOperator then "return-void" else if final then "last" else "return"
|
|
83
|
+
else if ignoreVoidOperator then "expression-void" else "expression"
|
|
84
|
+
let target if mode == "arrow" then ancestor.body.node
|
|
85
|
+
else if contains(["last", "return"], mode) then ancestor else node
|
|
86
|
+
let replacement if mode == "arrow" then if void_expression_fixable(target) then "{{ " target.structure_unwrapped.text "; }}" else null
|
|
87
|
+
else if mode == "last" then if void_expression_fixable(ancestor.argument.node) then void_expression_return_text(ancestor, true) else null
|
|
88
|
+
else if mode == "return" then if void_expression_fixable(ancestor.argument.node) then void_expression_return_text(ancestor, false) else null
|
|
89
|
+
else if contains(["arrow-void", "return-void"], mode) then "void " text
|
|
90
|
+
else null
|
|
91
|
+
warn if mode == "expression" then "Placing a void expression inside another expression is forbidden. Move it to its own statement instead."
|
|
92
|
+
else if mode == "arrow" then "Returning a void expression from an arrow function shorthand is forbidden. Please add braces to the arrow function."
|
|
93
|
+
else if mode == "last" then "Returning a void expression from a function is forbidden. Please remove the `return` statement."
|
|
94
|
+
else if mode == "return" then "Returning a void expression from a function is forbidden. Please move it before the `return` statement."
|
|
95
|
+
else if mode == "arrow-void" then "Void expressions returned from an arrow function shorthand must be marked explicitly with the `void` operator."
|
|
96
|
+
else if mode == "return-void" then "Void expressions returned from a function must be marked explicitly with the `void` operator."
|
|
97
|
+
else "Void expressions used inside another expression must be moved to its own statement or marked explicitly with the `void` operator."
|
|
98
|
+
fix at target if replacement != null && expression_fix_retains_comments(target, replacement) as replacement
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
}
|