Skip to content

add function ValidateAndNormalizeLicensesWithOptions#149

Merged
elrayle merged 5 commits into
mainfrom
elr/normalize
May 13, 2026
Merged

add function ValidateAndNormalizeLicensesWithOptions#149
elrayle merged 5 commits into
mainfrom
elr/normalize

Conversation

@elrayle
Copy link
Copy Markdown
Collaborator

@elrayle elrayle commented May 12, 2026

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 return true | false to 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 ValidateAndNormalizeLicensesWithOptions function 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.

Copilot AI review requested due to automatic review settings May 12, 2026 19:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ValidateLicensesWithOptions to delegate to a new ValidateAndNormalizeLicensesWithOptions API 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

Comment thread spdxexp/satisfies.go Outdated
Comment thread spdxexp/node.go Outdated
Copy link
Copy Markdown

@ljones140 ljones140 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. A minor nit on the tests.

Comment thread spdxexp/satisfies_test.go Outdated
@elrayle elrayle merged commit dbbda01 into main May 13, 2026
5 checks passed
@elrayle elrayle deleted the elr/normalize branch May 13, 2026 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants