@inthedark/dxlint 0.1.1 → 0.1.3

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 (46) hide show
  1. package/README.md +18 -20
  2. package/bin/dxlint-linux-x64 +0 -0
  3. package/bin/dxlint-win32-x64.exe +0 -0
  4. package/package.json +2 -2
  5. package/rules/bugs.dx +49 -0
  6. package/rules/es-no-semi.dx +1 -1
  7. package/rules/{format.dx → formatting.dx} +7 -9
  8. package/rules/recommended.dx +5 -50
  9. package/rules/{conventions.dx → style.dx} +17 -3
  10. package/rules/suspicious.dx +25 -4
  11. package/rules/type-safety.dx +18 -0
  12. package/std/core/lines.dx +3 -3
  13. package/std/ts/expressions.dx +1 -1
  14. package/std/ts/format.dx +8 -8
  15. package/std/ts/indentation.dx +59 -59
  16. package/std/ts/jsx.dx +9 -9
  17. package/std/ts/layout/blocks.dx +5 -5
  18. package/std/ts/layout/calls.dx +8 -8
  19. package/std/ts/layout/expressions.dx +3 -3
  20. package/std/ts/layout/literals.dx +2 -2
  21. package/std/ts/layout/separators.dx +4 -4
  22. package/std/ts/layout/text.dx +1 -1
  23. package/std/ts/license.dx +5 -5
  24. package/std/ts/parentheses.dx +1 -1
  25. package/std/ts/problems/expressions.dx +2 -2
  26. package/std/ts/restrictions/comments.dx +1 -1
  27. package/std/ts/restrictions.dx +11 -11
  28. package/std/ts/scoping.dx +7 -7
  29. package/std/ts/structure.dx +9 -9
  30. package/std/ts/style/classes.dx +2 -2
  31. package/std/ts/style/comments.dx +13 -5
  32. package/std/ts/style/declarations.dx +1 -1
  33. package/std/ts/style/signatures.dx +2 -2
  34. package/std/ts/style/types.dx +6 -6
  35. package/std/ts/suggestions/accessors.dx +1 -1
  36. package/std/ts/suggestions/builtins.dx +1 -1
  37. package/std/ts/suggestions/comparisons.dx +1 -1
  38. package/std/ts/suggestions/curly.dx +1 -1
  39. package/std/ts/suggestions/directives.dx +1 -1
  40. package/std/ts/suggestions/expressions.dx +1 -1
  41. package/std/ts/suggestions/functions.dx +3 -3
  42. package/std/ts/suggestions/object-shorthand.dx +2 -2
  43. package/std/ts/typed/return-await.dx +1 -1
  44. package/std/whitespace.dx +2 -2
  45. package/rules/correctness.dx +0 -33
  46. package/rules/types.dx +0 -21
@@ -366,7 +366,7 @@ in ts_property, ts_method {
366
366
  }
367
367
  in ts_object let restriction_sort_key_count count(property)
