Documentation
¶
Index ¶
- Variables
- func Include(pathname string, include, exclude []string) (bool, error)
- func Intersects(a, b Range) bool
- func RulesMapFromHunks(hunks []Hunk, options LintOptions) (map[string][]Rule, map[string]struct{}, error)
- func TargetKey(pathname string, target Target) string
- func Walk(root string, include []string, exclude []string, callback filepath.WalkFunc) error
- type ExtFileJSON
- type ExtMap
- type Hunk
- type LintOptions
- type LintResult
- type Range
- type Rule
- type Target
- type UnsatisfiedRule
- type UnsatisfiedRules
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultTemplates is the default list of directive templates. DefaultTemplates = []string{ "#LINT.?", "//LINT.?", "/*LINT.?", "<!--LINT.?", "'LINT.?", } // DefaultFileExtMap is the default map of file extensions to directive templates. DefaultFileExtMap = map[string][]int{ "py": {0}, "sh": {0}, "go": {1}, "js": {1, 2}, "jsx": {1, 2}, "mjs": {1, 2}, "ts": {1, 2}, "tsx": {1, 2}, "jsonc": {1, 2}, "c": {1, 2}, "cc": {1, 2}, "cpp": {1, 2}, "h": {1, 2}, "hpp": {1, 2}, "java": {1}, "rs": {1}, "swift": {1}, "svelte": {1, 2, 3}, "css": {2}, "html": {3}, "md": {3}, "markdown": {3}, "bas": {4}, } )
Functions ¶
func Intersects ¶
Intersects returns true if the given ranges intersect.
func RulesMapFromHunks ¶
func RulesMapFromHunks(hunks []Hunk, options LintOptions) (map[string][]Rule, map[string]struct{}, error)
RulesMapFromHunks parses rules from the given hunks by file name and returns the map of rules and the set of all the target keys that are present.
Types ¶
type ExtFileJSON ¶
ExtFileJSON is a JSON representation of a file extension to directive template map.
type ExtMap ¶
type ExtMap struct {
// Templates is the list of directive templates.
Templates []string
// FileExtMap is a map of file extensions to directive templates.
FileExtMap map[string][]int
}
ExtMap represents the extensions and templates for a linting operation.
type Hunk ¶
type Hunk struct {
// File specifier of the defined range.
File string
// Range of code in which a diff hunk intersects.
Range Range
}
Hunk represents a diff hunk that must be present in the diff.
type LintOptions ¶
type LintOptions struct {
// Reader is the reader from which the diff is read.
Reader io.Reader
// Include is a list of file patterns to include in the linting.
Include []string
// Exclude is a list of file patterns to exclude from the linting.
Exclude []string
// Templates is the list of directive templates.
Templates []string // []string{"//LINT.?", "#LINT.?", "<!-- LINT.? -->"}
// FileExtMap is a map of file extensions to directive templates.
FileExtMap map[string][]int // map[string][]int{".go": []int{0}, ".py": []int{1}}
// DefaultTemplate is the default directive template.
DefaultTemplate int
}
LintOptions represents the options for a linting operation.
func (*LintOptions) TemplatesFromFile ¶
func (o *LintOptions) TemplatesFromFile(file string) ([]string, error)
TemplatesFromFile returns the directive templates for the given file type.
type LintResult ¶
type LintResult struct {
// List of rules that were not satisfied.
UnsatisfiedRules UnsatisfiedRules
}
Result of a linting operation.
func Lint ¶
func Lint(o LintOptions) (*LintResult, error)
Lint lints the given hunks against the given rules and returns the result.
type Rule ¶
type Rule struct {
// Hunk is the diff hunk that must be present in the diff.
Hunk Hunk
// Targets are the files or ranges of code that must be present in the diff if the hunk is present.
Targets []Target
// Present is true if the change is present in the diff from which the rules were parsed.
Present bool
// ID is an optional, unique identifier for the rule.
ID *string
}
A rule says that file or range of code must be present in the diff if another range is present.
type Target ¶
type Target struct {
// File specifier expected to contain a diff hunk.
File *string
// ID is the ID of the range of code in which a diff hunk intersects.
ID *string
}
Target represents a file or range of code that must be present in the diff if a diff hunk is present.
type UnsatisfiedRule ¶
type UnsatisfiedRule struct {
// Rule that is not satisfied.
Rule
// UnsatisfiedTargets is the list of target indices that are not satisfied.
UnsatisfiedTargets map[int]struct{}
}
UnsatisfiedRule represents a rule that is not satisfied.
type UnsatisfiedRules ¶ added in v0.0.2
type UnsatisfiedRules []UnsatisfiedRule
UnsatisfiedRules is a list of unsatisfied rules.
func Check ¶
func Check(rulesMap map[string][]Rule, targetsMap map[string]struct{}) (UnsatisfiedRules, error)
Check returns the list of unsatisfied rules for the given map of rules.
func (*UnsatisfiedRules) String ¶ added in v0.0.2
func (r *UnsatisfiedRules) String() string
String returns a string representation of the unsatisfied rules.