old

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2020 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package old is an old (v0.1.0) copy of the licensecheck package, for easier comparison with the new Scan API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Checker

type Checker struct {
	// contains filtered or unexported fields
}

A Checker matches a set of known licenses.

func New

func New(licenses []License) *Checker

New returns a new Checker that recognizes the given list of licenses.

func (*Checker) Cover

func (c *Checker) Cover(input []byte, opts Options) (Coverage, bool)

Cover is like the top-level function Cover, but it uses the set of licenses in the Checker instead of the built-in license set.

type Coverage

type Coverage struct {
	// Percent is the fraction of the total text, in normalized words, that
	// matches any valid license, expressed as a percentage across all of the
	// licenses matched.
	Percent float64

	// Match describes, in sequential order, the matches of the input text
	// across the various licenses. Typically it will be only one match long,
	// but if the input text is a concatenation of licenses it will contain
	// a match value for each element of the concatenation.
	Match []Match
}

Coverage describes how the text matches various licenses.

func Cover

func Cover(input []byte, opts Options) (Coverage, bool)

Cover computes the coverage of the text according to the license set compiled into the package.

An input text may match multiple licenses. If that happens, Match contains only disjoint matches. If multiple licenses match a particular section of the input, the best match is chosen so the returned coverage describes at most one match for each section of the input.

type License

type License struct {
	Name string
	Text string
	URL  string
}

A License describes a single license that can be recognized. At least one of the Text or the URL should be set.

func BuiltinLicenses

func BuiltinLicenses() []License

BuiltinLicenses returns the list of licenses built into the package. That is, the built-in checker is equivalent to New(BuiltinLicenses()).

type Match

type Match struct {
	Name    string  // The (file) name of the license it matches.
	Type    Type    // The type of the license: BSD, MIT, etc.
	Percent float64 // The fraction of words between Start and End that are matched.
	Start   int     // The byte offset of the first word in the input that matches.
	End     int     // The byte offset of the end of the last word in the input that matches.
	// IsURL reports that the matched text identifies a license by indirection
	// through a URL. If set, Start and End specify the location of the URL
	// itself, and Percent is always 100.0.
	IsURL bool
}

Match describes how a section of the input matches a license.

type Options

type Options struct {
	MinLength int // Minimum length of run, in words, to count as a matching substring.
	Threshold int // Percentage threshold to report a match.
	Slop      int // Maximum allowable gap in a near-contiguous match.
}

Options allow us to adjust parameters for the matching algorithm. TODO: Delete this once the package has been fine-tuned.

type Type

type Type int

Type groups the licenses into various classifications. TODO: This list is clearly incomplete.

const (
	AGPL Type = iota
	Apache
	BSD
	CC
	GPL
	JSON
	MIT
	Unlicense
	Zlib
	Other
	NumTypes = Other
)

func (Type) String

func (i Type) String() string

Jump to

Keyboard shortcuts

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