From cf32a2e7f7a9ce67836f95acace9b39c77bf5178 Mon Sep 17 00:00:00 2001 From: NotTheDr01ds <32344964+NotTheDr01ds@users.noreply.github.com> Date: Sun, 16 Feb 2025 12:38:53 -0500 Subject: [PATCH 1/2] Fix failing lints on source files --- .github/workflows/ci.yml | 2 +- toolkit.nu | 34 +++++++++++++++++++++++----------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8890aa076..30a43457a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,4 +24,4 @@ jobs: # nix STUB_IDE_CHECK when nushell/nushell#12208 fixed run: | use ${{ github.workspace }}/toolkit.nu * - STUB_IDE_CHECK=true check pr --and-exit + check pr --and-exit diff --git a/toolkit.nu b/toolkit.nu index 037616ef5..3266ab9bc 100644 --- a/toolkit.nu +++ b/toolkit.nu @@ -66,22 +66,34 @@ def "with files" [ } } -# Check the input file with nu --ide-check. -export def "lint ide-check" []: path -> int { +export def "lint check" []: path -> int { let file = $in - let stub = $env.STUB_IDE_CHECK? | default false | into bool + let test_methodology = $env.TEST_METHOD? | default "source-or-import" const current_path = (path self) - let diagnostics = if $stub { - do { nu --no-config-file --commands $"use '($file)'" } - | complete - | [[severity message]; [$in.exit_code $in.stderr]] - | where severity != 0 - } else { - nu --ide-check 10 $file + + let diagnostics = match $test_methodology { + ide-check => { + nu --ide-check 10 $file | $"[($in)]" | from nuon | where type == diagnostic | select severity message + } + + source-or-import => { + # If any line in the file starts with `export`, then + # we assume it is a module. Otherwise, treat it as source + let has_exports = (open $file | $in like '(?m)^export\s') + let use_or_source = match $has_exports { + true => {{|| do { nu --no-config-file --commands $"use '($file)'" } | complete }} + false => {{|| do { nu --no-config-file --commands $"source '($file)'" } | complete }} + } + do $use_or_source + | [[severity message]; [$in.exit_code $in.stderr]] + | where severity != 0 + } + + _ => { error make { msg: "Invalid TEST_METHOD"}} } let error_count = $diagnostics | length if $error_count == 0 { @@ -101,6 +113,6 @@ export def lint [ --and-exit # Exit with error count ]: [list -> int, nothing -> int] { with files --full=$full --and-exit=$and_exit { - par-each { lint ide-check } + par-each { lint check } } } From 3e7705c8141f8d5a47dab37d13a2fd1f854f1a82 Mon Sep 17 00:00:00 2001 From: NotTheDr01ds <32344964+NotTheDr01ds@users.noreply.github.com> Date: Sun, 16 Feb 2025 17:22:48 -0500 Subject: [PATCH 2/2] nu-check before parse --- toolkit.nu | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/toolkit.nu b/toolkit.nu index 3266ab9bc..4a5716c88 100644 --- a/toolkit.nu +++ b/toolkit.nu @@ -68,7 +68,7 @@ def "with files" [ export def "lint check" []: path -> int { let file = $in - let test_methodology = $env.TEST_METHOD? | default "source-or-import" + let test_methodology = $env.TEST_METHOD? | default "import-or-source" const current_path = (path self) let diagnostics = match $test_methodology { @@ -80,17 +80,26 @@ export def "lint check" []: path -> int { | select severity message } - source-or-import => { + import-or-source => { # If any line in the file starts with `export`, then # we assume it is a module. Otherwise, treat it as source let has_exports = (open $file | $in like '(?m)^export\s') - let use_or_source = match $has_exports { - true => {{|| do { nu --no-config-file --commands $"use '($file)'" } | complete }} - false => {{|| do { nu --no-config-file --commands $"source '($file)'" } | complete }} + if $has_exports { + # treat as module + if not (nu-check --as-module $file) { + do { nu --no-config-file --commands $"use '($file)'" } + | complete + | [[severity message]; [$in.exit_code $in.stderr]] + | where severity != 0 + } + } else { + if not (nu-check $file) { + do { nu --no-config-file --commands $"source '($file)'" } + | complete + | [[severity message]; [$in.exit_code $in.stderr]] + | where severity != 0 + } } - do $use_or_source - | [[severity message]; [$in.exit_code $in.stderr]] - | where severity != 0 } _ => { error make { msg: "Invalid TEST_METHOD"}}