feat: fallback license file search for COPYING, LICENCE, etc.#12
Open
orius123 wants to merge 1 commit intoaviadl:masterfrom
Open
feat: fallback license file search for COPYING, LICENCE, etc.#12orius123 wants to merge 1 commit intoaviadl:masterfrom
orius123 wants to merge 1 commit intoaviadl:masterfrom
Conversation
When license.NewFromDir fails, search the module directory for common license file names (COPYING, LICENCE, LICENSE.md, MIT-LICENSE, etc.) and read the content directly. This handles modules where go-license can't detect the file due to non-standard naming. Particularly useful in list mode where the module cache has isolated directories and parent-directory walk is not possible.
aviadl
approved these changes
Mar 16, 2026
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.
Summary
When
license.NewFromDir()fails to detect a license, search the module directory for common license file names and read the content directly.Why
In
-go-mode list, the module cache has isolated directories per module — no parent-directory walk is possible. Some modules use non-standard license file names thatgo-licensedoesn't recognize:COPYING(used by many GNU projects)LICENCE(British spelling)LICENSE.md/LICENSE.txtMIT-LICENSE,LICENSE-APACHEWithout this fallback, these modules require manual entries in
manualLicense.json.How
Added
findLicenseFile()which searches the directory for any of 13 common license file names (case-insensitive). If found, the content is read and stored directly — same as a manual license entry.The fallback only runs when
license.NewFromDirfails, so existing detection is unaffected.Builds on top of PR #11 (go-mode list support).