diff --git a/format.nu b/format.nu index 9b7f003..1b24adb 100755 --- a/format.nu +++ b/format.nu @@ -7,8 +7,8 @@ const script_path = path self . @example "Format files (in-place replacement)" { format.nu foo.nu bar.nu } @example "Path overriding" { format.nu -c /path/to/topiary-nushell foo.nu bar.nu } def main [ - --config_dir (-c): path # Root of the topiary-nushell repo, defaults to the parent directory of this script - ...files: path # Files to format + --config_dir (-c): path, # Root of the topiary-nushell repo, defaults to the parent directory of this script + ...files: path, # Files to format ]: [nothing -> nothing string -> string] { let config_dir = $config_dir | default $script_path $env.TOPIARY_CONFIG_FILE = ($config_dir | path join languages.ncl) diff --git a/languages/nu.scm b/languages/nu.scm index 6fc46dd..b38d0c8 100644 --- a/languages/nu.scm +++ b/languages/nu.scm @@ -141,33 +141,54 @@ ) @append_indent_end ) -;; space/newline between parameters -(parameter_pipes - ( - (parameter) @append_space - . - (parameter) - )? -) @append_space @append_spaced_softline +(parameter_pipes) @append_space @append_spaced_softline -(parameter_bracks - (parameter) @append_space - . - (parameter) @prepend_empty_softline +(parameter + flag_capsule: _ @prepend_space ) -(parameter_parens - (parameter) @append_space - . - (parameter) @prepend_empty_softline +;; Comma/newline between parameters +;; NOTE: Currently, the parameter node contains the comma separator, +;; as well as its doc comment. We want the comma to appear before the comment. +(parameter + "," @delete ) (parameter - flag_capsule: _ @prepend_space + ;; need to be explicit to avoid + ;; commas between consecutive comments + [ + (flag_capsule) + (param_completer) + (param_long_flag) + (param_opt) + (param_short_flag) + (param_type) + (param_value) + ] @append_delimiter + . + (comment) + (#delimiter! ",") ) -(parameter - "," @delete +;; FIXME: comma after the last parameter for multi-line lists +;; https://github.com/nushell/tree-sitter-nu/issues/215 +( + (parameter + (comment)? @do_nothing + ) @append_delimiter + . + (parameter) + (#delimiter! ", ") + (#single_line_only!) +) + +( + (parameter + (comment)? @do_nothing + ) @append_delimiter @append_spaced_softline + (#delimiter! ",") + (#multi_line_only!) ) ;; attributes @@ -287,9 +308,19 @@ (ctrl_match "match" @append_space scrutinee: _? @append_space - (match_arm)? @prepend_spaced_softline - (default_arm)? @prepend_spaced_softline - "}"? @prepend_spaced_softline + "{" @append_spaced_softline + "}" @prepend_spaced_softline +) + +(ctrl_match + [ + (match_arm) + (default_arm) + ] @append_delimiter + . + (_) + (#delimiter! ", ") + (#single_line_only!) ) (match_pattern "|" @prepend_spaced_softline @append_space) @@ -313,27 +344,92 @@ file_path: _? @prepend_input_softline ) @prepend_input_softline +;; FIXME: comma after the last entry for multi-line expressions +;; A workaround given: +;; 1. https://github.com/nushell/tree-sitter-nu/issues/215 +;; 2. https://github.com/tree-sitter/tree-sitter/discussions/3967 +;; 3. Comments between entries should be kept unmoved (list_body - entry: _ @append_space + entry: _ @append_delimiter . - entry: _ @prepend_spaced_softline + entry: _ + (#delimiter! ", ") + (#single_line_only!) ) (record_body - entry: _ @append_space + entry: _ @append_delimiter . - entry: _ @prepend_spaced_softline + entry: _ + (#delimiter! ", ") + (#single_line_only!) ) -;; match_arm -(val_list - (list_body) +(list_body + entry: _ @append_delimiter + (#delimiter! ",") + (#multi_line_only!) +) + +(list_body + entry: _ @append_begin_scope . - rest: _ @prepend_spaced_softline + entry: _ @prepend_spaced_softline @prepend_end_scope + (#scope_id! "consecutive_scope") + (#multi_line_only!) +) + +(record_body + entry: _ @append_delimiter + (#delimiter! ",") + (#multi_line_only!) +) + +(record_body + entry: _ @append_begin_scope + . + entry: _ @prepend_spaced_softline @prepend_end_scope + (#scope_id! "consecutive_scope") + (#multi_line_only!) +) + +(val_table + row: _ @append_delimiter + . + row: _ + (#delimiter! ", ") + (#single_line_only!) ) (val_table - row: _ @prepend_spaced_softline + row: _ @append_delimiter @prepend_spaced_softline + (#delimiter! ",") + (#multi_line_only!) +) + +(ctrl_match + [ + (match_arm (block)? @do_nothing) + (default_arm (block)? @do_nothing) + ] @append_delimiter + (#delimiter! ",") + (#multi_line_only!) +) + +(ctrl_match + [ + (match_arm) + (default_arm) + ] @prepend_spaced_softline + (#multi_line_only!) +) + +;; match_arm +(val_list + (list_body) @append_delimiter + . + rest: _ @prepend_spaced_softline + (#delimiter! ",") ) ;; type notation diff --git a/run_test.nu b/run_test.nu index fb002fb..2648f69 100755 --- a/run_test.nu +++ b/run_test.nu @@ -8,15 +8,33 @@ let files = glob test/input_*.nu $env.TOPIARY_CONFIG_FILE = (pwd | path join languages.ncl) $env.TOPIARY_LANGUAGE_DIR = (pwd | path join languages) -for f in $files { - print $"(ansi green)Testing: (ansi yellow)($f)(ansi reset)" - cp $f $temp_file - topiary format $temp_file - let expected_file = $f | str replace --regex '/input_' '/expected_' - try { - assert ((open $temp_file) == (open $expected_file)) - } catch { - delta $temp_file $expected_file +def main [ + --update (-u), # force updating `expected_xxx` files +] { + for f in $files { + print $"(ansi green)Testing: (ansi yellow)($f)(ansi reset)" + cp $f $temp_file + topiary format $temp_file + let expected_file = $f | str replace --regex '/input_' '/expected_' + try { + if ((which delta) | is-empty) { + assert ((open $temp_file) == (open $expected_file)) + } else { + delta $temp_file $expected_file --paging never + } + } catch { + if $update and ( + [yes, no] + | input list --index --fuzzy $"Update expected results in file ( + $expected_file + | path basename + )?" + ) == 0 { + cp $temp_file $expected_file + } else { + exit 1 + } + } + rm $temp_file } - rm $temp_file } diff --git a/test/expected_attribute.nu b/test/expected_attribute.nu index 9b1ea3d..36ff8d3 100644 --- a/test/expected_attribute.nu +++ b/test/expected_attribute.nu @@ -12,9 +12,9 @@ def test [] { } path add {linux: "foo"} } export def --env "path add" [ - --ret (-r) # return $env.PATH, useful in pipelines to avoid scoping. - --append (-a) # append to $env.PATH instead of prepending to. - p + --ret (-r), # return $env.PATH, useful in pipelines to avoid scoping. + --append (-a), # append to $env.PATH instead of prepending to. + p, ] { } @search-terms multiply times diff --git a/test/expected_comment.nu b/test/expected_comment.nu index e731577..22c6c70 100644 --- a/test/expected_comment.nu +++ b/test/expected_comment.nu @@ -4,20 +4,21 @@ # multiline def foo_bar [ # comment at [ - foo: string # comment for arg - bar: int # another comment + foo: string, # comment for arg + # 2nd comment for arg foo + bar: int, # another comment ] { # comment at { # comment in body [ - foo # comment in list + foo, # comment in list # another comment - bar + bar, ]; { - foo: foo # comment in record + foo: foo, # comment in record # another comment - bar: bar + bar: bar, } # comment at } ( # comment at ( diff --git a/test/expected_ctrl.nu b/test/expected_ctrl.nu index e751181..b93a1cd 100644 --- a/test/expected_ctrl.nu +++ b/test/expected_ctrl.nu @@ -1,5 +1,5 @@ # for -for i in [1 2 3] { +for i in [1, 2, 3] { # if if (true or false) { print "break"; break # break @@ -14,25 +14,25 @@ alias ll = ls -l # alias comment ls | where $in.name == 'foo' | where {|e| $e.item.name !~ $'^($e.index + 1)' } # match -let foo = {name: 'bar' count: 7} +let foo = {name: 'bar', count: 7} match $foo { - {name: 'bar' count: $it} if $it < 5 => ($it + 3) # match arm comment + {name: 'bar', count: $it} if $it < 5 => ($it + 3), # match arm comment # match comment - {name: 'bar' count: $it} if not ($it >= 5) => ($it + 7) + {name: 'bar', count: $it} if not ($it >= 5) => ($it + 7), _ => { exit 0 } } match $foo { - [a b c] => 0 - a | b | c => 42 + [a, b, c] => 0, + a | b | c => 42, a | b - | c => 42 - {$bar $baz} => $baz + | c => 42, + {$bar, $baz} => $baz, # ..rest pattern - [$x ..$y] if $x == 1 => { 'good list' } + [$x, ..$y] if $x == 1 => { 'good list' } [..$y] => { $y } } -match $foo { null => { return "default" } $val => $val } +match $foo { null => { return "default" }, $val => $val } # while mut x = 0; while $x < 10 { $x = $x + 1 }; $x # while comment # loop @@ -44,6 +44,6 @@ loop { try { # error error make -u { - msg: 'Some error info' + msg: 'Some error info', } }; print 'Resuming' diff --git a/test/expected_data.nu b/test/expected_data.nu index d1ffe71..b2ad600 100644 --- a/test/expected_data.nu +++ b/test/expected_data.nu @@ -1,253 +1,258 @@ export const config = { default: { - align: center - updates: when_shown - padding_left: 2 - padding_right: 2 - icon.font: "Sarasa Term SC Nerd:Bold:17.0" - label.font: "Sarasa Term SC Nerd:Bold:12.0" - icon.color: $colors.white - label.color: $colors.fg - icon.padding_left: 8 - icon.padding_right: 2 - label.padding_left: 2 - label.padding_right: 8 - background.corner_radius: 10 - background.color: $colors.bg - background.border_width: 1 - background.border_color: $colors.bg - } + align: center, + updates: when_shown, + padding_left: 2, + padding_right: 2, + icon.font: "Sarasa Term SC Nerd:Bold:17.0", + label.font: "Sarasa Term SC Nerd:Bold:12.0", + icon.color: $colors.white, + label.color: $colors.fg, + icon.padding_left: 8, + icon.padding_right: 2, + label.padding_left: 2, + label.padding_right: 8, + background.corner_radius: 10, + background.color: $colors.bg, + background.border_width: 1, + background.border_color: $colors.bg, + }, workspace_default_args: { - icon.font.size: 12 - label.font.size: 17 - label.shadow.drawing: on - label.shadow.color: $colors.bg - label.shadow.distance: 3 - label.highlight_color: $colors.green - background.drawing: off - background.color: $colors.transparent - background.border_width: 2 - background.border_color: $colors.fg - background.shadow.drawing: on - background.shadow.color: $colors.bg - background.shadow.distance: 3 - } + icon.font.size: 12, + label.font.size: 17, + label.shadow.drawing: on, + label.shadow.color: $colors.bg, + label.shadow.distance: 3, + label.highlight_color: $colors.green, + background.drawing: off, + background.color: $colors.transparent, + background.border_width: 2, + background.border_color: $colors.fg, + background.shadow.drawing: on, + background.shadow.color: $colors.bg, + background.shadow.distance: 3, + }, plugin_configs: [ { - name: ws_listener - pos: left - events: [aerospace_workspace_change space_windows_change] + name: ws_listener, + pos: left, + events: [aerospace_workspace_change, space_windows_change], args: { - updates: on - drawing: off - script: '{}/aerospace.nu' - } - } + updates: on, + drawing: off, + script: '{}/aerospace.nu', + }, + }, { - name: front_app - pos: left - events: [front_app_switched aerospace_mode_change] + name: front_app, + pos: left, + events: [front_app_switched, aerospace_mode_change], args: { - label.color: $colors.black - icon.color: $colors.black - icon.font.size: 20 - background.color: $colors.blue - background.corner_radius: 3 - background.shadow.drawing: on - background.shadow.color: $colors.bg - background.shadow.distance: 3 - script: '{}/front_app.nu' - } - } + label.color: $colors.black, + icon.color: $colors.black, + icon.font.size: 20, + background.color: $colors.blue, + background.corner_radius: 3, + background.shadow.drawing: on, + background.shadow.color: $colors.bg, + background.shadow.distance: 3, + script: '{}/front_app.nu', + }, + }, { - name: media - pos: center - events: [media_change] + name: media, + pos: center, + events: [media_change], args: { - icon: '󰐎' - icon.color: $colors.fg - label.color: $colors.fg - background.color: $colors.bg - background.border_color: $colors.fg - script: '{}/media.nu' - } - } + icon: '󰐎', + icon.color: $colors.fg, + label.color: $colors.fg, + background.color: $colors.bg, + background.border_color: $colors.fg, + script: '{}/media.nu', + }, + }, { - name: media_cover - pos: center - events: [media_change] + name: media_cover, + pos: center, + events: [media_change], args: { - icon.drawing: off - label.drawing: off - background.image.drawing: on - background.image: media.artwork - background.image.scale: 0.7 - background.color: $colors.transparent - background.border_width: 0 - } - } + icon.drawing: off, + label.drawing: off, + background.image.drawing: on, + background.image: media.artwork, + background.image.scale: 0.7, + background.color: $colors.transparent, + background.border_width: 0, + }, + }, { - name: clock + name: clock, args: { - update_freq: 30 - icon: '' - script: '{}/clock.nu' - background.corner_radius: 3 - padding_right: 1 - padding_left: 1 - label.font.size: 10 - } - } + update_freq: 30, + icon: '', + script: '{}/clock.nu', + background.corner_radius: 3, + padding_right: 1, + padding_left: 1, + label.font.size: 10, + }, + }, { - name: volume - events: [volume_change] + name: volume, + events: [volume_change], args: { - script: '{}/volume.nu' - background.corner_radius: 3 - padding_right: 1 - padding_left: 1 - } - } + script: '{}/volume.nu', + background.corner_radius: 3, + padding_right: 1, + padding_left: 1, + }, + }, { - name: battery - events: [system_woke power_source_change] + name: battery, + events: [system_woke, power_source_change], args: { - update_freq: 120 - script: '{}/battery.nu' - click_script: 'open x-apple.systempreferences:com.apple.preference.battery' - background.corner_radius: 3 - padding_right: 1 - } - } + update_freq: 120, + script: '{}/battery.nu', + click_script: 'open x-apple.systempreferences:com.apple.preference.battery', + background.corner_radius: 3, + padding_right: 1, + }, + }, { - name: separator_right + name: separator_right, args: { - icon: '' - padding_left: 0 - label.drawing: off - background.drawing: off - click_script: '{}/toggle_stats.nu' - } - } + icon: '', + padding_left: 0, + label.drawing: off, + background.drawing: off, + click_script: '{}/toggle_stats.nu', + }, + }, { - name: disk + name: disk, args: { - icon: '' - update_freq: 120 - script: '{}/disk.nu' - click_script: 'open -a "Disk Utility"' - icon.color: $colors.green - background.border_color: $colors.green - } - } + icon: '', + update_freq: 120, + script: '{}/disk.nu', + click_script: 'open -a "Disk Utility"', + icon.color: $colors.green, + background.border_color: $colors.green, + }, + }, { - name: cpu + name: cpu, args: { - icon: '' - update_freq: 10 - script: '{}/cpu.nu' - click_script: 'open -a "Activity Monitor"' - icon.color: $colors.yellow - background.border_color: $colors.yellow - } - } + icon: '', + update_freq: 10, + script: '{}/cpu.nu', + click_script: 'open -a "Activity Monitor"', + icon.color: $colors.yellow, + background.border_color: $colors.yellow, + }, + }, { - name: memory + name: memory, args: { - icon: '﬙' - update_freq: 10 - script: '{}/mem.nu' - click_script: 'open -a "Activity Monitor"' - icon.color: $colors.cyan - background.border_color: $colors.cyan - } - } + icon: '﬙', + update_freq: 10, + script: '{}/mem.nu', + click_script: 'open -a "Activity Monitor"', + icon.color: $colors.cyan, + background.border_color: $colors.cyan, + }, + }, { - name: temp_cpu + name: temp_cpu, args: { - icon: '' - label.font.size: 7 - label.y_offset: -4 - icon.font.size: 16 - update_freq: 5 - padding_left: -58 - script: '{}/temp.nu' - click_script: '{}/popups/temp.nu' - popup.align: left - popup.background.border_width: 2 - popup.background.corner_radius: 3 - popup.background.border_color: $colors.yellow - popup.background.drawing: on - } + icon: '', + label.font.size: 7, + label.y_offset: -4, + icon.font.size: 16, + update_freq: 5, + padding_left: -58, + script: '{}/temp.nu', + click_script: '{}/popups/temp.nu', + popup.align: left, + popup.background.border_width: 2, + popup.background.corner_radius: 3, + popup.background.border_color: $colors.yellow, + popup.background.drawing: on, + }, popups: [ { - name: temp_fan1 + name: temp_fan1, args: { - label: "unk" - icon: '󱑲' - } - } + label: "unk", + icon: '󱑲', + }, + }, { - name: temp_fan2 + name: temp_fan2, args: { - label: "unk" - icon: '󱑳' - } - } + label: "unk", + icon: '󱑳', + }, + }, { - name: temp_power + name: temp_power, args: { - label: "unk" - icon: '󰠠' - } - } - ] - } + label: "unk", + icon: '󰠠', + }, + }, + ], + }, { - name: temp_gpu + name: temp_gpu, args: { - label.font.size: 7 - padding_left: 0 - padding_right: 0 - icon.font.size: 16 - icon.drawing: off - label.y_offset: 4 - background.drawing: off - } - } + label.font.size: 7, + padding_left: 0, + padding_right: 0, + icon.font.size: 16, + icon.drawing: off, + label.y_offset: 4, + background.drawing: off, + }, + }, { - name: network_down + name: network_down, args: { - icon: '󰖩' - label.font.size: 7 - label.y_offset: -4 - update_freq: 3 - padding_left: -73 - padding_right: 23 - script: '{}/network.nu' - icon.color: $colors.purple - label.highlight_color: $colors.purple - background.border_color: $colors.purple - } - } + icon: '󰖩', + label.font.size: 7, + label.y_offset: -4, + update_freq: 3, + padding_left: -73, + padding_right: 23, + script: '{}/network.nu', + icon.color: $colors.purple, + label.highlight_color: $colors.purple, + background.border_color: $colors.purple, + }, + }, { - name: network_up + name: network_up, args: { - label.font.size: 7 - padding_left: 0 - padding_right: 0 - icon.drawing: off - label.y_offset: 4 - background.drawing: off - label.highlight_color: $colors.purple - } - } - ] + label.font.size: 7, + padding_left: 0, + padding_right: 0, + icon.drawing: off, + label.y_offset: 4, + background.drawing: off, + label.highlight_color: $colors.purple, + }, + }, + ], } -const table = [[a b]; [1 2] [2 [4 4]]] -const table_no_row = [[a b]; ] +const table = [[a, b]; [1, 2], [2, [4, 4]]] +const multi_line_table = [ + [a, b]; + [1, 2], + [2, [4, 4]], +] +const table_no_row = [[a, b]; ] mut foo: record<"a", b, "c": int, d: list> = {} diff --git a/test/expected_decl.nu b/test/expected_decl.nu index 906101a..204d096 100644 --- a/test/expected_decl.nu +++ b/test/expected_decl.nu @@ -4,14 +4,14 @@ export extern hello [name: string] { } # decl_extern no body block extern hi [ - name: string - --long (-s) # flags + name: string, + --long (-s), # flags ] # env hide-env ABC with-env {ABC: 'hello'} { ( - do -i --env {|foo bar| + do -i --env {|foo, bar| print $env.ABC } foo bar @@ -19,7 +19,7 @@ with-env {ABC: 'hello'} { } # closure -let cls = {|foo bar baz| +let cls = {|foo, bar, baz| ( $foo + $bar + $baz @@ -34,8 +34,8 @@ export-env { # decl_def def "hi there" [where: string]: nothing -> record, bar: int> { { - foo: [["baz"]; [1.0]] - bar: 1 + foo: [["baz"]; [1.0]], + bar: 1, } } @@ -56,8 +56,8 @@ use module [ "foo" bar ] # decl_module module greetings { export def hello [ - name: string - --experimental-options: oneof, string> # enable or disable experimental options + name: string, + --experimental-options: oneof, string>, # enable or disable experimental options ] { $"hello ($name)!" } @@ -68,4 +68,4 @@ module greetings { }; # https://github.com/blindFS/topiary-nushell/issues/35 -def f [--arg1: number --arg2: string] { } +def f [--arg1: number, --arg2: string] { } diff --git a/test/expected_exe.nu b/test/expected_exe.nu index 9e6dae6..51a876f 100644 --- a/test/expected_exe.nu +++ b/test/expected_exe.nu @@ -9,8 +9,8 @@ use constants.nu [ const animate_frames = 30 def modify_args_per_workspace [ - sid: string - focused_sid: string + sid: string, + focused_sid: string, ]: nothing -> list { let icons = ( aerospace list-windows --workspace $sid --json @@ -21,28 +21,28 @@ def modify_args_per_workspace [ ) let extra = ( if $sid == $focused_sid { - {highlight: on border_color: $colors.green} + {highlight: on, border_color: $colors.green} } else { - {highlight: off border_color: $colors.fg} + {highlight: off, border_color: $colors.fg} } ) - ['--set' $"space.($sid)"] + ['--set', $"space.($sid)"] | append ( if (($icons | is-empty) and ($sid != $focused_sid)) { [ - background.drawing=off - label= - padding_left=-2 - padding_right=-2 + background.drawing=off, + label=, + padding_left=-2, + padding_right=-2, ] } else { [ - background.drawing=on - label=($icons) - label.highlight=($extra.highlight) - padding_left=2 - padding_right=2 + background.drawing=on, + label=($icons), + label.highlight=($extra.highlight), + padding_left=2, + padding_right=2, ] } ) @@ -50,22 +50,22 @@ def modify_args_per_workspace [ } def workspace_modification_args [ - name: string - last_sid: string + name: string, + last_sid: string, ]: nothing -> list { # use listener's label to store last focused space id let focused_sid = (aerospace list-workspaces --focused) let ids_to_modify = ( if ($last_sid | is-empty) { (aerospace list-workspaces --all | lines) } else { - [$focused_sid $last_sid] + [$focused_sid, $last_sid] } ) $ids_to_modify | uniq | each { modify_args_per_workspace $in $focused_sid } | flatten - | append ["--set" $name $"label=($focused_sid)"] + | append ["--set", $name, $"label=($focused_sid)"] } # remained for other possible signals diff --git a/test/input_comment.nu b/test/input_comment.nu index 08accc3..4ed61c2 100644 --- a/test/input_comment.nu +++ b/test/input_comment.nu @@ -4,6 +4,7 @@ # multiline def foo_bar [ # comment at [ foo: string # comment for arg + # 2nd comment for arg foo bar: int # another comment ] { # comment at { # comment in body diff --git a/test/input_data.nu b/test/input_data.nu index cac6b54..06f58e5 100644 --- a/test/input_data.nu +++ b/test/input_data.nu @@ -248,6 +248,8 @@ export const config = { } const table = [[a b]; [1 2] [2 [4 4]]] +const multi_line_table = [[a b]; [1 2] + [2 [4 4]]] const table_no_row = [[a b];] mut foo : record<"a", b "c": int d: list> = {} diff --git a/toolkit.nu b/toolkit.nu index 751369b..ae3c199 100644 --- a/toolkit.nu +++ b/toolkit.nu @@ -3,7 +3,7 @@ use std assert const script_pwd = path self . def run_ide_check [ - file: path + file: path, ] { nu --ide-check 9999 $file | lines @@ -14,12 +14,12 @@ def run_ide_check [ } def print_progress [ - ratio: float - length: int = 20 + ratio: float, + length: int = 20, ] { let done = '▓' let empty = '░' - let count = [1 (($ratio * $length) | into int)] | math max + let count = [1, (($ratio * $length) | into int)] | math max ( print -n ('' | fill -c $done -w $count) @@ -31,7 +31,7 @@ def print_progress [ # Test the topiary formatter with all nu files within a directory # each script should pass the idempotent check as well as the linter export def test_format [ - path: path # path to test + path: path, # path to test ] { $env.TOPIARY_CONFIG_FILE = ($script_pwd | path join languages.ncl) $env.TOPIARY_LANGUAGE_DIR = ($script_pwd | path join languages) @@ -45,28 +45,29 @@ export def test_format [ print $"No nu scripts found in (ansi yellow)($path).(ansi reset)" return } - let all_passed = 1..$len | par-each {|i| - let file = $files | get ($i - 1) - let target = $"(random uuid).nu" - if ($i mod 10) == 0 { - print -n $"(ansi -e '1000D')" - print_progress ($i / $len) + let all_passed = 1..$len + | par-each {|i| + let file = $files | get ($i - 1) + let target = $"(random uuid).nu" + if ($i mod 10) == 0 { + print -n $"(ansi -e '1000D')" + print_progress ($i / $len) + } + let failed = try { + cp $file $target + let err_before = run_ide_check $target + topiary format $target + let err_after = run_ide_check $target + assert ($err_before == $err_after) + true + } catch { + print $"(ansi red)Error detected: (ansi yellow)($file)(ansi reset)" + false + } + rm $target + $failed } - let failed = try { - cp $file $target - let err_before = run_ide_check $target - topiary format $target - let err_after = run_ide_check $target - assert ($err_before == $err_after) - true - } catch { - print $"(ansi red)Error detected: (ansi yellow)($file)(ansi reset)" - false - } - rm $target - $failed - } - | all { $in } + | all { $in } if $all_passed { print -n $"(ansi -e '1000D')" print $"(ansi green)All nu scripts successfully passed the check, but style issues are still possible.(ansi reset)"