368
368
  in ts_property, ts_method, ts_spread rule es-sort-keys {
369
- option mode "asc" | "desc" = "asc" "key order"
369
+ default option mode "asc" | "desc" = "asc" "key order"
370
370
  option caseSensitive boolean = true "compare letter case"
371
371
  option natural boolean = false "compare digit sequences numerically"
372
372
  option minKeys int(2..) = 2 "minimum object properties"
@@ -502,7 +502,7 @@ in ts_parameter {
502
502
  let max_params_counted !restriction_void_this_parameter || node != first(parent.parameter.nodes)
503
503
  }
504
504
  in restriction_parameter_function rule es-max-params {
505
- option max int(0..) = 3 "maximum parameters"
505
+ default option max int(0..) = 3 "maximum parameters"
506
506
  let amount { value parameter.nodes; filter (p) p.max_params_counted.nonempty ?? true; count }
507
507
  when amount > max
508
508
  report at restriction_function_head(node)
@@ -519,7 +519,7 @@ in ts_function_like {
519
519
  let max_statements_checked true
520
520
  }
521
521
  in ts_function_like rule es-max-statements {
522
- option max int(0..) = 10 "maximum statements"
522
+ default option max int(0..) = 10 "maximum statements"
523
523
  option ignoreTopLevelFunctions boolean = false "skip top-level functions unless the file has only one"
524
524
  when restriction_subtree_statements > max
525
525
  when max_statements_checked
@@ -528,7 +528,7 @@ in ts_function_like rule es-max-statements {
528
528
  warn "{@restriction_function_name} has too many statements ({restriction_subtree_statements}). Maximum allowed is {max}."
529
529
  }
530
530
  in ts_function_like rule es-complexity {
531
- option max int(0..) = 20 "maximum cyclomatic complexity"
531
+ default option max int(0..) = 20 "maximum cyclomatic complexity"
532
532
  option variant "classic" | "modified" = "classic" "how switches contribute"
533
533
  let amount 1 + (if variant == "classic" then restriction_subtree_classic else restriction_subtree_modified)
534
534
  when amount > max
@@ -536,7 +536,7 @@ in ts_function_like rule es-complexity {
536
536
  warn "{@restriction_function_name} has a complexity of {amount}. Maximum allowed is {max}."
537
537
  }
538
538
  in ts_static_block, ts_class_property.init rule es-complexity:implicit {
539
- option max int(0..) = 20 "maximum cyclomatic complexity"
539
+ default option max int(0..) = 20 "maximum cyclomatic complexity"
540
540
  option variant "classic" | "modified" = "classic" "how switches contribute"
541
541
  let amount if is (ts_function, ts_arrow) then 1 else 1 + (if variant == "classic" then restriction_subtree_classic else restriction_subtree_modified)
542
542
  when amount > max
@@ -546,21 +546,21 @@ in ts_static_block, ts_class_property.init rule es-complexity:implicit {
546
546
  group restriction_depth_control ts_if, ts_switch, ts_try, ts_do_while, ts_while, ts_with, ts_for, ts_for_in, ts_for_of
547
547
  in ts_statement, ts_arrow, ts_method, ts_static_block, ts_case let restriction_nesting if is (ts_function_like, ts_static_block) then 0 else (parent.restriction_nesting.nonempty ?? 0) + (if is restriction_depth_control && !(is ts_if && is ts_if.alternate) then 1 else 0)
548
548
  in restriction_depth_control rule es-max-depth {
549
- option max int(0..) = 4 "maximum control-flow nesting"
549
+ default option max int(0..) = 4 "maximum control-flow nesting"
550
550
  when !(is ts_if && is ts_if.alternate)
551
551
  when restriction_nesting > max
552
552
  report at { start: first_token.start, end: first_token.end }
553
553
  warn "Blocks are nested too deeply ({restriction_nesting}). Maximum allowed is {max}."
554
554
  }
555
555
  in ts_function, ts_arrow rule es-max-nested-callbacks {
556
- option max int(0..) = 10 "maximum callback nesting"
556
+ default option max int(0..) = 10 "maximum callback nesting"
557
557
  let amount restriction_callbacks
558
558
  when max_nested_callbacks_counted && amount > max
559
559
  report at function_warning_site(node)
560
560
  warn "Too many nested callbacks ({amount}). Maximum allowed is {max}."
561
561
  }
562
562
  in ts_program rule es-max-classes-per-file {
563
- option max int(1..) = 1 "maximum classes"
563
+ default option max int(1..) = 1 "maximum classes"
564
564
  option ignoreExpressions boolean = false "count only class declarations"
565
565
  let amount if ignoreExpressions then restriction_declared_classes else restriction_classes
566
566
  when amount > max
@@ -608,7 +608,7 @@ fn restriction_function_head(n) = when {
608
608
  else then { start: n.offset, end: restriction_open_paren(n) }
609
609
  }
610
610
  in ts_program rule es-max-lines {
611
- option max int(0..) = 300 "maximum lines"
611
+ default option max int(0..) = 300 "maximum lines"
612
612
  option skipComments boolean = false "exclude comment-only lines"
613
613
  option skipBlankLines boolean = false "exclude blank lines"
614
614
  let lines filter(restriction_line_rows, l => !(skipComments && l.restriction_line_comment || skipBlankLines && l.restriction_line_blank))
@@ -620,7 +620,7 @@ in ts_program rule es-max-lines {
620
620
  }
621
621
  in ts_function_like let max_lines_per_function_checked !restriction_iife
622
622
  in ts_function_like rule es-max-lines-per-function {
623
- option max int(0..) = 50 "maximum function lines"
623
+ default option max int(0..) = 50 "maximum function lines"
624
624
  option skipComments boolean = false "exclude comment-only lines"
625
625
  option skipBlankLines boolean = false "exclude blank lines"
626
626
  let lines filter(restriction_line_rows, l => !(skipComments && l.restriction_line_comment || skipBlankLines && l.restriction_line_blank))
@@ -694,7 +694,7 @@ in ts_identifier, ts_private_name {
694
694
  let id_match_checked contains(["always", "destructuring", "import", "declaration", "reference"], restriction_name_match_context)
695
695
  }
696
696
  in ts_identifier, ts_private_name rule es-id-match {
697
- option mode regex = "^.+$" "required identifier pattern"
697
+ default option mode regex = "^.+$" "required identifier pattern"
698
698
  when !restriction_name_attributes && id_match_checked && !restriction_name_external
699
699
  when !re_test(restriction_identifier_name, mode)
700
700
  warn "Identifier '{text}' does not match the pattern '{mode}'."
package/std/ts/scoping.dx CHANGED
@@ -218,7 +218,7 @@ in ts_function let scoping_function_context {
218
218
  }
219
219
  }
220
220
  in ts_function rule es-func-names {
221
- option mode "always" | "as-needed" | "never" = "always"
221
+ default option mode "always" | "as-needed" | "never" = "always"
222
222
  option generators "always" | "as-needed" | "never" | null = null "override policy for generators"
223
223
  let context scoping_function_context
224
224
  let policy if context.generator && generators != null then generators else mode
@@ -270,7 +270,7 @@ in ts_property, ts_class_property let scoping_name_destination
270
270
  property: true, commonjs: false, descriptor: if static_name == "value" then parent.scoping_descriptor_context else null, offset: offset}
271
271
  in ts_parenthesized let scoping_name_destination parent.scoping_name_destination
272
272
  in ts_function rule es-func-name-matching {
273
- option mode "always" | "never" = "always"
273
+ default option mode "always" | "never" = "always"
274
274
  option considerPropertyDescriptor boolean = false
275
275
  option includeCommonJSModuleExports boolean = false
276
276
  let matched parent.scoping_name_destination
@@ -548,7 +548,7 @@ in ts_variable_declaration rule es-vars-on-top {
548
548
  }
549
549
 
550
550
  in ts_function rule es-no-inner-declarations {
551
- option mode "functions" | "both" = "functions"
551
+ default option mode "functions" | "both" = "functions"
552
552
  option blockScopedFunctions "allow" | "disallow" = "allow"
553
553
  when parent is (ts_program, ts_block, ts_export, ts_if, ts_labeled, ts_while, ts_do_while, ts_for, ts_for_in, ts_for_of, ts_case)
554
554
  when !parent.scoping_body_root && parent not ts_export
@@ -556,7 +556,7 @@ in ts_function rule es-no-inner-declarations {
556
556
  warn "Move function declaration to { parent.scoping_declaration_body.nonempty ?? 'program' } root."
557
557
  }
558
558
  in ts_variable_declaration rule es-no-inner-declarations:variable {
559
- option mode "functions" | "both" = "functions"
559
+ default option mode "functions" | "both" = "functions"
560
560
  option blockScopedFunctions "allow" | "disallow" = "allow"
561
561
  when mode == "both" && kind == "var" && !parent.scoping_body_root && parent not ts_export
562
562
  warn "Move variable declaration to { parent.scoping_declaration_body.nonempty ?? 'program' } root."
@@ -642,7 +642,7 @@ in ts_program.binding_declarations rule es-no-shadow {
642
642
  }
643
643
 
644
644
  in ts_identifier rule es-no-use-before-define {
645
- option mode "always" | "nofunc" = "always"
645
+ default option mode "always" | "nofunc" = "always"
646
646
  option functions boolean = true "check function declarations"
647
647
  option classes boolean = true "check class declarations across execution contexts"
648
648
  option variables boolean = true "check variables across execution contexts"
@@ -735,14 +735,14 @@ in ts_variable_declaration {
735
735
  let scoping_iteration_binding is (ts_for_in.left, ts_for_of.left)
736
736
  }
737
737
  in ts_declarator rule es-init-declarations {
738
- option mode "always" | "never" = "always"
738
+ default option mode "always" | "never" = "always"
739
739
  option ignoreForLoopInit boolean = false "allow initialized declarations in loop initializers"
740
740
  when name.declaration_kind != null && name.ambient != true && mode == "always" && init == null
741
741
  when !parent.scoping_iteration_binding
742
742
  warn "Variable '{name}' should be initialized on declaration."
743
743
  }
744
744
  in ts_declarator rule es-init-declarations:never {
745
- option mode "always" | "never" = "always"
745
+ default option mode "always" | "never" = "always"
746
746
  option ignoreForLoopInit boolean = false "allow initialized declarations in loop initializers"
747
747
  when name.declaration_kind != null && name.ambient != true && mode == "never"
748
748
  when parent.kind != "const" && name.declaration_kind != "using"
@@ -375,7 +375,7 @@ in ts_line_comment rule es-line-comment-position {
375
375
  }
376
376
 
377
377
  @macro structure_comment_style_options {
378
- option mode "starred-block" | "bare-block" | "separate-lines" = "starred-block"
378
+ default option mode "starred-block" | "bare-block" | "separate-lines" = "starred-block"
379
379
  option checkJSDoc boolean = false "check JSDoc when requiring line comments"
380
380
  option checkExclamation boolean = false "check exclamation comments when requiring line comments"
381
381
  }
@@ -548,7 +548,7 @@ in ts_line_comment rule es-multiline-comment-style:consecutive {
548
548
  }
549
549
 
550
550
  in ts_question, ts_colon rule es-multiline-ternary {
551
- option mode "always" | "always-multiline" | "never" = "always"
551
+ default option mode "always" | "always-multiline" | "never" = "always"
552
552
  option ignoreJSX boolean = false "ignore conditionals in JSX expressions"
553
553
  when parent is ts_conditional
554
554
  when !ignoreJSX || !parent.structure_ternary_jsx
@@ -577,7 +577,7 @@ in structure_tab_run rule es-no-tabs {
577
577
  }
578
578
 
579
579
  in ts_line rule es-no-mixed-spaces-and-tabs {
580
- option mode "default" | "smart-tabs" = "default"
580
+ default option mode "default" | "smart-tabs" = "default"
581
581
  let indentation re_find(structure_line_content, /^[ \t]+/)
582
582
  let mixed if indentation == null then null
583
583
  else if mode == "smart-tabs" then re_find(indentation, /^\t* +\t/)
@@ -595,7 +595,7 @@ in ts_line rule es-no-mixed-spaces-and-tabs {
595
595
  }
596
596
 
597
597
  in ts_program rule es-unicode-bom {
598
- option mode "always" | "never" = "never"
598
+ default option mode "always" | "never" = "never"
599
599
  when mode == "always" && !bom || mode == "never" && bom
600
600
  fix at { start: 0, end: if mode == "never" then 3 else 0 } as if mode == "always" then "\u{feff}" else ""
601
601
  report at 0
@@ -609,7 +609,7 @@ in ts_regex rule es-wrap-regex {
609
609
  }
610
610
 
611
611
  in ts_declarator rule es-one-var-declaration-per-line {
612
- option mode "initializations" | "always" = "initializations"
612
+ default option mode "initializations" | "always" = "initializations"
613
613
  when previous_sibling != null && !re_test(previous_gap, /[\n\r\u{2028}\u{2029}]/)
614
614
  when !parent.structure_loop_declaration
615
615
  when mode == "always" || init != null || previous.init != null
@@ -646,7 +646,7 @@ fn operand_add(info) =
646
646
  || contains(["[", "(", "{{", "=>", ":"], info.before) || operand_assignment(info.before)
647
647
 
648
648
  in ts_program rule es-indent-binary-ops {
649
- option mode number | "tab" = 2 "indent width or tabs"
649
+ default option mode number | "tab" = 2 "indent width or tabs"
650
650
  let width if mode == "tab" then 1 else mode
651
651
  let unit if mode == "tab" then "\t" else " "
652
652
  let measurements {
@@ -695,7 +695,7 @@ fn structure_operator_fix(before, after, next, policy, operator, before_comment,
695
695
 
696
696
  in ts_binary.operator, ts_logical.operator, ts_assignment.operator, ts_equals, ts_question, ts_colon,
697
697
  ts_union.structure_type_operators, ts_intersection.structure_type_operators rule es-operator-linebreak {
698
- option mode "before" | "after" | "none" | null = null "operator side of a line break"
698
+ default option mode "before" | "after" | "none" | null = null "operator side of a line break"
699
699
  option overrides { [key: string]: "before" | "after" | "none" | "ignore" } = {} "operator-specific placement"
700
700
  when parent is (ts_binary, ts_logical, ts_assignment)
701
701
  || parent is (ts_conditional, ts_conditional_type) && contains(["?", ":"], text)
@@ -928,7 +928,7 @@ in ts_call rule es-newline-per-chained-call {
928
928
  }
929
929
 
930
930
  in ts_arrow.body rule es-implicit-arrow-linebreak {
931
- option mode "beside" | "below" = "beside"
931
+ default option mode "beside" | "below" = "beside"
932
932
  when not ts_block
933
933
  let broken space_before.line_break
934
934
  when mode == "beside" && broken || mode == "below" && !broken
@@ -946,7 +946,7 @@ in ts_arrow rule es-no-confusing-arrow {
946
946
  }
947
947
 
948
948
  in ts_if.consequent, ts_if.alternate, ts_while.body, ts_do_while.body, ts_for.body, ts_for_in.body, ts_for_of.body rule es-nonblock-statement-body-position {
949
- option mode "beside" | "below" | "any" = "beside"
949
+ default option mode "beside" | "below" | "any" = "beside"
950
950
  option overrides { if?: "beside" | "below" | "any"; else?: "beside" | "below" | "any"; while?: "beside" | "below" | "any"; do?: "beside" | "below" | "any"; for?: "beside" | "below" | "any" } = {} "position by statement"
951
951
  let kind if parent is ts_if then (if is ts_if.alternate then "else" else "if") else if parent is ts_while then "while" else if parent is ts_do_while then "do" else "for"
952
952
  let style {
@@ -96,14 +96,14 @@ in ts_class let setter_member_names [] member.setter_member_name
96
96
  in ts_method let literal_member_candidate kind == "get" && !contains([] modifier, "override") && body.first_member_literal && (member_static_name == null || !contains(parent.setter_member_names, member_static_name))
97
97
  in ts_class_property let literal_member_candidate contains([] modifier, "readonly") && !contains([] modifier, "declare") && !contains([] modifier, "override") && init.member_literal == true && (member_static_name == null || !contains(parent.constructor_member_writes, member_static_name))
98
98
  in ts_method.key rule es-class-literal-property-style {
99
- option mode ("fields" | "getters") = "fields" "Preferred literal member declaration."
99
+ default option mode ("fields" | "getters") = "fields" "Preferred literal member declaration."
100
100
  when mode == "fields" && parent.literal_member_candidate
101
101
  let shape parent.style_member
102
102
  report at { start: shape.key, end: shape.key_end }
103
103
  warn "Literals should be exposed using readonly fields."
104
104
  }
105
105
  in ts_class_property.key rule es-class-literal-property-style:getters {
106
- option mode ("fields" | "getters") = "fields" "Preferred literal member declaration."
106
+ default option mode ("fields" | "getters") = "fields" "Preferred literal member declaration."
107
107
  when mode == "getters" && parent.literal_member_candidate
108
108
  let shape parent.style_member
109
109
  report at { start: shape.key, end: shape.key_end }
@@ -3,7 +3,7 @@
3
3
  define {
4
4
 
5
5
  # ---- comments --------------------------------------------------------------------
6
- fn tslint_comment_edit(source, n) = {
6
+ fn linter_comment_edit(source, n) = {
7
7
  value line_start: position(n.offset).js_line_start
8
8
  value prefix: byte_slice(source, line_start, n.offset)
9
9
  value tail: n.after
@@ -24,12 +24,20 @@ fn tslint_comment_edit(source, n) = {
24
24
  text: if re_test(prefix, /\S$/) && re_test(tail, /^\S/) && !re_test(tail, /^[;,)}\]]/) then " " else ""
25
25
  }
26
26
  }
27
- in ts_comment rule es-ban-tslint-comment {
27
+ # Patterns read the whole comment, `//` or `/* */` included: ESLint takes its
28
+ # config comments (`/* eslint ... */`, `/* global x */`) from block comments only.
29
+ in ts_comment rule es-ban-linter-comment {
30
+ option formats { name: string; pattern: regex }[] = [
31
+ { name: "tslint", pattern: /^(?:\/\/|\/\*)\s*tslint:(?:enable|disable)(?:-(?:line|next-line))?(?::|\s|\*\/|$)/ },
32
+ { name: "eslint", pattern: /^(?:\/\/|\/\*)\s*eslint-(?:disable|enable)(?:-(?:line|next-line))?(?:\s|\*\/|$)/ },
33
+ { name: "eslint", pattern: /^\/\*\s*(?:eslint|eslint-env|globals?|exported)(?:\s|\*\/)/ }
34
+ ] "linter comments to report: a name for the message and a pattern over the whole comment"
35
+ let format first(filter(formats, format => re_test(text, format.pattern)))
36
+ when format != null
28
37
  let content re_replace(text, /^\/\/|^\/\*|\*\/$/, "")
29
38
  let normalised re_replace(content, /^\s+|\s+$/, "")
30
- when re_test(content, /^\s*tslint:(enable|disable)(?:-(line|next-line))?(:|\s|$)/)
31
- let edit tslint_comment_edit(source, node)
32
- warn "tslint comment detected: \"{if node is ts_line_comment then '// ' normalised else '/* ' normalised ' */'}\""
39
+ let edit linter_comment_edit(source, node)
40
+ warn "{format.name} comment detected: \"{if node is ts_line_comment then '// ' normalised else '/* ' normalised ' */'}\""
33
41
  fix at edit if edit != null as edit.text
34
42
  }
35
43
 
@@ -67,7 +67,7 @@ fn generic_constructor_replacement(source, owner, construction, annotation, mode
67
67
  value { start: start, end: generics.end, text: ": " construction.name arguments between }
68
68
  }
69
69
  in ts_declarator, ts_class_property, ts_parameter rule es-consistent-generic-constructors {
70
- option mode ("constructor" | "type-annotation") = "constructor" "Preferred location for generic arguments."
70
+ default option mode ("constructor" | "type-annotation") = "constructor" "Preferred location for generic arguments."
71
71
  when not ts_parameter || parent is (ts_function, ts_method)
72
72
  let construction init.constructor_arguments
73
73
  let annotation type.annotation_arguments
@@ -187,7 +187,7 @@ in ts_method_signature, ts_property_signature let signature_report_end {
187
187
  value if next != null && contains([";", ","], next.text) then next.end else end_offset
188
188
  }
189
189
  in ts_method_signature rule es-method-signature-style {
190
- option mode ("method" | "property") = "property" "Preferred method signature notation."
190
+ default option mode ("method" | "property") = "property" "Preferred method signature notation."
191
191
  when mode == "property" && kind != "get" && kind != "set"
192
192
  report at { start: offset, end: signature_report_end }
193
193
  warn "Shorthand method signature is forbidden. Use a function property instead."
@@ -195,7 +195,7 @@ in ts_method_signature rule es-method-signature-style {
195
195
  fix at { start: replacement.start ?? offset, end: replacement.end ?? offset } if replacement != null as replacement.text
196
196
  }
197
197
  in ts_property_signature rule es-method-signature-style:property {
198
- option mode ("method" | "property") = "property" "Preferred method signature notation."
198
+ default option mode ("method" | "property") = "property" "Preferred method signature notation."
199
199
  when mode == "method" && type.is_function_type == true
200
200
  report at { start: offset, end: signature_report_end }
201
201
  warn "Function property signature is forbidden. Use a method shorthand instead."
@@ -370,28 +370,28 @@ fn indexed_notation_replacement(source, owner, info) = {
370
370
  }
371
371
  }
372
372
  in ts_type_literal rule es-consistent-indexed-object-style {
373
- option mode ("record" | "index-signature") = "record" "Preferred indexed object notation."
373
+ default option mode ("record" | "index-signature") = "record" "Preferred indexed object notation."
374
374
  when mode == "record" && indexed_record_eligible
375
375
  warn "A record is preferred over an index signature."
376
376
  let replacement indexed_notation_replacement(source, node, indexed_conversion)
377
377
  fix if replacement != null as replacement
378
378
  }
379
379
  in ts_interface rule es-consistent-indexed-object-style:interface {
380
- option mode ("record" | "index-signature") = "record" "Preferred indexed object notation."
380
+ default option mode ("record" | "index-signature") = "record" "Preferred indexed object notation."
381
381
  when mode == "record" && indexed_record_eligible
382
382
  warn "A record is preferred over an index signature."
383
383
  let replacement indexed_notation_replacement(source, node, indexed_conversion)
384
384
  fix if replacement != null as replacement
385
385
  }
386
386
  in ts_mapped_type rule es-consistent-indexed-object-style:mapped {
387
- option mode ("record" | "index-signature") = "record" "Preferred indexed object notation."
387
+ default option mode ("record" | "index-signature") = "record" "Preferred indexed object notation."
388
388
  when mode == "record" && indexed_record_eligible
389
389
  warn "A record is preferred over an index signature."
390
390
  let replacement indexed_notation_replacement(source, node, indexed_conversion)
391
391
  fix if replacement != null as replacement
392
392
  }
393
393
  in ts_type_reference rule es-consistent-indexed-object-style:record {
394
- option mode ("record" | "index-signature") = "record" "Preferred indexed object notation."
394
+ default option mode ("record" | "index-signature") = "record" "Preferred indexed object notation."
395
395
  when mode == "index-signature" && name == "Record" && count(type_argument) == 2
396
396
  warn "An index signature is preferred over a record."
397
397
  let replacement indexed_notation_replacement(source, node, indexed_conversion)
@@ -451,14 +451,14 @@ fn type_definition_type(source, n) = {
451
451
  value if global_augmentation || open == null || header_end == null then null else type_definition_edit(source, start, close.end_offset, edits)
452
452
  }
453
453
  in ts_type_alias.name rule es-consistent-type-definitions {
454
- option mode ("interface" | "type") = "interface" "Preferred object type definition."
454
+ default option mode ("interface" | "type") = "interface" "Preferred object type definition."
455
455
  when mode == "interface" && parent.aliases_type_literal
456
456
  warn "Use an `interface` instead of a `type`."
457
457
  let edit type_definition_interface(source, parent.node)
458
458
  fix at { start: edit.start ?? offset, end: edit.end ?? offset } if edit != null as edit.text
459
459
  }
460
460
  in ts_interface.name rule es-consistent-type-definitions:interface {
461
- option mode ("interface" | "type") = "interface" "Preferred object type definition."
461
+ default option mode ("interface" | "type") = "interface" "Preferred object type definition."
462
462
  when mode == "type"
463
463
  warn "Use a `type` instead of an `interface`."
464
464
  let edit type_definition_type(source, parent.node)
@@ -126,7 +126,7 @@ in ts_object rule es-accessor-pairs:descriptor {
126
126
  }
127
127
 
128
128
  in ts_method, ts_method_signature rule es-grouped-accessor-pairs {
129
- option mode ("anyOrder" | "getBeforeSet" | "setBeforeGet") = "anyOrder" "accessor order"
129
+ default option mode ("anyOrder" | "getBeforeSet" | "setBeforeGet") = "anyOrder" "accessor order"
130
130
  option enforceForTSTypes boolean = false "check type accessors"
131
131
  let group_info accessor_pair.grouping
132
132
  when accessor_pair.scope != "type" || enforceForTSTypes
@@ -27,7 +27,7 @@ fn valid_radix(value) = value.type == "number" && value.value >= 2 && value.valu
27
27
  fn invalid_radix(n) = n is ts_identifier && n.text == "undefined" && n.resolved == "global" || (n is (ts_number, ts_string, ts_boolean, ts_null, ts_regex, ts_bigint) || n is ts_unary && contains(["+", "-"], n.operator) && n.argument is ts_number) && !valid_radix(n.literal_value)
28
28
 
29
29
  in ts_call rule es-radix {
30
- option mode ("always" | "as-needed") = "always" "legacy radix policy"
30
+ default option mode ("always" | "as-needed") = "always" "legacy radix policy"
31
31
  when parse_int_name != null
32
32
  let argument_count count(argument)
33
33
  let first_argument { value argument.nodes; first; unparenthesised_node }
@@ -28,7 +28,7 @@ fn comparison_fix(source, n) = {
28
28
  }
29
29
 
30
30
  in ts_binary rule es-yoda {
31
- option mode ("never" | "always") = "never" "literal comparison side"
31
+ default option mode ("never" | "always") = "never" "literal comparison side"
32
32
  option exceptRange boolean = false "allow parenthesised ordered range checks"
33
33
  option onlyEquality boolean = false "apply only to equality operators"
34
34
  when contains(["==", "===", "!=", "!==", "<", ">", "<=", ">="], operator)
@@ -105,7 +105,7 @@ fn curly_replacement(source, n, block) = if !block then "{{" n.text "}}" else {
105
105
  }
106
106
 
107
107
  @macro suggestion_curly_policy {
108
- option mode ("all" | "multi" | "multi-line" | "multi-or-nest") = "all" "control body brace policy"
108
+ default option mode ("all" | "multi" | "multi-line" | "multi-or-nest") = "all" "control body brace policy"
109
109
  option style ("consistent" | null) = null "consistent braces throughout if chains"
110
110
  let curly_info curly_body_info(node, mode, style == "consistent")
111
111
  when curly_info != null
@@ -48,7 +48,7 @@ fn strict_missing(n, scope, mode) =
48
48
  else then []
49
49
  }
50
50
  in ts_program, ts_function, ts_arrow, ts_method rule es-strict {
51
- option mode ("safe" | "never" | "global" | "function") = "safe" "strict directive policy"
51
+ default option mode ("safe" | "never" | "global" | "function") = "safe" "strict directive policy"
52
52
  let strict_scope directive_scope
53
53
  let strict_mode when {
54
54
  ts_source_type(ts_module_program(node)) == "module" then "module"
@@ -218,7 +218,7 @@ fn assignment_fix_text(source, n, mode, shorthand) = {
218
218
  }
219
219
  }
220
220
  in ts_assignment rule es-operator-assignment {
221
- option mode ("always" | "never") = "always" "compound arithmetic assignment policy"
221
+ default option mode ("always" | "never") = "always" "compound arithmetic assignment policy"
222
222
  let assigned_key left.reference_key_strict
223
223
  let shorthand if operator == "=" && right.arithmetic_operator != null && assigned_key != null && (assigned_key == right.strict_left_reference_key || contains(["*", "&", "^", "|"], right.arithmetic_operator) && assigned_key == right.strict_right_reference_key) then right.arithmetic_operator "=" else null
224
224
  when if mode == "never" then operator != "=" && !contains(["&&=", "||=", "??="], operator) else shorthand != null
@@ -123,7 +123,7 @@ fn suggestion_function_style(n) = {
123
123
  }
124
124
 
125
125
  in ts_function, ts_arrow rule es-func-style {
126
- option style ("declaration" | "expression") = "expression" "function syntax policy"
126
+ default option style ("declaration" | "expression") = "expression" "function syntax policy"
127
127
  option allowArrowFunctions boolean = false "allow arrow expressions"
128
128
  option allowTypeAnnotation boolean = false "allow annotated function variables"
129
129
  option overrides { namedExports: "" | "declaration" | "expression" | "ignore" } = { namedExports: "" } "named export policy"
@@ -136,7 +136,7 @@ in ts_function, ts_arrow rule es-func-style {
136
136
  }
137
137
 
138
138
  in ts_assignment rule es-no-return-assign {
139
- option mode ("except-parens" | "always") = "except-parens" "assignment return policy"
139
+ default option mode ("except-parens" | "always") = "except-parens" "assignment return policy"
140
140
  let return_info return_assignment_context
141
141
  when return_info != null && (mode == "always" || parent not ts_parenthesized)
142
142
  report at return_info.offset
@@ -190,7 +190,7 @@ fn arrow_body_block_fix(source, n) = {
190
190
  else { start: body.offset, end: body.end_offset, text: replacement }
191
191
  }
192
192
  in ts_arrow rule es-arrow-body-style {
193
- option mode ("always" | "never" | "as-needed") = "as-needed" "arrow body block policy"
193
+ default option mode ("always" | "never" | "as-needed") = "as-needed" "arrow body block policy"
194
194
  option requireReturnForObjectLiteral boolean = false "require a block for object values"
195
195
  when body != null
196
196
  let body_block body is ts_block
@@ -118,7 +118,7 @@ fn shorthand_member_fix(source, n, info, longform, method) =
118
118
  } else n.value.text
119
119
 
120
120
  in ts_property, ts_method rule es-object-shorthand {
121
- option mode ("always" | "never" | "methods" | "properties" | "consistent" | "consistent-as-needed") = "always" "object shorthand policy"
121
+ default option mode ("always" | "never" | "methods" | "properties" | "consistent" | "consistent-as-needed") = "always" "object shorthand policy"
122
122
  option avoidQuotes boolean = false "keep string-literal keys in long form"
123
123
  option ignoreConstructors boolean = false "ignore capitalised method names"
124
124
  option methodsIgnorePattern string = "" "method names to ignore"
@@ -139,7 +139,7 @@ in ts_property, ts_method rule es-object-shorthand {
139
139
  }
140
140
 
141
141
  in ts_object rule es-object-shorthand:consistent {
142
- option mode ("always" | "never" | "methods" | "properties" | "consistent" | "consistent-as-needed") = "always" "object shorthand policy"
142
+ default option mode ("always" | "never" | "methods" | "properties" | "consistent" | "consistent-as-needed") = "always" "object shorthand policy"
143
143
  when mode == "consistent" || mode == "consistent-as-needed"
144
144
  when shorthand_consistency == "mixed" || mode == "consistent-as-needed" && shorthand_consistency == "redundant"
145
145
  warn if shorthand_consistency == "mixed" then "Unexpected mix of shorthand and non-shorthand properties." else "Expected shorthand for all properties."
@@ -74,7 +74,7 @@ fn return_await_selected(result, mode) = result.certainty == "never" && result.a
74
74
  })
75
75
 
76
76
  in ts_function, ts_arrow, ts_method rule es-return-await {
77
- option mode ("always" | "error-handling-correctness-only" | "in-try-catch" | "never") = "in-try-catch" "Await policy for returned promises"
77
+ default option mode ("always" | "error-handling-correctness-only" | "in-try-catch" | "never") = "in-try-catch" "Await policy for returned promises"
78
78
  when contains([] modifier, "async") && body != null
79
79
  let owner node
80
80
  let resources {
package/std/whitespace.dx CHANGED
@@ -10,7 +10,7 @@ in .* layer text match trailing_whitespace /[ \t]+$/ {
10
10
 
11
11
  in .* layer text match line_text /^[^\r\n]+/ {
12
12
  rule shared-max-line-length warn "line is {len(text)} characters long (max {max})" {
13
- option max int(1..) = 120 "maximum line length, in characters"
13
+ default option max int(1..) = 120 "maximum line length, in characters"
14
14
  when len(text) > max
15
15
  }
16
16
  }
@@ -24,7 +24,7 @@ in .* layer text match tab_indent /^ *\t[ \t]*/ {
24
24
 
25
25
  in .* layer text match blank_run /\n(?:[ \t]*\r?\n){2,}/ {
26
26
  rule shared-blank-lines warn "at most {max} blank lines in a row" {
27
- option max int(0..) = 2 "blank lines allowed in a row"
27
+ default option max int(0..) = 2 "blank lines allowed in a row"
28
28
  when { value text; split "\n"; len } - 2 > max
29
29
  fix as "\n" repeat("\n", max)
30
30
  }
@@ -1,33 +0,0 @@
1
- # rules:correctness: code that is almost certainly wrong. Turns on every
2
- # such rule of the imported languages, at its defaults; rules of languages
3
- # not imported are skipped. `rule name off` after the import takes one back.
4
-
5
- rule es-constructor-super
6
- rule es-for-direction
7
- rule es-no-async-promise-executor
8
- rule es-no-compare-neg-zero
9
- rule es-no-cond-assign
10
- rule es-no-constant-condition*
11
- rule es-no-control-regex
12
- rule es-no-debugger
13
- rule es-no-dupe-else-if
14
- rule es-no-duplicate-case
15
- rule es-no-empty-character-class
16
- rule es-no-empty-pattern*
17
- rule es-no-ex-assign
18
- rule es-no-fallthrough
19
- rule es-no-invalid-regexp
20
- rule es-no-irregular-whitespace
21
- rule es-no-loss-of-precision
22
- rule es-no-misleading-character-class*
23
- rule es-no-self-assign
24
- rule es-no-sparse-arrays
25
- rule es-no-unexpected-multiline*
26
- rule es-no-unsafe-finally*
27
- rule es-no-unsafe-optional-chaining*
28
- rule es-no-unused-private-class-members
29
- rule es-no-unused-vars*
30
- rule es-no-useless-assignment
31
- rule es-no-useless-backreference*
32
- rule es-use-isnan
33
- rule es-valid-typeof
package/rules/types.dx DELETED
@@ -1,21 +0,0 @@
1
- # rules:types: rules that read declared types (dxlint's own type evaluator:
2
- # no TypeScript needed). Turns on every such rule of the imported languages,
3
- # at its defaults.
4
-
5
- rule es-await-thenable*
6
- rule es-no-deprecated
7
- rule es-no-floating-promises
8
- rule es-no-for-in-array
9
- rule es-no-misused-promises
10
- rule es-no-unnecessary-boolean-literal-compare
11
- rule es-no-unnecessary-template-expression
12
- rule es-no-unnecessary-type-arguments
13
- rule es-no-unsafe-unary-minus
14
- rule es-unbound-method
15
- rule es-prefer-find*
16
- rule es-prefer-includes
17
- rule es-prefer-optional-chain
18
- rule es-prefer-readonly*
19
- rule es-prefer-string-starts-ends-with*
20
- rule es-restrict-plus-operands*
21
- rule es-restrict-template-expressions