@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
@@ -242,95 +242,95 @@ in ts_variable_declaration let indent_declaration_offset null
242
242
 
243
243
  in ts_line rule es-indent {
244
244
  indent reset indent_reset
245
- option mode int(0..) | "tab" = 4 "spaces per level, or tab"
246
- option tab_length number(1..) = 4 "spaces per raw-template tab in tab mode"
247
- option switch_case int(0..) = 1
248
- option variable_declarator indent_list_offset = 1
249
- option variable_declarator_var indent_list_offset | null = null
250
- option variable_declarator_let indent_list_offset | null = null
251
- option variable_declarator_const indent_list_offset | null = null
252
- option variable_declarator_using indent_list_offset | null = null
253
- option member_expression int(0..) = 1
254
- option function_declaration_parameters indent_list_offset = 1
255
- option function_declaration_body int(0..) = 1
256
- option function_declaration_return_type int(0..) = 1
257
- option function_expression_parameters indent_list_offset = 1
258
- option function_expression_body int(0..) = 1
259
- option function_expression_return_type int(0..) = 1
260
- option static_block int(0..) = 1
261
- option call_expression indent_list_offset = 1
262
- option array_expression indent_list_offset = 1
263
- option object_expression indent_list_offset = 1
264
- option import_declaration indent_list_offset = 1
265
- option assignment_operator int(0..) = 1
245
+ default option mode int(0..) | "tab" = 4 "spaces per level, or tab"
246
+ option tabLength number(1..) = 4 "spaces per raw-template tab in tab mode"
247
+ option switchCase int(0..) = 1
248
+ option variableDeclarator indent_list_offset = 1
249
+ option variableDeclaratorVar indent_list_offset | null = null
250
+ option variableDeclaratorLet indent_list_offset | null = null
251
+ option variableDeclaratorConst indent_list_offset | null = null
252
+ option variableDeclaratorUsing indent_list_offset | null = null
253
+ option memberExpression int(0..) = 1
254
+ option functionDeclarationParameters indent_list_offset = 1
255
+ option functionDeclarationBody int(0..) = 1
256
+ option functionDeclarationReturnType int(0..) = 1
257
+ option functionExpressionParameters indent_list_offset = 1
258
+ option functionExpressionBody int(0..) = 1
259
+ option functionExpressionReturnType int(0..) = 1
260
+ option staticBlock int(0..) = 1
261
+ option callExpression indent_list_offset = 1
262
+ option arrayExpression indent_list_offset = 1
263
+ option objectExpression indent_list_offset = 1
264
+ option importDeclaration indent_list_offset = 1
265
+ option assignmentOperator int(0..) = 1
266
266
  option outerIIFEBody int(0..) = 1
267
- option flat_ternary_expressions boolean = false
268
- option offset_ternary_expressions boolean = false "extra depth for grouped ternary branches"
267
+ option flatTernaryExpressions boolean = false
268
+ option offsetTernaryExpressions boolean = false "extra depth for grouped ternary branches"
269
269
 
270
270
  indent in ts_block, ts_interface, ts_namespace.body
271
271
  indent in ts_class from indent_class_head
272
272
  indent ts_class.token from if is (ts_open_brace, ts_close_brace) then parent.indent_class_head else if contains(["class", "abstract", "declare"], text) then parent.offset else offset by 0
273
273
  indent ts_enum.token from if is ts_open_brace then parent.offset else offset by 0
274
274
  indent indent_generic_arguments.token, indent_generic_parameters.token from if offset == parent.indent_angle_close then parent.indent_angle_open else offset by 0
275
- indent in ts_array, ts_array_pattern, ts_tuple_type by indent_numeric(array_expression)
276
- indent in ts_object, ts_object_pattern, ts_enum, ts_type_literal by indent_numeric(object_expression)
275
+ indent in ts_array, ts_array_pattern, ts_tuple_type by indent_numeric(arrayExpression)
276
+ indent in ts_object, ts_object_pattern, ts_enum, ts_type_literal by indent_numeric(objectExpression)
277
277
  indent in ts_parenthesized, ts_parenthesized_type, ts_computed_key, ts_mapped_type
278
- indent ts_template.expression from indent_template_code_anchor(parent.node, index, mode, tab_length, false) by if { value parent.node; indent_template_parts index; indent_template_relative } then 1 else 0
279
- indent ts_template.quasi from if index == 0 then offset else indent_template_code_anchor(parent.node, index - 1, mode, tab_length, true) by 0
278
+ indent ts_template.expression from indent_template_code_anchor(parent.node, index, mode, tabLength, false) by if { value parent.node; indent_template_parts index; indent_template_relative } then 1 else 0
279
+ indent ts_template.quasi from if index == 0 then offset else indent_template_code_anchor(parent.node, index - 1, mode, tabLength, true) by 0
280
280
  indent in ts_index from indent_index_open
281
- indent ts_index.token from if text == "]" then parent.indent_index_open else if text == "?." then parent.offset else parent.optional.offset.nonempty ?? parent.offset by if text == "]" then 0 else indent_numeric(member_expression)
282
- indent in indent_calls from indent_call_anchor by { value indent_arguments_offset.nonempty ?? call_expression; indent_numeric }
281
+ indent ts_index.token from if text == "]" then parent.indent_index_open else if text == "?." then parent.offset else parent.optional.offset.nonempty ?? parent.offset by if text == "]" then 0 else indent_numeric(memberExpression)
282
+ indent in indent_calls from indent_call_anchor by { value indent_arguments_offset.nonempty ?? callExpression; indent_numeric }
283
283
  indent indent_calls.token from if text == "?." then indent_optional_call_anchor(parent) else if is (ts_open_paren, ts_close_paren) then parent.indent_call_anchor else offset by if text == "?." then 1 else 0
284
- indent in ts_function.body, ts_arrow.body, ts_method.body from indent_function_anchor(parent.indent_body_root) by if parent.indent_outer_iife then parent.indent_body_offset.nonempty ?? indent_numeric(outerIIFEBody) else indent_function_offset(parent, parent.indent_body_offset, function_declaration_body, function_expression_body)
285
- indent in ts_static_block.body by parent.indent_body_offset.nonempty ?? static_block
284
+ indent in ts_function.body, ts_arrow.body, ts_method.body from indent_function_anchor(parent.indent_body_root) by if parent.indent_outer_iife then parent.indent_body_offset.nonempty ?? indent_numeric(outerIIFEBody) else indent_function_offset(parent, parent.indent_body_offset, functionDeclarationBody, functionExpressionBody)
285
+ indent in ts_static_block.body by parent.indent_body_offset.nonempty ?? staticBlock
286
286
  indent ts_function.parameter, ts_arrow.parameter, ts_method.parameter by {
287
287
  value parent
288
- indent_function_offset parent.indent_parameters_offset function_declaration_parameters function_expression_parameters
288
+ indent_function_offset parent.indent_parameters_offset functionDeclarationParameters functionExpressionParameters
289
289
  indent_numeric
290
290
  }
291
- indent ts_function.return_type from parent.indent_return_anchor by indent_function_offset(parent, parent.indent_return_type_offset, function_declaration_return_type, function_expression_return_type)
292
- indent ts_function.token from if is ts_close_paren then indent_function_anchor(parent.indent_body_root) else if offset == parent.indent_return_colon then parent.indent_return_anchor else offset by if is ts_close_paren then 0 else indent_function_offset(parent, parent.indent_return_type_offset, function_declaration_return_type, function_expression_return_type)
291
+ indent ts_function.return_type from parent.indent_return_anchor by indent_function_offset(parent, parent.indent_return_type_offset, functionDeclarationReturnType, functionExpressionReturnType)
292
+ indent ts_function.token from if is ts_close_paren then indent_function_anchor(parent.indent_body_root) else if offset == parent.indent_return_colon then parent.indent_return_anchor else offset by if is ts_close_paren then 0 else indent_function_offset(parent, parent.indent_return_type_offset, functionDeclarationReturnType, functionExpressionReturnType)
293
293
  indent ts_arrow.token, ts_method.token from if is ts_close_paren then indent_function_anchor(parent.indent_body_root) else offset by 0
294
294
  indent ts_arrow.return_type, ts_parameter.type
295
- indent ts_call.argument, ts_new.argument, ts_import_call.argument from parent.indent_call_anchor by { value parent.indent_arguments_offset.nonempty ?? call_expression; indent_numeric }
296
- indent ts_switch.case by switch_case
295
+ indent ts_call.argument, ts_new.argument, ts_import_call.argument from parent.indent_call_anchor by { value parent.indent_arguments_offset.nonempty ?? callExpression; indent_numeric }
296
+ indent ts_switch.case by switchCase
297
297
  indent ts_case.body by if is ts_block && count(parent.body.nodes) == 1 then 0 else 1
298
298
  indent ts_variable_declaration.declaration class declarators by {
299
299
  value parent
300
- style: indent_variable_mode variable_declarator variable_declarator_var variable_declarator_let variable_declarator_const variable_declarator_using
300
+ style: indent_variable_mode variableDeclarator variableDeclaratorVar variableDeclaratorLet variableDeclaratorConst variableDeclaratorUsing
301
301
  value indent_declaration_level(parent, style, mode)
302
302
  }
303
303
  indent in ts_variable_declaration class declarators by {
304
304
  value node
305
- style: indent_variable_mode variable_declarator variable_declarator_var variable_declarator_let variable_declarator_const variable_declarator_using
305
+ style: indent_variable_mode variableDeclarator variableDeclaratorVar variableDeclaratorLet variableDeclaratorConst variableDeclaratorUsing
306
306
  value indent_declaration_level(node, style, mode)
307
307
  }
308
- indent ts_declarator.token from token_neighbours.before.start by if text == "=" then indent_numeric(assignment_operator) else 0
309
- indent ts_member.property, ts_member.token, ts_member.optional, ts_index.optional, ts_meta_property.token by indent_numeric(member_expression)
308
+ indent ts_declarator.token from token_neighbours.before.start by if text == "=" then indent_numeric(assignmentOperator) else 0
309
+ indent ts_member.property, ts_member.token, ts_member.optional, ts_index.optional, ts_meta_property.token by indent_numeric(memberExpression)
310
310
  indent ts_call.optional from indent_optional_call_anchor(parent)
311
- indent ts_import.specifier by indent_numeric(import_declaration)
311
+ indent ts_import.specifier by indent_numeric(importDeclaration)
312
312
  indent ts_import.token, ts_export.token from if parent.indent_module_tail != null && offset >= parent.indent_module_tail && node not ts_semicolon then parent.offset else offset
313
313
  indent ts_import.from, ts_export.from from if parent.indent_module_from != null then parent.offset else offset
314
314
  indent ts_export.specifier
315
- indent ts_assignment.right, ts_assignment_pattern.right by indent_numeric(assignment_operator)
315
+ indent ts_assignment.right, ts_assignment_pattern.right by indent_numeric(assignmentOperator)
316
316
  indent ts_class_property.key from if offset != parent.offset && (is ts_computed_key || first(parent.decorator.nodes) == null) then parent.offset else offset by if is ts_computed_key then 0 else 1
317
- indent ts_class_property.token from if text == "=" then token_neighbours.before.start else if text == ";" then parent.init.token_neighbours.before.start.nonempty ?? parent.key.last_token.start else offset by if text == ";" then 1 else indent_numeric(assignment_operator)
318
- indent ts_class_property.init from token_neighbours.before.start by indent_numeric(assignment_operator)
319
- indent ts_declarator.init from token_neighbours.before.start by indent_numeric(assignment_operator)
320
- indent ts_import_equals.value, ts_type_parameter.default from token_neighbours.before.start by indent_numeric(assignment_operator)
321
- indent ts_import_equals.token, ts_type_parameter.token from if text == "=" then token_neighbours.before.start else offset by indent_numeric(assignment_operator)
317
+ indent ts_class_property.token from if text == "=" then token_neighbours.before.start else if text == ";" then parent.init.token_neighbours.before.start.nonempty ?? parent.key.last_token.start else offset by if text == ";" then 1 else indent_numeric(assignmentOperator)
318
+ indent ts_class_property.init from token_neighbours.before.start by indent_numeric(assignmentOperator)
319
+ indent ts_declarator.init from token_neighbours.before.start by indent_numeric(assignmentOperator)
320
+ indent ts_import_equals.value, ts_type_parameter.default from token_neighbours.before.start by indent_numeric(assignmentOperator)
321
+ indent ts_import_equals.token, ts_type_parameter.token from if text == "=" then token_neighbours.before.start else offset by indent_numeric(assignmentOperator)
322
322
  indent ts_arrow.body from indent_function_anchor(parent.indent_body_root) by if is ts_block then 0 else 1
323
323
  indent ts_property.value, ts_return.argument, ts_throw.argument
324
324
  indent ts_conditional.consequent, ts_conditional.alternate by {
325
325
  value statement: containing(ts_statement)
326
- value indent_ternary_level(node, flat_ternary_expressions, offset_ternary_expressions, statement)
326
+ value indent_ternary_level(node, flatTernaryExpressions, offsetTernaryExpressions, statement)
327
327
  }
328
328
  # An anchor at the branch itself skips this candidate; own-line branches keep ordinary collapsing.
329
329
  indent ts_conditional.consequent, ts_conditional.alternate from if position(first_token.start).js_line == position(token_neighbours.before.start).js_line && position(parent.offset).js_line < position(first_token.start).js_line then token_neighbours.before.start else offset class branches by {
330
330
  value statement: containing(ts_statement)
331
- value indent_ternary_anchor_level(node, flat_ternary_expressions, offset_ternary_expressions, statement)
331
+ value indent_ternary_anchor_level(node, flatTernaryExpressions, offsetTernaryExpressions, statement)
332
332
  }
333
- indent ts_conditional.token by if flat_ternary_expressions && { value statement: containing(ts_statement); value indent_flat_ternary(parent, statement) } then 0 else 1
333
+ indent ts_conditional.token by if flatTernaryExpressions && { value statement: containing(ts_statement); value indent_flat_ternary(parent, statement) } then 0 else 1
334
334
  indent ts_conditional_type.consequent, ts_conditional_type.alternate, ts_conditional_type.token by if parent is ts_conditional_type.alternate && position(parent.extends.last_token.end).js_line == position(parent.consequent.first_token.start).js_line then 0 else 1
335
335
  indent in ts_jsx_element, ts_jsx_fragment
336
336
  indent in ts_jsx_opening
@@ -340,8 +340,8 @@ in ts_line rule es-indent {
340
340
  indent in ts_jsx_fragment.closing from parent.offset by 1
341
341
  indent ts_jsx_closing.name from token_neighbours.before.start
342
342
  indent ts_jsx_opening.token, ts_jsx_closing.token from parent.parent.offset by indent_jsx_token_level(node)
343
- indent ts_jsx_attribute.token from parent.offset by indent_numeric(assignment_operator)
344
- indent ts_jsx_attribute.value from token_neighbours.before.start by indent_numeric(assignment_operator)
343
+ indent ts_jsx_attribute.token from parent.offset by indent_numeric(assignmentOperator)
344
+ indent ts_jsx_attribute.value from token_neighbours.before.start by indent_numeric(assignmentOperator)
345
345
  indent ts_function_type.parameter, ts_method_signature.parameter, ts_call_signature.parameter
346
346
  indent ts_function_type.return_type, ts_method_signature.return_type, ts_call_signature.return_type
347
347
  indent indent_generic_arguments.type_argument, indent_generic_parameters.type_parameter from parent.indent_angle_open
@@ -364,8 +364,8 @@ in ts_line rule es-indent {
364
364
  let list_item indent_first_list_item(first_nodes, first_offset)
365
365
  let list_mode if list_item == null then 1 else {
366
366
  value list_item.parent
367
- variable: indent_variable_mode variable_declarator variable_declarator_var variable_declarator_let variable_declarator_const variable_declarator_using
368
- value indent_list_mode(list_item, call_expression, function_declaration_parameters, function_expression_parameters, array_expression, object_expression, import_declaration, variable)
367
+ variable: indent_variable_mode variableDeclarator variableDeclaratorVar variableDeclaratorLet variableDeclaratorConst variableDeclaratorUsing
368
+ value indent_list_mode(list_item, callExpression, functionDeclarationParameters, functionExpressionParameters, arrayExpression, objectExpression, importDeclaration, variable)
369
369
  }
370
370
  let binary_right { value overlapping(ts_binary.right, first_offset, first_offset + 1); first }
371
371
  let logical_right { value overlapping(ts_logical.right, first_offset, first_offset + 1); first }
@@ -399,8 +399,8 @@ in ts_line rule es-indent {
399
399
  let comment_next { value comment_list.indent_items; filter (item) item.first_token.start >= comment.end_offset; first }
400
400
  let comment_list_mode {
401
401
  value comment_next.parent
402
- variable: indent_variable_mode variable_declarator variable_declarator_var variable_declarator_let variable_declarator_const variable_declarator_using
403
- value indent_list_mode(comment_next, call_expression, function_declaration_parameters, function_expression_parameters, array_expression, object_expression, import_declaration, variable)
402
+ variable: indent_variable_mode variableDeclarator variableDeclaratorVar variableDeclaratorLet variableDeclaratorConst variableDeclaratorUsing
403
+ value indent_list_mode(comment_next, callExpression, functionDeclarationParameters, functionExpressionParameters, arrayExpression, objectExpression, importDeclaration, variable)
404
404
  }
405
405
  let comment_list_range comment_next.indent_list_previous != null && comment_next.indent_list_previous.last_token.end <= comment.offset && position(comment_next.indent_list_previous.last_token.end).js_line > position(comment_list.indent_list_open.offset).js_line && !(comment_list_mode == "first" && position(comment_next.first_token.start).js_column == len(comment_next.indent) + 1)
406
406
  let before_wanted indent_expected(comment_before, unit)
@@ -408,7 +408,7 @@ in ts_line rule es-indent {
408
408
  # Only line-leading declaration semicolons are unchecked; inline ones retain their declaration offset.
409
409
  let after_wanted {
410
410
  value comment_after.parent
411
- variable: indent_variable_mode variable_declarator variable_declarator_var variable_declarator_let variable_declarator_const variable_declarator_using
411
+ variable: indent_variable_mode variableDeclarator variableDeclaratorVar variableDeclaratorLet variableDeclaratorConst variableDeclaratorUsing
412
412
  value indent_comment_after(comment_policy, unit, variable)
413
413
  }
414
414
  when comment == null || comment_list_range || !(comment_before != null && comment.space_before.blank_gaps == 0 && indent == before_wanted || comment_after != null && comment.space_after.blank_gaps == 0 && indent == after_wanted)
@@ -421,10 +421,10 @@ in ts_line rule es-indent {
421
421
  }
422
422
  let aligned_anchor if aligned_first == null then "" else if aligned_quasi != null then indent_expected(aligned_quasi, unit) else if position(aligned_first.first_token.start).js_line == position(aligned_first.parent.offset).js_line then list_item.parent_indent else indent_expected(aligned_first, unit)
423
423
  let aligned_column if aligned_quasi == null then len(aligned_first.indent) else position(aligned_quasi.offset).js_column - 1
424
- let comment_wanted if comment_policy == null then null else indent_comment_wanted(comment_policy, after_wanted, unit, switch_case)
424
+ let comment_wanted if comment_policy == null then null else indent_comment_wanted(comment_policy, after_wanted, unit, switchCase)
425
425
  let attribute_node indent_attribute_node(first_offset)
426
426
  # Raw JSX text uses the tag line's actual indentation, not virtual code-token offsets.
427
- let wanted if jsx_text != null then jsx_text.parent.indent unit else if jsx_member != null then indent_expected(jsx_member.indent_jsx_closing_anchor, unit) { value member_expression; levels: indent_numeric; value indent_steps(unit, levels) } else if type_of(comment_wanted) != "null" then comment_wanted else if attribute_node != null then indent_expected(attribute_node, unit) else if aligned_first != null then aligned_anchor {
427
+ let wanted if jsx_text != null then jsx_text.parent.indent unit else if jsx_member != null then indent_expected(jsx_member.indent_jsx_closing_anchor, unit) { value memberExpression; levels: indent_numeric; value indent_steps(unit, levels) } else if type_of(comment_wanted) != "null" then comment_wanted else if attribute_node != null then indent_expected(attribute_node, unit) else if aligned_first != null then aligned_anchor {
428
428
  value result: if mode == "tab" then "\t" else " "
429
429
  value result_2: position(aligned_first.first_token.start).js_column - 1 - aligned_column
430
430
  value repeat(result, result_2)
package/std/ts/jsx.dx CHANGED
@@ -25,7 +25,7 @@ in ts_jsx_attribute, ts_jsx_spread_attribute {
25
25
  let jsx_prop_indent_extra previous.jsx_prop_indent_extra == true || !jsx_prop_indent_operator && !contains(jsx_prop_indent_line, "<") && (if previous == null then parent.jsx_prop_indent_operator else previous.jsx_prop_indent_operator)
26
26
  }
27
27
  in ts_jsx_attribute, ts_jsx_spread_attribute rule es-jsx-indent-props {
28
- option mode int | "tab" | "first" = 4 "prop indent size or alignment"
28
+ default option mode int | "tab" | "first" = 4 "prop indent size or alignment"
29
29
  let size if mode == "tab" then 1 else mode
30
30
  let base_indent if mode == "tab" then jsx_indent_tabs(parent.jsx_line_prefix) else jsx_indent_spaces(parent.jsx_line_prefix)
31
31
  let actual if mode == "tab" then jsx_indent_tabs(jsx_line_prefix) else jsx_indent_spaces(jsx_line_prefix)
@@ -200,7 +200,7 @@ in ts_jsx_element, ts_jsx_fragment rule es-jsx-wrap-multilines {
200
200
  fix at edit if expression_fix_retains_comments(original, edit.text) as edit.text
201
201
  }
202
202
  in ts_jsx_element, ts_jsx_fragment rule es-jsx-function-call-newline {
203
- option mode "always" | "multiline" = "multiline" "call argument linebreak policy"
203
+ default option mode "always" | "multiline" = "multiline" "call argument linebreak policy"
204
204
  when jsx_call_argument && (mode == "always" || jsx_break(text))
205
205
  when !space_before.line_break || next_token not ts_comma && !space_after.line_break
206
206
  warn "Missing line break around JSX"
@@ -256,7 +256,7 @@ in ts_jsx_expression {
256
256
  let jsx_presence_comments { value descendants(ts_comment); count }
257
257
  }
258
258
  in ts_jsx_expression, ts_jsx_text, ts_string, ts_jsx_element, ts_jsx_fragment rule es-jsx-curly-brace-presence {
259
- option mode "always" | "never" | "ignore" = "never" "default brace policy"
259
+ default option mode "always" | "never" | "ignore" = "never" "default brace policy"
260
260
  option props "always" | "never" | "ignore" | null = null "attribute literal brace policy"
261
261
  option children "always" | "never" | "ignore" | null = null "child literal brace policy"
262
262
  option propElementValues "always" | "never" | "ignore" = "ignore" "JSX element attribute brace policy"
@@ -474,7 +474,7 @@ in jsx_self_closing_brackets rule es-jsx-closing-bracket-location:self-closing {
474
474
  @jsx_closing_bracket_body
475
475
  }
476
476
  in ts_open_angle rule es-jsx-closing-tag-location {
477
- option mode "tag-aligned" | "line-aligned" = "tag-aligned" "closing-tag alignment"
477
+ default option mode "tag-aligned" | "line-aligned" = "tag-aligned" "closing-tag alignment"
478
478
  let here position(offset)
479
479
  let expected if mode == "tag-aligned" then position(parent.parent.opening.offset).js_column else jsx_indent(parent.parent.opening.jsx_line_prefix) + 1
480
480
  let own_line jsx_trim_space(jsx_line_prefix) == ""
@@ -544,7 +544,7 @@ fn jsx_contains_quote(text, double) = { value result: if double then '"' else "'
544
544
  value re_test(text, result_2)
545
545
  }
546
546
  in ts_jsx_attribute.value rule es-jsx-quotes {
547
- option mode "prefer-double" | "prefer-single" = "prefer-double" "preferred attribute quote"
547
+ default option mode "prefer-double" | "prefer-single" = "prefer-double" "preferred attribute quote"
548
548
  let double mode == "prefer-double"
549
549
  when is ts_string
550
550
  when slice(text, 0, 1) != (if double then '"' else "'") && !{ value result: len(text) - 1; value slice(text, 1, result); jsx_contains_quote double }
@@ -556,7 +556,7 @@ in ts_jsx_attribute.value rule es-jsx-quotes {
556
556
  fix at node as quote body quote
557
557
  }
558
558
  @macro jsx_equals_spacing_body {
559
- option mode "always" | "never" = "never" "spacing around equals"
559
+ default option mode "always" | "never" = "never" "spacing around equals"
560
560
  when parent is ts_jsx_attribute
561
561
  when { value if jsx_equals_before then space_before.text else space_after.text; jsx_js_space } != (mode == "always")
562
562
  report at if jsx_equals_before then space_before else space_after
@@ -592,7 +592,7 @@ in ts_jsx_attribute let jsx_prop_name jsx_strip_space(name)
592
592
  in ts_parenthesized let jsx_unparenthesized_text expression.jsx_unparenthesized_text.nonempty ?? expression
593
593
  in ts_jsx_spread_attribute let jsx_prop_name argument.jsx_unparenthesized_text.nonempty ?? argument
594
594
  in ts_jsx_attribute, ts_jsx_spread_attribute rule es-jsx-first-prop-new-line {
595
- option mode "always" | "never" | "multiline" | "multiline-multiprop" | "multiprop" = "multiline-multiprop" "first prop placement"
595
+ default option mode "always" | "never" | "multiline" | "multiline-multiprop" | "multiprop" = "multiline-multiprop" "first prop placement"
596
596
  let should_wrap mode == "always" || mode == "multiline" && !parent.jsx_opening_single || mode == "multiline-multiprop" && !parent.jsx_opening_single && parent.jsx_property_count > 1 || mode == "multiprop" && parent.jsx_property_count > 1
597
597
  let should_inline mode == "never" || mode == "multiprop" && !parent.jsx_opening_single && parent.jsx_property_count <= 1
598
598
  when jsx_prop_first && (should_wrap && jsx_prop_headline || should_inline && !jsx_prop_headline)
@@ -622,8 +622,8 @@ in jsx_max_props_multiline rule es-jsx-max-props-per-line:multiline {
622
622
  @jsx_max_props_body
623
623
  }
624
624
  @macro jsx_props_style_body {
625
- option max_per_line int(1..) = 1 "maximum props per line when wrapping"
626
- when if need_wrap then jsx_prop_same && (jsx_prop_first || jsx_prop_run > max_per_line && (jsx_prop_run - 1) % max_per_line == 0) else !jsx_prop_same
625
+ option maxPerLine int(1..) = 1 "maximum props per line when wrapping"
626
+ when if need_wrap then jsx_prop_same && (jsx_prop_first || jsx_prop_run > maxPerLine && (jsx_prop_run - 1) % maxPerLine == 0) else !jsx_prop_same
627
627
  report at if is ts_jsx_attribute then name.node else node
628
628
  warn if need_wrap then "Prop `{jsx_prop_name}` must be placed on a new line" else "Prop `{jsx_prop_name}` should not be placed on a new line"
629
629
  fix at space_before if jsx_gap_safe(space_before.text) as if need_wrap then "\n" else " "
@@ -5,7 +5,7 @@ import .ts/layout/shared
5
5
  define {
6
6
 
7
7
  @macro layout_block_space_options {
8
- option style "always" | "never" = "always" "spaces inside non-empty blocks"
8
+ default option style "always" | "never" = "always" "spaces inside non-empty blocks"
9
9
  }
10
10
 
11
11
  @macro layout_switch_colon_options {
@@ -51,7 +51,7 @@ fn layout_line_breaks(gap) = re_count(gap, /\r\n|[\n\r\u{2028}\u{2029}]/)
51
51
  fn layout_padding_reduced(gap) = "\n" { value gap; re_find /[^\n\r\u{2028}\u{2029}]*$/ }
52
52
  fn layout_padding_mode(style, blocks, switches, classes, owner) = if owner.layout_block_module.nonempty ?? false then null else if style != null then style else if blocks == null && switches == null && classes == null then "always" else if owner is ts_class then classes else if owner is ts_switch then switches else blocks
53
53
  @macro layout_padding_options {
54
- option style "always" | "never" | "start" | "end" | null = null "padding at block boundaries"
54
+ default option style "always" | "never" | "start" | "end" | null = null "padding at block boundaries"
55
55
  option blocks "always" | "never" | "start" | "end" | null = null "statement block padding"
56
56
  option switches "always" | "never" | "start" | "end" | null = null "switch padding"
57
57
  option classes "always" | "never" | "start" | "end" | null = null "class padding"
@@ -152,7 +152,7 @@ fn layout_member_gap_fix(source, start, end, padded) = {
152
152
  else { start: insertion, end: insertion, text: "\n" }
153
153
  }
154
154
  in ts_class.member rule es-lines-between-class-members {
155
- option style "always" | "never" = "always" "blank lines between class members"
155
+ default option style "always" | "never" = "always" "blank lines between class members"
156
156
  option enforce { blankLine: "always" | "never"; prev: "method" | "field" | "*"; next: "method" | "field" | "*" }[] = [] "policy by neighbouring member kinds"
157
157
  option exceptAfterSingleLine boolean = false "skip after single-line members"
158
158
  option exceptAfterOverload boolean = true "skip overload signatures"
@@ -181,7 +181,7 @@ in ts_class.member rule es-lines-between-class-members {
181
181
  }
182
182
 
183
183
  in ts_open_brace rule es-space-before-blocks {
184
- option style "always" | "never" = "always" "spaces before blocks"
184
+ default option style "always" | "never" = "always" "spaces before blocks"
185
185
  option functions "always" | "never" | "off" | null = null "function body policy"
186
186
  option keywords "always" | "never" | "off" | null = null "statement body policy"
187
187
  option classes "always" | "never" | "off" | null = null "class body policy"
@@ -243,7 +243,7 @@ in ts_colon rule es-switch-colon-spacing:after {
243
243
  }
244
244
 
245
245
  @macro layout_brace_options {
246
- option style "1tbs" | "stroustrup" | "allman" = "1tbs" "brace layout"
246
+ default option style "1tbs" | "stroustrup" | "allman" = "1tbs" "brace layout"
247
247
  option allowSingleLine boolean = false "allow single-line block bodies"
248
248
  when parent is (ts_block, ts_static_block, ts_switch, ts_class)
249
249
  when !(parent.layout_brace_excluded.nonempty ?? false)
@@ -6,7 +6,7 @@ import .ts/format
6
6
  define {
7
7
 
8
8
  in ts_open_paren rule es-space-before-function-paren {
9
- option style "always" | "never" = "always" "spaces before function parameter lists"
9
+ default option style "always" | "never" = "always" "spaces before function parameter lists"
10
10
  option named "always" | "never" | "ignore" | null = null "named function policy"
11
11
  option anonymous "always" | "never" | "ignore" | null = null "anonymous function policy"
12
12
  option asyncArrow "always" | "never" | "ignore" | null = null "async arrow policy"
@@ -39,10 +39,10 @@ fn layout_invocation_chain(gap, allow_newlines, before, after) = {
39
39
  value if after then (if re_test(prefix, /\s$/) then prefix else prefix " ") else trim_end(prefix)
40
40
  }
41
41
  in ts_open_paren rule es-function-call-spacing {
42
- option mode "always" | "never" = "never" "spacing before invocation parentheses"
42
+ default option mode "always" | "never" = "never" "spacing before invocation parentheses"
43
43
  option allowNewlines boolean = false "allow line breaks before invocation parentheses"
44
- option chain_before boolean = true "space before optional invocation punctuation"
45
- option chain_after boolean = true "space after optional invocation punctuation"
44
+ option chainBefore boolean = true "space before optional invocation punctuation"
45
+ option chainAfter boolean = true "space after optional invocation punctuation"
46
46
  when parent is (ts_call, ts_new, ts_import_call)
47
47
  when offset >= parent.layout_invocation_end
48
48
  let invocation_optional parent.layout_invocation_optional
@@ -50,23 +50,23 @@ in ts_open_paren rule es-function-call-spacing {
50
50
  let invocation_spaced invocation_prefix.spaced || space_before.spaced
51
51
  let bad_newline mode == "always" && !allowNewlines && (invocation_prefix.line_break || space_before.line_break)
52
52
  let bad_space if mode == "never" then invocation_spaced
53
- else if invocation_optional then invocation_prefix.spaced != chain_before || space_before.spaced != chain_after
53
+ else if invocation_optional then invocation_prefix.spaced != chainBefore || space_before.spaced != chainAfter
54
54
  else !invocation_spaced
55
55
  when bad_newline || bad_space
56
56
  report at { start: invocation_prefix.start, end: offset }
57
57
  warn if bad_newline then "Unexpected newline between function name and paren."
58
- else if mode == "never" || invocation_optional && (!chain_before && invocation_prefix.spaced || !chain_after && space_before.spaced) then "Unexpected whitespace between function name and paren."
58
+ else if mode == "never" || invocation_optional && (!chainBefore && invocation_prefix.spaced || !chainAfter && space_before.spaced) then "Unexpected whitespace between function name and paren."
59
59
  else "Missing space between function name and paren."
60
60
  let invocation_insert mode == "always" && !invocation_optional && !invocation_spaced
61
61
  let invocation_gap byte_slice(source, invocation_prefix.start, offset)
62
62
  let invocation_fix if mode == "never" then (if invocation_optional then "?." else "")
63
- else if invocation_optional then layout_invocation_chain(invocation_gap, allowNewlines, chain_before, chain_after) else " "
63
+ else if invocation_optional then layout_invocation_chain(invocation_gap, allowNewlines, chainBefore, chainAfter) else " "
64
64
  fix at { start: if invocation_insert then offset else invocation_prefix.start, end: offset } if invocation_insert || !(invocation_prefix.comments || space_before.comments) as invocation_fix
65
65
  }
66
66
 
67
67
  # Empty constructor argument lists belong to this new expression, not its callee.
68
68
  in ts_new rule es-new-parens {
69
- option style "always" | "never" = "always" "empty constructor parentheses"
69
+ default option style "always" | "never" = "always" "empty constructor parentheses"
70
70
  let constructor_open opener.ts_open_paren.offset
71
71
  let constructor_close closer.ts_close_paren.offset
72
72
  when count(argument) == 0
@@ -6,7 +6,7 @@ import .ts/expression-fixes
6
6
  define {
7
7
 
8
8
  @macro layout_computed_space_options {
9
- option style "always" | "never" = "never" "spaces inside computed property brackets"
9
+ default option style "always" | "never" = "never" "spaces inside computed property brackets"
10
10
  option enforceForClassMembers boolean = true "check class member keys"
11
11
  }
12
12
  group computed_spacing_owners ts_computed_key, ts_index, ts_indexed_access
@@ -20,7 +20,7 @@ in ts_function let generator_star_named name != null
20
20
  in ts_method let generator_star_shorthand parent is ts_object
21
21
  @macro layout_yield_star_options {
22
22
  @ts_token_context
23
- option mode "before" | "after" | "both" | "neither" = "after" "spacing around yield star"
23
+ default option mode "before" | "after" | "both" | "neither" = "after" "spacing around yield star"
24
24
  option before boolean | null = null "override space before star"
25
25
  option after boolean | null = null "override space after star"
26
26
  }
@@ -200,7 +200,7 @@ in ts_unary, ts_update, ts_new, ts_await, ts_yield, ts_non_null rule es-space-un
200
200
  }
201
201
 
202
202
  in ts_ellipsis rule es-rest-spread-spacing {
203
- option style "always" | "never" = "never" "spacing after rest and spread"
203
+ default option style "always" | "never" = "never" "spacing after rest and spread"
204
204
  when parent is (ts_rest, ts_spread) && next_token != null
205
205
  let spread_space layout_comma_space(space_after.text, false)
206
206
  when (spread_space != "") != (style == "always")
@@ -19,7 +19,7 @@ fn layout_quote_piece_text(piece, old, target) =
19
19
  else if piece == target || target == "`" && piece == "${{" then "\\" piece
20
20
  else piece
21
21
  in quoted_literals rule es-quotes {
22
- option style "double" | "single" | "backtick" = "double" "string delimiters"
22
+ default option style "double" | "single" | "backtick" = "double" "string delimiters"
23
23
  option avoidEscape boolean = false "allow alternate quotes to avoid escapes"
24
24
  option allowTemplateLiterals "never" | "avoidEscape" | "always" = "never" "allow unused template delimiters"
25
25
  let quote_template is ts_template
@@ -84,7 +84,7 @@ fn layout_property_quote_sites(n) = {
84
84
  value filter(sites, site => site != null)
85
85
  }
86
86
  in ts_property, ts_pattern_property, ts_property_signature, ts_enum_member, ts_object, ts_interface, ts_type_literal, ts_enum, ts_import, ts_export rule es-quote-props {
87
- option style "always" | "as-needed" | "consistent" | "consistent-as-needed" = "always" "property quoting policy"
87
+ default option style "always" | "as-needed" | "consistent" | "consistent-as-needed" = "always" "property quoting policy"
88
88
  option keywords boolean = false "require quotes on reserved words"
89
89
  option unnecessary boolean = true "report redundant quotes"
90
90
  option numbers boolean = false "require quoted numeric keys"
@@ -23,7 +23,7 @@ in ts_import_attribute_comma {
23
23
  }
24
24
  in ts_comma, ts_import_attribute_comma let comma_style_checked comma_style_owner is comma_style_lists
25
25
  in ts_comma, ts_import_attribute_comma rule es-comma-style {
26
- option style "last" | "first" = "last" "comma line position"
26
+ default option style "last" | "first" = "last" "comma line position"
27
27
  when if style == "last" then space_before.line_break else space_after.line_break
28
28
  when comma_style_checked
29
29
  when comma_style_owner not (ts_array, ts_array_pattern) || comma_style_previous != null
@@ -57,7 +57,7 @@ fn layout_attribute_sites(sites, style, policies) = {
57
57
  }) else []
58
58
  }
59
59
  in ts_array, ts_array_pattern, ts_object, ts_object_pattern, ts_function, ts_arrow, ts_method, ts_function_type, ts_call, ts_new, ts_import_call, ts_import, ts_export, ts_enum, ts_tuple_type, ts_class, ts_interface, ts_type_alias, ts_type_reference, ts_method_signature, ts_call_signature, ts_import_attributes rule es-comma-dangle {
60
- option style trailing_comma_mode = "never" "trailing comma policy"
60
+ default option style trailing_comma_mode = "never" "trailing comma policy"
61
61
  option arrays trailing_comma_mode | null = null "array policy"
62
62
  option objects trailing_comma_mode | null = null "object policy"
63
63
  option functions trailing_comma_mode | null = null "parameter and argument policy"
@@ -95,7 +95,7 @@ in ts_variable_declaration let layout_semi_initializer parent is ts_for && offse
95
95
  in ts_semicolon let layout_semi_header if parent is ts_for then parent.init != null && (parent.test == null && previous_token not ts_semicolon || offset < parent.test.offset) || parent.test != null && offset >= parent.test.end_offset else parent.layout_semi_initializer.nonempty ?? false
96
96
  in ts_semicolon let layout_semi_statement parent is layout_semi_owner && end_offset == parent.end_offset
97
97
  in ts_semicolon rule es-semi-style {
98
- option style "last" | "first" = "last" "semicolon line position"
98
+ default option style "last" | "first" = "last" "semicolon line position"
99
99
  when layout_semi_header || layout_semi_statement
100
100
  let semi_at_end style == "last" || layout_semi_header
101
101
  when if semi_at_end then position(offset).js_line != position(token(node, "before").end).js_line
@@ -167,7 +167,7 @@ fn layout_next_position_len(source, offset) = {
167
167
  value if char == "\r" && byte_char(source, offset + 1) == "\n" then 2 else byte_len(char)
168
168
  }
169
169
  in semicolon_statement rule es-semi {
170
- option mode "always" | "never" = "always" "statement semicolon policy"
170
+ default option mode "always" | "never" = "always" "statement semicolon policy"
171
171
  option omitLastInOneLineBlock boolean = false "omit final semicolons in single-line blocks"
172
172
  option omitLastInOneLineClassBody boolean = false "omit final semicolons in single-line class bodies"
173
173
  option beforeStatementContinuationChars "always" | "any" | "never" = "any" "semicolons before continuation characters"
@@ -43,7 +43,7 @@ in multiple_space_gap rule es-no-multi-spaces {
43
43
 
44
44
 
45
45
  @macro layout_comment_policy {
46
- option style "always" | "never" = "always" "spacing inside comment delimiters"
46
+ default option style "always" | "never" = "always" "spacing inside comment delimiters"
47
47
  option exceptions string[] = [] "repeated sequences exempt from spacing"
48
48
  option markers string[] = [] "comment prefix markers"
49
49
  let comment_block is ts_block_comment
package/std/ts/license.dx CHANGED
@@ -8,7 +8,7 @@
8
8
  define {
9
9
 
10
10
  @macro license_text ({ value to: @newline; value replace(license, "\n", to) })
11
- @macro license_wanted license != "" && (skip_files == "" || !re_test(file, skip_files))
11
+ @macro license_wanted license != "" && (skipFiles == "" || !re_test(file, skipFiles))
12
12
  fn license_like(comment) = re_test(comment, /(?i)(?:Copyright|@license|SPDX-License-Identifier)\b/)
13
13
 
14
14
  in ts_program let license_prefix re_find(text, /\A\s*/)
@@ -18,7 +18,7 @@ in ts_program let license_suffix_space if license_header == null then "" else {
18
18
 
19
19
  in ts_program rule es-header:missing warn "Missing license header" {
20
20
  option license string = "" "the license header"
21
- option skip_files regex = "" "file paths without a header"
21
+ option skipFiles regex = "" "file paths without a header"
22
22
  report change
23
23
  when @license_wanted && byte_len(license_prefix) < byte_len(text)
24
24
  when license_header == null || !license_like(license_header.text)
@@ -26,7 +26,7 @@ in ts_program rule es-header:missing warn "Missing license header" {
26
26
  }
27
27
  in ts_program rule es-header:invalid warn "Invalid license header" {
28
28
  option license string = "" "the license header"
29
- option skip_files regex = "" "file paths without a header"
29
+ option skipFiles regex = "" "file paths without a header"
30
30
  when @license_wanted && license_header != null
31
31
  when license_like(license_header.text) && license_header.text != @license_text
32
32
  report at { start: license_header.offset, end: license_header.end_offset }
@@ -34,7 +34,7 @@ in ts_program rule es-header:invalid warn "Invalid license header" {
34
34
  }
35
35
  in ts_program rule es-header:before warn "Superfluous new lines before license header" {
36
36
  option license string = "" "the license header"
37
- option skip_files regex = "" "file paths without a header"
37
+ option skipFiles regex = "" "file paths without a header"
38
38
  when @license_wanted && license_header != null && contains(license_prefix, "\n")
39
39
  when license_header.text == @license_text
40
40
  report at license_header.offset
@@ -42,7 +42,7 @@ in ts_program rule es-header:before warn "Superfluous new lines before license h
42
42
  }
43
43
  in ts_program rule es-header:after warn "{if re_count(license_suffix_space, /\n/) > 2 then 'Superfluous new lines' else 'Missing new line'} after license header" {
44
44
  option license string = "" "the license header"
45
- option skip_files regex = "" "file paths without a header"
45
+ option skipFiles regex = "" "file paths without a header"
46
46
  when @license_wanted && license_header != null
47
47
  when license_header.text == @license_text
48
48
  let suffix_end license_header.end_offset + byte_len(license_suffix_space)
@@ -12,7 +12,7 @@ in ts_parenthesized let structure_iife_callee expression.structure_iife_callee
12
12
  in ts_member, ts_index let structure_iife_callee if (object.structure_iife_callee).direct && contains(["call", "apply"], static_name) then { direct: false, prototype: true, wrapped: (object.structure_iife_callee).wrapped, node: (object.structure_iife_callee).node } else null
13
13
 
14
14
  in ts_call rule es-wrap-iife {
15
- option mode "outside" | "inside" | "any" = "outside"
15
+ default option mode "outside" | "inside" | "any" = "outside"
16
16
  option functionPrototypeMethods boolean = false "include function call/apply invocations"
17
17
  let info callee.structure_iife_callee
18
18
  when info != null && (functionPrototypeMethods || !info.prototype)
@@ -18,14 +18,14 @@ in ts_binary rule es-no-compare-neg-zero {
18
18
  in ts_assignment let is_assignment true
19
19
  in ts_parenthesized let wraps_assignment expression.is_assignment == true
20
20
  in ts_if.test, ts_while.test, ts_do_while.test, ts_for.test, ts_conditional.test rule es-no-cond-assign {
21
- option mode "except-parens" | "always" = "except-parens"
21
+ default option mode "except-parens" | "always" = "except-parens"
22
22
  when mode == "except-parens"
23
23
  when is ts_assignment || parent is ts_conditional && is ts_parenthesized && wraps_assignment == true
24
24
  report at unparenthesised_node(node)
25
25
  warn "Expected a conditional expression and instead saw an assignment."
26
26
  }
27
27
  in ts_assignment rule es-no-cond-assign:always {
28
- option mode "except-parens" | "always" = "except-parens"
28
+ default option mode "except-parens" | "always" = "except-parens"
29
29
  let where if conditional_ancestor is ts_if then "an 'if' statement" else if conditional_ancestor is ts_while then "a 'while' statement" else if conditional_ancestor is ts_do_while then "a 'do...while' statement" else if conditional_ancestor is ts_for then "a 'for' statement" else "ConditionalExpression"
30
30
  when mode == "always" && conditional_ancestor != null
31
31
  warn "Unexpected assignment within {where}."
@@ -59,7 +59,7 @@ fn comment_case_fix(n, body, mode) = {
59
59
  }
60
60
  in ts_comment let capitalized_comments_checked true
61
61
  @macro restriction_capitalized_comment_body {
62
- option mode "always" | "never" = "always" "required initial letter case"
62
+ default option mode "always" | "never" = "always" "required initial letter case"
63
63
  option ignorePattern regex = "" "starting comment text to ignore"
64
64
  when capitalized_comments_checked
65
65
  when (if mode == "always" then restriction_comment_lowercase else restriction_comment_uppercase)