1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-01 06:37:46 +00:00

Fix failing lints on source files (#1049)

This PR updates the toolkit testing to:

* Determine whether to lint as a module or source file based on the
presence of any `export ` line in the file.
* Run `nu-check` on files before linting with `use <file>` or `source
<file>`
* Updates the environment variable to `TEST_METHOD` with options for
`ide-check` or `import-or-source`.
* Updates the default to `import-or-source` (was `ide-check`) to match
CI
* Removes environment variable from CI since this test method is now the
default.

With this in place we should have far fewer (false positive) failing CI
runs.
This commit is contained in:
Douglas 2025-02-17 09:14:30 -05:00 committed by GitHub
parent 446f06f34f
commit c17dcc3855
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 33 additions and 12 deletions

View file

@ -24,4 +24,4 @@ jobs:
# nix STUB_IDE_CHECK when nushell/nushell#12208 fixed # nix STUB_IDE_CHECK when nushell/nushell#12208 fixed
run: | run: |
use ${{ github.workspace }}/toolkit.nu * use ${{ github.workspace }}/toolkit.nu *
STUB_IDE_CHECK=true check pr --and-exit check pr --and-exit

View file

@ -66,22 +66,43 @@ def "with files" [
} }
} }
# Check the input file with nu --ide-check. export def "lint check" []: path -> int {
export def "lint ide-check" []: path -> int {
let file = $in let file = $in
let stub = $env.STUB_IDE_CHECK? | default false | into bool let test_methodology = $env.TEST_METHOD? | default "import-or-source"
const current_path = (path self) const current_path = (path self)
let diagnostics = if $stub {
do { nu --no-config-file --commands $"use '($file)'" } let diagnostics = match $test_methodology {
| complete ide-check => {
| [[severity message]; [$in.exit_code $in.stderr]] nu --ide-check 10 $file
| where severity != 0
} else {
nu --ide-check 10 $file
| $"[($in)]" | $"[($in)]"
| from nuon | from nuon
| where type == diagnostic | where type == diagnostic
| select severity message | select severity message
}
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')
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
}
}
}
_ => { error make { msg: "Invalid TEST_METHOD"}}
} }
let error_count = $diagnostics | length let error_count = $diagnostics | length
if $error_count == 0 { if $error_count == 0 {
@ -101,6 +122,6 @@ export def lint [
--and-exit # Exit with error count --and-exit # Exit with error count
]: [list<path> -> int, nothing -> int] { ]: [list<path> -> int, nothing -> int] {
with files --full=$full --and-exit=$and_exit { with files --full=$full --and-exit=$and_exit {
par-each { lint ide-check } par-each { lint check }
} }
} }