Conversation
This adds a simple cli to the package called `spdx-validate`. It takes a string or an input file containing spdx expressions and runs the `ValidateLicenses` function on them, presenting errors if they fail validation. (Disclosure: Coded with Claude Opus 4.6)
There was a problem hiding this comment.
Pull request overview
Adds a new spdx-validate command-line tool to validate SPDX license expressions using the existing spdxexp.ValidateLicenses API, with README documentation and accompanying tests.
Changes:
- Introduce
cmd/spdx-validateCobra-based CLI supporting stdin (single expression) and--file(newline-separated expressions). - Add unit/integration-style tests for CLI validation helpers.
- Update module dependencies and README with build/usage instructions.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| go.mod | Adds Cobra (and indirect deps) needed for the new CLI. |
| go.sum | Records new dependency checksums. |
| cmd/spdx-validate/main.go | Implements the spdx-validate CLI and validation helpers. |
| cmd/spdx-validate/main_test.go | Adds tests for the validation helper functions. |
| README.md | Documents the new CLI build and usage. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cmd/spdx-validate/main.go
Outdated
| scanner := bufio.NewScanner(r) | ||
| if !scanner.Scan() { |
There was a problem hiding this comment.
validateSingleExpression treats any scanner.Scan() failure as "no input provided" without checking scanner.Err(). This can hide real read errors (including bufio.ErrTooLong when the line exceeds the scanner token limit). Check scanner.Err() when Scan() returns false and return a wrapped read error when present; consider increasing the scanner buffer if long lines are plausible.
| scanner := bufio.NewScanner(r) | |
| if !scanner.Scan() { | |
| scanner := bufio.NewScanner(r) | |
| // Increase the scanner buffer to better handle long expressions. | |
| scanner.Buffer(make([]byte, 0, 64*1024), 1024*1024) | |
| if !scanner.Scan() { | |
| if err := scanner.Err(); err != nil { | |
| return false, fmt.Errorf("failed to read input: %w", err) | |
| } |
There was a problem hiding this comment.
there's not going to be a 64mb spdx expression.
dangoor
left a comment
There was a problem hiding this comment.
Copilot has some good suggestions here, but I'm not concerned about them if this is going to stay just a tool for spot checking things.
The previous split code path was left over from my initial attempts. now stdin is treated like a newline-separated file rather than being special-cased, so the tool can accept multiple lines from a shell pipeline or a file.
|
Closing this in favour of a local branch rather than a forked one. Note that the way the repo is configured, any external contributor's PR will be blocked due to the codeql setup, as @elrayle found on #129 . Copilot says: PR #136 is a cross-fork PR (from Meanwhile, branch protection rules on main likely require the CodeQL check to pass before merging, creating a deadlock: the check is required but can never run. How to UnblockThere are a few options (roughly ordered by ease):
Recommended: Option 1 (admin bypass) is the quickest fix for this specific PR. For a longer-term solution, option 2 (pushing branches directly to the repo) avoids this problem entirely for contributors with write access. |
This adds a simple cli to the package called
spdx-validate. It takes a string or an input file containing spdx expressions and runs theValidateLicensesfunction on them, presenting errors if they fail validation.(Disclosure: Coded with Claude Opus 4.6)