@inthedark/dxlint 0.0.0-stage → 0.1.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 (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 +29 -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,10 @@
1
+ # .ts/selectors: open syntax policy; contextual exclusions use ordinary rules.
2
+ define {
3
+
4
+ group restricted_syntax
5
+
6
+ in restricted_syntax rule es-no-restricted-syntax {
7
+ warn "This syntax is not allowed."
8
+ }
9
+
10
+ }
@@ -0,0 +1,97 @@
1
+ # Spread policy over constrained constituent types and declaration provenance.
2
+
3
+ import .ts/type-specifiers
4
+
5
+ define {
6
+
7
+ fn spread_string(n) = ts_value_has_trait(n, "string") == true
8
+ fn spread_declared_contract(n) = {
9
+ value roots: value_sources(n)
10
+ value sites: walk(roots.sites ?? [], site => site_sources(n, site).sites ?? [])
11
+ value any(sites, site => site.kind == "ts_declarator" && count(site_field(n, site, "type") ?? []) > 0)
12
+ }
13
+ fn spread_written_properties(n) = {
14
+ value binding: name_binding(n)
15
+ value if binding == null then if n is (ts_function, ts_arrow) then false else null
16
+ else if spread_declared_contract(n) then false
17
+ else any(binding.references, reference => reference.parent is (ts_member, ts_index)
18
+ && reference.parent.object.node == reference && reference.parent.write_site != null)
19
+ }
20
+ fn spread_class_value(n, arms) = {
21
+ value roots: value_sources(n)
22
+ value sites: walk(roots.sites ?? [], site => site_sources(n, site).sites ?? [])
23
+ value any(arms, arm => any(arm.parts, part => contains(part.traits, "constructible")))
24
+ && (n is (ts_class, ts_instantiation) || any(sites, site => contains(["ts_class", "ts_instantiation"], site.kind)))
25
+ }
26
+ fn spread_global_instance(n, carrier) = if carrier.description.name == null then false else {
27
+ value types: global_declarations(n, carrier.description.name, "type")
28
+ value constructors: if types == null || !contains(types, {file: carrier.file, node: carrier.node}) then [] else
29
+ global_declarations(n, carrier.description.name, "value")
30
+ value any(constructors ?? [], constructor =>
31
+ any(value_constructors(declaration_value(n, constructor)) ?? [], headers =>
32
+ any(headers, signature => any(value_parts(signature.result) ?? [], arm =>
33
+ any(arm.parts, part => part.carrier.file == carrier.file && part.carrier.node == carrier.node)))))
34
+ }
35
+ fn spread_class_instance(n, arms) = any(arms, arm => any(arm.parts, part => {
36
+ value carrier: part.carrier
37
+ value if contains(part.traits, "constructible") || carrier.description.kind != "named" then false else {
38
+ value headers: value_constructors(declaration_value(n, {file: carrier.file, node: carrier.node}))
39
+ value headers != null && any(headers, signatures => count(signatures) > 0)
40
+ || spread_global_instance(n, carrier)
41
+ }
42
+ }))
43
+ fn spread_iterable(n, arms) = {
44
+ value key: ts_value_symbol_key(n, "iterator")
45
+ value key != null && any(arms, arm => {
46
+ value member: value_lookup(arm.handle, key)
47
+ value signatures: if member.member == null then null else value_signatures(member.member)
48
+ value member.alternatives != null && count(member.alternatives) > 0
49
+ && all(member.alternatives, alternative => alternative.matched)
50
+ && signatures != null && count(signatures) > 0 && all(signatures, headers => count(headers) > 0)
51
+ })
52
+ }
53
+ fn spread_builtin_type(n, arms, names) = any(arms, arm =>
54
+ any(arm.parts, part => ts_value_builtin_ancestor(part, n, names) == true))
55
+ fn spread_object_category(n) = {
56
+ value arms: value_parts(n)
57
+ value if arms == null then null
58
+ else if spread_builtin_type(n, arms, ["Promise"]) then "promise"
59
+ else if spread_written_properties(n) != true && any(arms, arm => {
60
+ value signatures: value_signatures(arm.handle)
61
+ value signatures != null && any(signatures, headers => count(headers) > 0)
62
+ && value_children(arm.handle, true, []) == []
63
+ }) then "function"
64
+ else if spread_builtin_type(n, arms, ["Map", "ReadonlyMap", "WeakMap"]) then "map"
65
+ else if any(arms, arm => any(arm.parts, part => contains(["array", "tuple"], part.carrier.description.kind))) then "array"
66
+ else if !spread_string(n) && spread_iterable(n, arms) then "iterable"
67
+ else if spread_class_instance(n, arms) then "instance"
68
+ else if spread_class_value(n, arms) then "class" else null
69
+ }
70
+ in ts_spread, ts_jsx_spread_attribute let no_misused_spread_checked true
71
+ in ts_spread, ts_jsx_spread_attribute rule es-no-misused-spread {
72
+ option allow (string | type_specifier_file | type_specifier_lib | type_specifier_package)[] = [] "types safe to spread"
73
+ let object_spread node is ts_jsx_spread_attribute || parent is ts_object
74
+ let sequence_spread parent is (ts_array, ts_call)
75
+ when object_spread || sequence_spread
76
+ let subject argument.node
77
+ when type_value_allowed(allow, subject) != true
78
+ let category if object_spread then spread_object_category(subject) else if spread_string(subject) then "string" else null
79
+ when category != null
80
+ when no_misused_spread_checked
81
+ warn if category == "promise" then "Using the spread operator on Promise in an object can cause unexpected behavior. Did you forget to await the promise?"
82
+ else if category == "function" then "Using the spread operator on a function without additional properties can cause unexpected behavior. Did you forget to call the function?"
83
+ else if category == "map" then "Using the spread operator on a Map in an object will result in an empty object. Did you mean to use `Object.fromEntries(map)` instead?"
84
+ else if category == "array" then "Using the spread operator on an array in an object will result in a list of indices."
85
+ else if category == "iterable" then "Using the spread operator on an Iterable in an object can cause unexpected behavior."
86
+ else if category == "instance" then "Using the spread operator on class instances will lose their class prototype."
87
+ else if category == "class" then "Using the spread operator on class declarations will spread only their static properties, and will lose their class prototype."
88
+ else """
89
+ Using the spread operator on a string can mishandle special characters, as can `.split("")`.
90
+ - `...` produces Unicode code points, which will decompose complex emojis into individual emojis
91
+ - .split("") produces UTF-16 code units, which breaks rich characters in many languages
92
+ Consider using `Intl.Segmenter` for locale-aware string decomposition.
93
+ Otherwise, if you don't need to preserve emojis or other non-Ascii characters, disable this lint rule on this line or configure the 'allow' rule option.
94
+ """
95
+ }
96
+
97
+ }
@@ -0,0 +1,52 @@
1
+ define {
2
+
3
+ group structure_function_scope ts_program, ts_function, ts_arrow, ts_method, ts_static_block
4
+ group structure_lexical_scope structure_function_scope, ts_block, ts_for, ts_for_in, ts_for_of, ts_switch
5
+ fn structure_declaration_scope(n) = {
6
+ value hoisted: n.kind.text == "var"
7
+ value walk(n.parent.node, current => current.parent.node)
8
+ find (current) if hoisted then current is structure_function_scope else current is structure_lexical_scope
9
+ }
10
+ fn structure_declaration_counts(n) = {
11
+ initialized: count(filter(n.declaration.nodes, item => item.init.node != null)),
12
+ uninitialized: count(filter(n.declaration.nodes, item => item.init.node == null)),
13
+ requires: count(filter(n.declaration.nodes, item => item.init is ts_call
14
+ && item.init.callee is ts_identifier && item.init.callee.text == "require")),
15
+ }
16
+ fn structure_declaration_previous(n) = {
17
+ value body: n.parent.body.nodes
18
+ value previous: if !contains(body, n) then null else last(filter(body, item => item.offset < n.offset))
19
+ value if previous is ts_variable_declaration && previous.kind.text == n.kind.text
20
+ then structure_declaration_counts(previous) else null
21
+ }
22
+ fn structure_declaration_entry(n, counts, prior) = {
23
+ node: n,
24
+ kind: n.kind.text,
25
+ counts: counts,
26
+ prior: prior,
27
+ for_init: n is ts_for.init,
28
+ for_binding: n.parent is (ts_for_in, ts_for_of),
29
+ }
30
+ fn structure_declaration_group(entries) = {
31
+ value entries
32
+ fold ({ counts: {initialized: 0, uninitialized: 0, requires: 0}, entries: [] }) (state, n) {
33
+ value counts: structure_declaration_counts(n)
34
+ value {
35
+ counts: {
36
+ initialized: state.counts.initialized + counts.initialized,
37
+ uninitialized: state.counts.uninitialized + counts.uninitialized,
38
+ requires: state.counts.requires + counts.requires,
39
+ },
40
+ entries: state.entries [structure_declaration_entry(n, counts, state.counts)],
41
+ }
42
+ }
43
+ }
44
+ in structure_lexical_scope let structure_declaration_entries {
45
+ value owner: node
46
+ value descendants(ts_variable_declaration)
47
+ filter (item) structure_declaration_scope(item) == owner
48
+ sort_by (item) item.offset
49
+ group_by (item) item.kind.text
50
+ flat_map (group) structure_declaration_group(group.items).entries
51
+ }
52
+ }
@@ -0,0 +1,79 @@
1
+ import .ts/helpers
2
+ import .ts/tokens
3
+
4
+ define {
5
+
6
+ in ts_program let bom starts_with(source, "\u{feff}")
7
+
8
+ group structure_operand ts_binary, ts_logical, ts_union, ts_intersection
9
+ fn structure_operand_line(source, at) = {
10
+ value line: position(at)
11
+ value {
12
+ row: line.js_line,
13
+ offset: line.js_line_start,
14
+ indent: re_find(byte_slice(source, line.js_line_start), /^[^\S\r\n\u{2028}\u{2029}]*/),
15
+ node: first(overlapping(ts_line, at, at + 1)),
16
+ }
17
+ }
18
+ fn structure_operand_start(right) = {
19
+ value inner: unparenthesised_node(right)
20
+ value before: token(inner, "before")
21
+ value parens: walk(if before.text == "(" then ts_token_node(before) else null, current => {
22
+ value previous: token(current, "before")
23
+ value if previous.text == "(" && token(ts_token_node(previous), "before") != null
24
+ then ts_token_node(previous) else null
25
+ })
26
+ value {
27
+ first: if count(parens) > 0 then token(last(parens), "first") else token(inner, "first"),
28
+ before: if count(parens) > 0 then token(last(parens), "before") else before,
29
+ climbed: count(parens) > 0,
30
+ }
31
+ }
32
+ fn structure_operand_measure(source, n, right, member) = {
33
+ value start: structure_operand_start(right)
34
+ value first: start.first
35
+ value operator: if n is (ts_binary, ts_logical) then token(n.operator.node, "first")
36
+ else start.before
37
+ value left: token(ts_token_node(operator), "before")
38
+ value type_member: n is (ts_union, ts_intersection)
39
+ value if first == null || left == null
40
+ || operator.start <= n.offset && !(type_member && member == 0 && !start.climbed)
41
+ || position(left.start).js_line == position(first.start).js_line then null else {
42
+ value left_line: structure_operand_line(source, left.start)
43
+ value right_line: structure_operand_line(source, first.start)
44
+ value root_line: structure_operand_line(source, n.offset)
45
+ value first_on_line: token(left_line.node, "first") ?? left
46
+ value line_last: token(left_line.node, "last")
47
+ value last_on_line: if line_last == null || left.start > line_last.start then left else line_last
48
+ value before: token(n, "before")
49
+ value {
50
+ offset: right_line.offset,
51
+ left_line: left_line.row,
52
+ right_line: right_line.row,
53
+ root_line: root_line.row,
54
+ left: left_line.indent,
55
+ right: right_line.indent,
56
+ root: root_line.indent,
57
+ first: first_on_line.text,
58
+ last: last_on_line.text,
59
+ before: if before != null && position(before.start).js_line == left_line.row then before.text else "",
60
+ parens: sum(map(token_list(left_line.node), text => if text == "(" then 1 else if text == ")" then -1 else 0)),
61
+ type_keyword: first_on_line.text == "type" && any(walk(n.parent.node, current => current.parent.node),
62
+ current => current is ts_type_alias && current.offset == first_on_line.start),
63
+ }
64
+ }
65
+ }
66
+ in structure_operand let structure_operand_records {
67
+ value owner: node
68
+ value if position(offset).js_line == position(end_offset).js_line then [] else {
69
+ value if is (ts_binary, ts_logical) then right.nodes else type.nodes
70
+ map (item, index) structure_operand_measure(source, owner, item, index)
71
+ compact
72
+ }
73
+ }
74
+ in ts_program let binary_operand_indents {
75
+ value descendants(structure_operand)
76
+ flat_map (item) item.structure_operand_records
77
+ }
78
+
79
+ }
@@ -0,0 +1,144 @@
1
+ import .core/lists
2
+ import .ts/layout/shared
3
+ import .ts/tokens
4
+
5
+ define {
6
+
7
+ group structure_list_open_token ts_open_paren, ts_open_bracket, ts_open_brace, ts_open_angle
8
+ in ts_node let structure_list_main null
9
+ in ts_array let structure_list_main {kind: "ArrayExpression", brackets: "[]", items: element.nodes}
10
+ in ts_array_pattern let structure_list_main {kind: "ArrayPattern", brackets: "[]", items: element.nodes}
11
+ in ts_object let structure_list_main {kind: "ObjectExpression", brackets: "{{}}", items: property.nodes}
12
+ in ts_object_pattern let structure_list_main {kind: "ObjectPattern", brackets: "{{}}", items: property.nodes rest.nodes}
13
+ in ts_function let structure_list_main {
14
+ kind: if parent is (ts_program, ts_block, ts_export) then "FunctionDeclaration" else "FunctionExpression",
15
+ brackets: "()", items: parameter.nodes,
16
+ }
17
+ in ts_arrow let structure_list_main {kind: "ArrowFunctionExpression", brackets: "()", items: parameter.nodes}
18
+ in ts_call let structure_list_main {kind: "CallExpression", brackets: "()", items: argument.nodes}
19
+ in ts_new let structure_list_main {kind: "NewExpression", brackets: "()", items: argument.nodes}
20
+ in ts_if let structure_list_main {kind: "IfStatement", brackets: "()", items: test.nodes}
21
+ in ts_import let structure_list_main {kind: "ImportDeclaration", brackets: "{{}}", items: specifier.nodes}
22
+ in ts_export let structure_list_main if declaration.node == null then {kind: "ExportNamedDeclaration", brackets: "{{}}", items: specifier.nodes} else null
23
+ in ts_enum let structure_list_main {kind: "TSEnumBody", brackets: "{{}}", items: member.nodes}
24
+ in ts_function_type let structure_list_main {kind: "TSFunctionType", brackets: "()", items: parameter.nodes}
25
+ in ts_interface let structure_list_main {kind: "TSInterfaceBody", brackets: "{{}}", items: member.nodes}
26
+ in ts_type_literal let structure_list_main {kind: "TSTypeLiteral", brackets: "{{}}", items: member.nodes}
27
+ in ts_tuple_type let structure_list_main {kind: "TSTupleType", brackets: "[]", items: element.nodes}
28
+ fn structure_list_groups(n) = {
29
+ value main: n.structure_list_main
30
+ value (if main == null then [] else [main]) {
31
+ value n.layout_syntax_lists
32
+ filter (list) contains(["type_parameter", "type_argument"], list.field)
33
+ map (list) {
34
+ kind: if list.field == "type_parameter" then "TSTypeParameterDeclaration" else "TSTypeParameterInstantiation",
35
+ brackets: "<>", items: list.items,
36
+ }
37
+ }
38
+ }
39
+ fn structure_list_comment(n) = {
40
+ start: n.offset, end: n.end_offset,
41
+ text: if starts_with(n.text, "/*") then byte_slice(n.text, 2, byte_len(n.text) - 2) else byte_slice(n.text, 2),
42
+ }
43
+ fn structure_list_comments(start, end) = {
44
+ value overlapping(ts_comment, start, end)
45
+ filter (item) item.offset >= start && item.end_offset <= end
46
+ sort_by (item) item.offset
47
+ }
48
+ fn structure_list_first(code, comments) = {
49
+ value comment: first(comments)
50
+ value if comment != null && (code == null || comment.offset < code.start)
51
+ then structure_list_comment(comment) else code
52
+ }
53
+ fn structure_list_last(code, comments) = {
54
+ value comment: last(comments)
55
+ value if comment != null && (code == null || comment.offset > code.start)
56
+ then structure_list_comment(comment) else code
57
+ }
58
+ fn structure_list_open(n, group, items) = {
59
+ value open: byte_slice(group.brackets, 0, 1)
60
+ value close: byte_slice(group.brackets, 1)
61
+ value first: first(items)
62
+ value prefix_end: if count(items) > 0 then unparenthesised_node(first).offset else n.body.offset ?? n.end_offset
63
+ value candidates: {
64
+ value overlapping(structure_list_open_token, n.offset, prefix_end)
65
+ filter (item) item.offset >= n.offset && item.end_offset <= prefix_end && item.text == open
66
+ sort_by (item) item.offset
67
+ }
68
+ value selected: if group.brackets == "()" && n is (ts_call, ts_new) then {
69
+ value after: last(n.type_argument.nodes).end_offset ?? n.callee.end_offset ?? n.offset
70
+ value find(candidates, item => item.offset >= after)
71
+ } else if count(items) > 0 then {
72
+ value edge: token(unparenthesised_node(first), "before")
73
+ value if edge.text == open then ts_token_node(edge) else null
74
+ } else find(candidates, item => token(item, "after").text == close)
75
+ value if selected != null then token(selected, "first") else null
76
+ }
77
+ fn structure_list_close(n, group, items, left) = {
78
+ value after: if count(items) == 0 then token(ts_token_node(left), "after") else token(last(items), "after")
79
+ value chain: walk(ts_token_node(after), current =>
80
+ if token(current, "first").text == "," then ts_token_node(token(current, "after")) else null)
81
+ value right: token(last(chain), "first")
82
+ value if right.text == byte_slice(group.brackets, 1) && right.end <= n.end_offset then right else null
83
+ }
84
+ fn structure_list_wrap(items, left, after_open) = {
85
+ value items
86
+ map (item, index) {node: item, index: index}
87
+ fold ({previous: left.end, edge: left, pairs: [[left, after_open]]}) (state, entry) {
88
+ value item: entry.node
89
+ value first: token(unparenthesised_node(item), "first")
90
+ value previous: token(item, "last")
91
+ value before: if first == null then null else {
92
+ value chain: walk(ts_token_node(token(unparenthesised_node(item), "before")), current =>
93
+ if current.offset >= state.previous && token(current, "first").text == "("
94
+ then ts_token_node(token(current, "before")) else null)
95
+ value edge: token(last(chain), "first")
96
+ value if edge.start >= state.previous then edge else state.edge
97
+ }
98
+ value {
99
+ previous: item.end_offset,
100
+ edge: previous ?? state.edge,
101
+ pairs: state.pairs (if first == null || entry.index == 0 && after_open.start == first.start then [] else [[before, first]]),
102
+ }
103
+ }
104
+ }
105
+ fn structure_list_sites(source, n, group) = {
106
+ value items: {value group.items; sort_by (item) item.offset}
107
+ value left: structure_list_open(n, group, items)
108
+ value right: if left == null then null else structure_list_close(n, group, items, left)
109
+ value if right == null then [] else {
110
+ value first_item: find(items, item => item not ts_hole)
111
+ value first_start: if first_item == null then right.start else unparenthesised_node(first_item).offset
112
+ value last_end: last(items).end_offset ?? left.end
113
+ value after_open: token(ts_token_node(left), "after")
114
+ value before_close: token(ts_token_node(right), "before")
115
+ value first_edge: structure_list_first(
116
+ if after_open.start <= first_start then after_open else token(unparenthesised_node(first_item), "first"),
117
+ structure_list_comments(left.end, first_start)) ?? right
118
+ value last_edge: structure_list_last(
119
+ if before_close.start >= last_end then before_close else token(last(items), "last"),
120
+ structure_list_comments(last_end, right.start)) ?? left
121
+ value spacing: [[left, first_edge]] (if first_edge.start == right.start then [] else [[last_edge, right]])
122
+ value wrapping: if count(items) == 0 then spacing else
123
+ structure_list_wrap(items, left, after_open).pairs [[before_close ?? left, right]]
124
+ value context: {
125
+ kind: group.kind, brackets: group.brackets, count: count(items),
126
+ single: layout_same_line(byte_slice(source, left.start, right.end)),
127
+ node_single: layout_same_line(n.text),
128
+ first_broken: count(items) > 0 && !layout_same_line(byte_slice(source, left.end, unparenthesised_node(first(items)).offset)),
129
+ empty_comments: first_edge.start != right.start,
130
+ }
131
+ value comments: structure_list_comments(left.end, right.start)
132
+ value spacing_sites: map(spacing, pair => core_list_site(source, context, "spacing", first(pair), last(pair), comments))
133
+ value wrapping_sites: map(wrapping, pair => core_list_site(source, context,
134
+ if count(items) == 0 then "empty_wrapping" else "wrapping", first(pair), last(pair), comments))
135
+ value spacing_sites wrapping_sites
136
+ }
137
+ }
138
+ in ts_node let list_layout {
139
+ value owner: node
140
+ value structure_list_groups(owner)
141
+ flat_map (group) structure_list_sites(source, owner, group)
142
+ }
143
+
144
+ }
@@ -0,0 +1,258 @@
1
+ # Statement padding policies, comment-separated gaps and whitespace fixes.
2
+ import .ts/parentheses
3
+ import .ts/helpers
4
+
5
+ define {
6
+
7
+ fn padding_prepare_selectors(selectors) = {
8
+ value choices: if type_of(selectors) == "list" then selectors else [selectors]
9
+ value if contains(choices, "*") then { wildcard: true } else {
10
+ wildcard: false, names: choices,
11
+ special: any(choices, selector => type_of(selector) != "str" || contains([
12
+ "block-like", "multiline-block-like", "singleline-block-like", "require", "cjs-import", "iife", "cjs-export", "exports",
13
+ ], selector)),
14
+ block_like: contains(choices, "block-like"),
15
+ multiline_block_like: contains(choices, "multiline-block-like"),
16
+ singleline_block_like: contains(choices, "singleline-block-like"),
17
+ require: contains(choices, "require"),
18
+ cjs_import: contains(choices, "cjs-import"),
19
+ iife: contains(choices, "iife"),
20
+ cjs_export: contains(choices, "cjs-export"),
21
+ exports: contains(choices, "exports"),
22
+ records: map(filter(choices, selector => type_of(selector) != "str"), selector => {
23
+ selector: re_replace(selector.selector, /["']/, ""),
24
+ lineMode: selector.lineMode.nonempty ?? "any",
25
+ }),
26
+ }
27
+ }
28
+ fn padding_record_selector_matches(item, selector) =
29
+ contains(item.structure_padding_selectors.nonempty ?? [item.structure_padding_type], selector.selector)
30
+ && (selector.lineMode == "any"
31
+ || selector.lineMode == "multiline" && item.structure_padding_multiline
32
+ || selector.lineMode == "singleline" && !item.structure_padding_multiline)
33
+ fn padding_side_matches(item, selectors) = {
34
+ value if selectors.wildcard then true else if len(selectors.names) == 0 then false else {
35
+ value categories: item.structure_padding_categories
36
+ value any(categories.structure_padding_names, name => contains(selectors.names, name))
37
+ || selectors.special && (selectors.block_like && categories.structure_padding_block_like
38
+ || selectors.multiline_block_like && categories.structure_padding_multiline && categories.structure_padding_block_like
39
+ || selectors.singleline_block_like && !categories.structure_padding_multiline && categories.structure_padding_block_like
40
+ || selectors.require && categories.structure_padding_require
41
+ || selectors.cjs_import && categories.structure_padding_cjs_import
42
+ || selectors.iife && categories.structure_padding_iife
43
+ || selectors.cjs_export && categories.structure_padding_cjs_export
44
+ || selectors.exports && categories.structure_padding_exports_tag
45
+ || any(selectors.records, selector => padding_record_selector_matches(categories, selector)))
46
+ }
47
+ }
48
+
49
+ group structure_padding_owner ts_program, ts_block, ts_static_block, ts_case, ts_switch, ts_interface, ts_type_literal
50
+ group structure_padding_block ts_block, ts_switch
51
+ in ts_program, ts_block, ts_static_block, ts_case let structure_padding_items body.node
52
+ in ts_switch let structure_padding_items case.node
53
+ in ts_interface, ts_type_literal let structure_padding_items filter(member.node, item => !(item is (ts_property_signature, ts_index_signature)))
54
+ in structure_padding_owner let structure_padding_first_non_directive find(structure_padding_items, item => !item.structure_padding_directive)
55
+ in ts_expression_statement let structure_padding_directive expression is ts_string
56
+ && (parent is ts_program || parent is ts_block && parent.parent is (ts_function, ts_arrow, ts_method))
57
+ in ts_labeled let structure_padding_unlabel body.structure_padding_unlabel.nonempty ?? body.node
58
+ in ts_sequence let structure_padding_sequence { value (last(expression.node)).structure_padding_sequence; nonempty } ?? (last(expression.node)).structure_unwrapped
59
+ in ts_parenthesized let structure_padding_sequence expression.structure_padding_sequence.nonempty ?? expression.structure_unwrapped
60
+ in ts_unary let structure_padding_iife_expression argument.structure_unwrapped
61
+ in ts_parenthesized let structure_padding_iife_expression expression.structure_padding_iife_expression
62
+ in ts_expression_statement let structure_padding_iife {
63
+ value expression.structure_padding_iife_expression.nonempty ?? expression.structure_unwrapped
64
+ structure_padding_is_iife
65
+ }
66
+ fn structure_padding_is_iife(n) = (n.callee.structure_padding_sequence.nonempty ?? n.callee.structure_unwrapped) is (ts_function, ts_arrow)
67
+ in ts_member, ts_index let structure_padding_receiver object.structure_padding_receiver.nonempty ?? object.structure_unwrapped
68
+ in ts_parenthesized let structure_padding_receiver expression.structure_padding_receiver.nonempty ?? expression.structure_unwrapped
69
+ in ts_member, ts_index let structure_padding_exports
70
+ if object is ts_identifier then object.text == "exports" || object.text == "module" && node.property == "exports"
71
+ else object.structure_unwrapped.structure_padding_exports
72
+ in ts_parenthesized let structure_padding_exports expression.structure_padding_exports
73
+ in ts_function let structure_padding_declaration_type if body == null then "TSDeclareFunction" else "FunctionDeclaration"
74
+ in ts_class let structure_padding_declaration_type "ClassDeclaration"
75
+ in ts_variable_declaration let structure_padding_declaration_type "VariableDeclaration"
76
+ in ts_interface let structure_padding_declaration_type "TSInterfaceDeclaration"
77
+ in ts_type_alias let structure_padding_declaration_type "TSTypeAliasDeclaration"
78
+ in ts_enum let structure_padding_declaration_type "TSEnumDeclaration"
79
+ in ts_node let structure_padding_keyword first_token.text
80
+ in ts_break let structure_padding_keyword_tag ["break", "BreakStatement"]
81
+ in ts_case let structure_padding_keyword_tag [if test != null then "case" else "default", "SwitchCase"]
82
+ in ts_class let structure_padding_keyword_tag ["class", "ClassDeclaration"]
83
+ in ts_continue let structure_padding_keyword_tag ["continue", "ContinueStatement"]
84
+ in ts_debugger let structure_padding_keyword_tag ["debugger", "DebuggerStatement"]
85
+ in ts_do_while let structure_padding_keyword_tag ["do", "DoWhileStatement"]
86
+ in ts_for, ts_for_in, ts_for_of let structure_padding_keyword_tag ["for", "ForStatement"]
87
+ in ts_if let structure_padding_keyword_tag ["if", "IfStatement"]
88
+ in ts_import let structure_padding_keyword_tag ["import", "ImportDeclaration"]
89
+ in ts_switch let structure_padding_keyword_tag ["switch", "SwitchStatement"]
90
+ in ts_throw let structure_padding_keyword_tag ["throw", "ThrowStatement"]
91
+ in ts_try let structure_padding_keyword_tag ["try", "TryStatement"]
92
+ in ts_while let structure_padding_keyword_tag ["while", "WhileStatement"]
93
+ in ts_with let structure_padding_keyword_tag ["with", "WithStatement"]
94
+ in ts_enum let structure_padding_keyword_tag ["enum", "TSEnumDeclaration"]
95
+ in ts_interface let structure_padding_keyword_tag ["interface", "TSInterfaceDeclaration"]
96
+ in ts_node let structure_padding_type structure_padding_node_type(node)
97
+ fn structure_padding_node_type(n) = when {
98
+ n is ts_block then "BlockStatement"
99
+ n is ts_empty then "EmptyStatement"
100
+ n is ts_method_signature then "TSMethodSignature"
101
+ n is ts_expression_statement then "ExpressionStatement"
102
+ n is ts_return then "ReturnStatement"
103
+ n is ts_export then when {
104
+ n.kind == "default" then "ExportDefaultDeclaration"
105
+ n.operator == "*" then "ExportAllDeclaration"
106
+ else then "ExportNamedDeclaration"
107
+ }
108
+ else then { value n.structure_padding_keyword_tag; last; nonempty } ?? n.structure_padding_declaration_type.nonempty ?? ""
109
+ }
110
+ in ts_block let structure_padding_plain_tag "block"
111
+ in ts_empty let structure_padding_plain_tag "empty"
112
+ in ts_method_signature let structure_padding_plain_tag "ts-method"
113
+ in ts_function let structure_padding_plain_tag if body == null then "function-overload" else "function"
114
+ in ts_expression_statement let structure_padding_plain_tag if structure_padding_directive && (parent.structure_padding_first_non_directive == null || offset < (parent.structure_padding_first_non_directive).offset) then "directive" else null
115
+ in ts_expression_statement let structure_padding_sized_tag if structure_padding_plain_tag == "directive" then null else "expression"
116
+ in ts_variable_declaration let structure_padding_sized_tag when {
117
+ contains(["var", "let", "const"], structure_padding_keyword) then structure_padding_keyword
118
+ contains(["using", "await using"], kind) then "using"
119
+ else then null
120
+ }
121
+ in ts_export let structure_padding_sized_tag if structure_padding_keyword == "export" then "export" else null
122
+ in ts_type_alias let structure_padding_sized_tag if structure_padding_keyword == "type" then "type" else null
123
+ in ts_return let structure_padding_sized_tag if structure_padding_keyword == "return" then "return" else null
124
+ in ts_node let structure_padding_names {
125
+ value plain: structure_padding_plain_tag
126
+ value keyword: first(structure_padding_keyword_tag)
127
+ value sized: structure_padding_sized_tag
128
+ value [
129
+ plain,
130
+ if keyword != null && structure_padding_keyword == keyword then keyword else null,
131
+ sized,
132
+ if sized != null then (if structure_padding_multiline then "multiline-" else "singleline-") sized else null,
133
+ ]
134
+ compact
135
+ }
136
+ in ts_declarator let structure_padding_init init.node
137
+ in ts_variable_declaration let structure_padding_first_init first(declaration.structure_padding_init)
138
+ in ts_variable_declaration let structure_padding_require { value structure_padding_first_init; structure_padding_receiver; structure_padding_is_require }
139
+ in ts_variable_declaration let structure_padding_cjs_import starts_with(structure_padding_first_init.text, "require(")
140
+ in ts_expression_statement let structure_padding_cjs_export expression.structure_unwrapped is ts_assignment
141
+ && { value expression.structure_unwrapped.left.text; re_replace /\s/ ""; re_test /^(?:module\.)?exports(?:$|[.\[])/ }
142
+ in ts_expression_statement let structure_padding_exports_tag expression.structure_unwrapped is ts_assignment
143
+ && expression.structure_unwrapped.left.structure_padding_exports
144
+ in ts_function let structure_padding_selectors { value [if name != null then structure_padding_type "[id.name=" name "]" else null, structure_padding_type]; compact }
145
+ in ts_export let structure_padding_selectors {
146
+ value [if declaration != null then structure_padding_type "[declaration.type=" (declaration.structure_padding_declaration_type.nonempty ?? "") "]" else null, structure_padding_type]
147
+ compact
148
+ }
149
+ in ts_expression_statement let structure_padding_selectors {
150
+ value [if expression.structure_unwrapped.callee is ts_identifier then "ExpressionStatement[expression.callee.name=" expression.structure_unwrapped.callee.text "]" else null, structure_padding_type]
151
+ compact
152
+ }
153
+ in ts_node let structure_padding_trimmed {
154
+ value text
155
+ trim_end
156
+ re_replace /;+$/ ""
157
+ trim_end
158
+ }
159
+ in ts_node let structure_padding_block_like structure_padding_iife
160
+ || is ts_do_while && node.body is ts_block
161
+ || { value result: "}}"; value ends_with(structure_padding_trimmed, result) } && (is structure_padding_block && end_offset == offset + byte_len(structure_padding_trimmed)
162
+ || {
163
+ value result_2: offset + byte_len(structure_padding_trimmed) - 1
164
+ value result_3: offset + byte_len(structure_padding_trimmed)
165
+ value overlapping(structure_padding_block, result_2, result_3)
166
+ any (block) block.end_offset == offset + byte_len(structure_padding_trimmed)
167
+ })
168
+ in ts_node let structure_padding_categories structure_padding_unlabel.nonempty ?? node
169
+ in ts_node let structure_padding_multiline position(offset).js_line != position(end_offset).js_line
170
+ fn structure_padding_receiver(n) = n.structure_padding_receiver.nonempty ?? n.structure_unwrapped
171
+ fn structure_padding_is_require(n) = n.callee is ts_identifier && n.callee.text == "require"
172
+ fn structure_padding_blank(text) = { value text; replace "\r\n" "\n"; re_test /[\n\r\u2028\u2029]\s*[\n\r\u2028\u2029]/ }
173
+ fn structure_padding_gap_end(previous, next, source) = {
174
+ value end: if previous is ts_method_signature then previous.member_terminal_token.end else previous.end_offset
175
+ value semicolon: if previous is ts_method_signature then previous.member_terminal_token.text == ";" else ends_with(previous.text, ";")
176
+ value when {
177
+ !semicolon then end
178
+ { value source; byte_slice (end - 1) next.offset; re_test /[\n\r\u2028\u2029]/ } then end
179
+ else then {
180
+ value trimmed_end: { value source; byte_slice previous.offset (end - 1); trim_end; byte_len } + previous.offset
181
+ value if { value source; byte_slice trimmed_end (end - 1); re_test /[\n\r\u2028\u2029]/ }
182
+ then trimmed_end else end
183
+ }
184
+ }
185
+ }
186
+
187
+ fn structure_padding_segments(end, start, comments) = {
188
+ value left: [end] map(comments, comment => comment.end_offset)
189
+ value right: map(comments, comment => comment.offset) [start]
190
+ value zip(left, right)
191
+ map (segment) { start: first(segment), end: last(segment) }
192
+ }
193
+ fn structure_padding_remove(source, segment) = {
194
+ value byte_slice(source, segment.start, segment.end)
195
+ re_replace /^(\s*?(?:\r\n|[\n\r\u2028\u2029]))\s*(?:\r\n|[\n\r\u2028\u2029])(\s*;?)$/ "$1$2"
196
+ }
197
+ fn structure_padding_insert(source, end, start, comments) = {
198
+ value attached: fold(comments, end, (prior, comment) => if comment.offset >= prior && !{ value source; byte_slice prior comment.offset; re_test /[\n\r\u2028\u2029]/ } then comment.end_offset else prior)
199
+ value following: { value comments; filter (comment) comment.offset >= attached; first; get "offset" } ?? start
200
+ value { start: attached, end: attached, text: if { value source; byte_slice attached following; re_test /[\n\r\u2028\u2029]/ } then "\n" else "\n\n" }
201
+ }
202
+ fn structure_padding_finding(source, pair, comments) = {
203
+ value padded: if len(comments) == 0
204
+ then if structure_padding_blank(byte_slice(source, pair.end, pair.start)) then [{start: pair.end, end: pair.start}] else []
205
+ else filter(structure_padding_segments(pair.end, pair.start, comments),
206
+ segment => structure_padding_blank(byte_slice(source, segment.start, segment.end)))
207
+ value if pair.policy == "always" && len(padded) > 0 || pair.policy == "never" && len(padded) == 0 then null
208
+ else {
209
+ value edit: if pair.policy == "always" then structure_padding_insert(source, pair.end, pair.start, comments) else first(padded)
210
+ value {
211
+ offset: pair.start, policy: pair.policy,
212
+ edit: edit, replacement: when {
213
+ pair.policy == "always" then edit.text
214
+ len(padded) == 1 then structure_padding_remove(source, edit)
215
+ else then null
216
+ }
217
+ }
218
+ }
219
+ }
220
+
221
+ in structure_padding_owner rule es-padding-line-between-statements {
222
+ option options { blankLine: "any" | "always" | "never"; prev: string | { selector: string; lineMode?: "any" | "singleline" | "multiline" } | (string | { selector: string; lineMode?: "any" | "singleline" | "multiline" })[]; next: string | { selector: string; lineMode?: "any" | "singleline" | "multiline" } | (string | { selector: string; lineMode?: "any" | "singleline" | "multiline" })[] }[] = [] "ordered statement padding policies"
223
+ when any(options, policy => policy.blankLine != "any")
224
+ let prepared_options map(options, config => {
225
+ blankLine: config.blankLine,
226
+ prev: padding_prepare_selectors(config.prev),
227
+ next: padding_prepare_selectors(config.next),
228
+ })
229
+ let policies {
230
+ value zip(structure_padding_items, slice(structure_padding_items, 1))
231
+ map (pair) {
232
+ prior: first(pair),
233
+ following: last(pair),
234
+ policy: find_last(prepared_options, config =>
235
+ padding_side_matches(first(pair), config.prev) && padding_side_matches(last(pair), config.next)).blankLine ?? "any",
236
+ }
237
+ filter (pair) pair.policy != "any"
238
+ map (pair) {
239
+ end: structure_padding_gap_end(pair.prior, pair.following, source),
240
+ start: pair.following.offset, policy: pair.policy,
241
+ }
242
+ filter (pair) pair.end <= pair.start
243
+ && (pair.policy != "never" || structure_padding_blank(byte_slice(source, pair.end, pair.start)))
244
+ }
245
+ let findings compact(map(policies, pair => {
246
+ value comments: if !contains(byte_slice(source, pair.end, pair.start), "/") then []
247
+ else filter(overlapping(ts_comment, pair.end, pair.start),
248
+ comment => pair.end <= comment.offset && comment.end_offset <= pair.start)
249
+ value structure_padding_finding(source, pair, comments)
250
+ }))
251
+ each info in findings {
252
+ report at info.offset
253
+ warn if info.policy == "always" then "Expected blank line before this statement." else "Unexpected blank line before this statement."
254
+ fix at info.edit if info.replacement != null as info.replacement
255
+ }
256
+ }
257
+
258
+ }