package
0.19.0
Repository: https://github.com/hashicorp/copywrite.git
Documentation: pkg.go.dev

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

# Functions

AddHeader prepends a given string to a file.
AddLicenseFile creates a file named "LICENSE" in the target directory pre-populated with license text based on the SPDX Identifier you supply.
EnsureCorrectName fixes a malformed license file name and returns the new (corrected) file path E.g., "license.txt" --> "LICENSE".
FindLicenseFiles returns a list of filepaths for licenses in a given directory.
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.
HasMatchingCopyright takes an explicit copyright statement and validates that a given file contains that string in the header (first 1k chars).