add function ValidateAndNormalizeLicensesWithOptions#149
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a new validation API that both validates SPDX license inputs and returns a normalized, deduplicated list of valid licenses while separately reporting invalid entries. It also extends expression reconstruction so normalized output can include properly-parenthesized SPDX expressions.
Changes:
- Refactors
ValidateLicensesWithOptionsto delegate to a newValidateAndNormalizeLicensesWithOptionsAPI that returns(normalizedValid, invalid)lists. - Adds normalization/deduplication behavior for valid licenses (including expressions via
parse(...).reconstructedLicenseString()). - Extends
node.reconstructedLicenseString()to support expression nodes and adds tests covering expression reconstruction and the new validation API.
Show a summary per file
| File | Description |
|---|---|
spdxexp/satisfies.go |
Adds ValidateAndNormalizeLicensesWithOptions and refactors existing validation to use it. |
spdxexp/satisfies_test.go |
Adds tests for normalized+invalid outputs across option combinations and dedup behavior. |
spdxexp/node.go |
Adds expression reconstruction support (including precedence/parentheses) used for normalization. |
spdxexp/node_test.go |
Adds coverage for expression reconstruction output/parentheses behavior. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 4/4 changed files
- Comments generated: 2
ljones140
approved these changes
May 13, 2026
ljones140
left a comment
There was a problem hiding this comment.
Looks great. A minor nit on the tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When validating licenses, a license can be valid (e.g. "mit") but not the canonical license (e.g. "MIT"). The existing
ValidateLicenses*functions only returntrue | falseto indicate that all the licenses were valid (true) or at least one license was invalid (false). In the case of invalid licenses, the list of invalid licenses is returned.The new
ValidateAndNormalizeLicensesWithOptionsfunction returns a list normalized valid licenses and a list of invalid licenses. It also dedupes the valid licenses, so that if "MIT" and "mit" are both passed in, there is only one "MIT" license in the normalized license list.