Skip to content

feat: fallback license file search for COPYING, LICENCE, etc.#12

Open
orius123 wants to merge 1 commit intoaviadl:masterfrom
orius123:feat/license-file-fallback
Open

feat: fallback license file search for COPYING, LICENCE, etc.#12
orius123 wants to merge 1 commit intoaviadl:masterfrom
orius123:feat/license-file-fallback

Conversation

@orius123
Copy link
Contributor

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 that go-license doesn't recognize:

  • COPYING (used by many GNU projects)
  • LICENCE (British spelling)
  • LICENSE.md / LICENSE.txt
  • MIT-LICENSE, LICENSE-APACHE

Without 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.NewFromDir fails, so existing detection is unaffected.

Builds on top of PR #11 (go-mode list support).

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.
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.

2 participants