licensecheck

package
v0.22.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2025 License: MPL-2.0 Imports: 7 Imported by: 0

README

License Check

This module provides helper functions to validating and remediating any problems with a LICENSE file.

Entry

The Entry(dirPath string) function takes in a directory path and will do the following:

  • Check if any files appear to be licenses
  • If no files are found, a stubbed out addLicenseFile function is called
  • If a file is found but it does not adhere to the LICENSE desired nomenclature, it will be renamed
  • If a file is found that matches the desired naming scheme, it is left alone
  • If multiple files are found, an error will be returned

License File Criteria

Potential LICENSE files are found by searching all files in a directory to find matching files with the name LICENSE with or without .txt or .md extensions in a case-insensitive manner. As an example, the following all qualify:

  • LICENSE
  • LICENSE.txt
  • LICENSE.md
  • license.TXT
  • LiCeNsE (for those who woke up and chose chaos)

Testing

Due to the nature of mutating the filesystem, some functions in this module are not suited to being tested with a more common testdata paradigm. Instead, testing/TempDir() is used to generate an ephemeral testing directory for each sub-test.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddHeader

func AddHeader(filePath string, header string) error

AddHeader prepends a given string to a file. It will automatically handle newline characters

func AddLicenseFile

func AddLicenseFile(dirPath string, spdxID string) (string, error)

AddLicenseFile creates a file named "LICENSE" in the target directory pre-populated with license text based on the SPDX Identifier you supply. Returns the fully qualified path to the license file it created

NOTE: this function will NOT add a copyright statement for you. You must manually call AddHeader() afterward if you wish to have copyright headers

func EnsureCorrectName

func EnsureCorrectName(filePath string) (string, error)

EnsureCorrectName fixes a malformed license file name and returns the new (corrected) file path E.g., "license.txt" --> "LICENSE"

func FindLicenseFiles

func FindLicenseFiles(dirPath string) ([]string, error)

FindLicenseFiles returns a list of filepaths for licenses in a given directory

func HasCopyright

func HasCopyright(filePath string) (bool, error)

HasCopyright reports whether or not a file contains a copyright statement It makes no promises as to the validity of the copyright statement, however! If you wish to validate the contents of the statement, use hasValidCopyright

func HasMatchingCopyright

func HasMatchingCopyright(filePath string, copyrightStatement string, caseSensitive bool) (bool, error)

HasMatchingCopyright takes an explicit copyright statement and validates that a given file contains that string in the header (first 1k chars)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL