Documentation ¶
Overview ¶
Package core contains configuration and utility internals.
Index ¶
- Variables
- func AllStringsInSlice(strings []string, slice []string) bool
- func CapFirst(s string) string
- func CondSprintf(format string, v ...interface{}) string
- func FileExists(filename string) bool
- func FindAsset(cfg *Config, path string) string
- func FormatAlert(a *Alert, limit int, level, name string)
- func FormatFromExt(path string, mapping map[string]string) (string, string)
- func FormatMessage(msg string, subs ...string) string
- func FromFile(cfg *Config, dry bool) (*ini.File, error)
- func FromString(src string, cfg *Config, dry bool) (*ini.File, error)
- func GetPackages(src string) ([]string, error)
- func HasAnySuffix(s string, suffixes []string) bool
- func InRange(n int, r []int) bool
- func Indent(text, indent string) string
- func IntInSlice(a int, slice []int) bool
- func IsDir(filename string) bool
- func IsLetter(s string) bool
- func IsPhrase(s string) bool
- func NewE100(context string, err error) error
- func NewE201(msg, value, path string, finder errorCondition) error
- func NewE201FromPosition(msg, file string, goal int) error
- func NewE201FromTarget(msg, value, file string) error
- func NewError(code, title, msg string) error
- func ReplaceAllStringSubmatchFunc(re *regexp.Regexp, str string, repl func([]string) string) string
- func Sanitize(txt string) string
- func ShouldIgnoreDirectory(directoryName string) bool
- func SplitLines(data []byte, atEOF bool) (adv int, token []byte, err error)
- func StringInSlice(a string, slice []string) bool
- func StringsToInterface(strings []string) []interface{}
- func StripANSI(s string) string
- func Substitute(src, sub string, char rune) (string, bool)
- func TextToContext(text string, meta *nlp.Info) []nlp.TaggedWord
- func ToSentence(words []string, andOrOr string) string
- func Which(cmds []string) string
- func WhitespaceToSpace(msg string) string
- type Action
- type Alert
- type ByName
- type ByPosition
- type CLIFlags
- type Config
- type ConfigSrc
- type File
- func (f *File) AddAlert(a Alert, blk nlp.Block, lines, pad int, lookup bool)
- func (f *File) ComputeMetrics() (map[string]interface{}, error)
- func (f *File) FindLoc(ctx, s string, pad, count int, a Alert) (int, []int)
- func (f *File) QueryComments(check string) bool
- func (f *File) ResetComments()
- func (f *File) SetText(s string)
- func (f *File) SortedAlerts() []Alert
- func (f *File) UpdateComments(comment string)
Constants ¶
This section is empty.
Variables ¶
var AlertLevels = []string{"suggestion", "warning", "error"}
AlertLevels holds the possible values for "level" in an external rule.
var CommentsByNormedExt = map[string]map[string]string{
".c": {
"inline": `(?:^|\s)(?:(//.+)|(/\*.+\*/))`,
"blockStart": `(/\*.*)`,
"blockEnd": `(.*\*/)`,
},
".clj": {
"inline": `(;+.+)`,
"blockStart": `$^`,
"blockEnd": `$^`,
},
".css": {
"inline": `(/\*.+\*/)`,
"blockStart": `(/\*.*)`,
"blockEnd": `(.*\*/)`,
},
".rs": {
"inline": `(//.+)`,
"blockStart": `$^`,
"blockEnd": `$^`,
},
".r": {
"inline": `(#.+)`,
"blockStart": `$^`,
"blockEnd": `$^`,
},
".py": {
"inline": `(#.*)|('{3}.+'{3})|("{3}.+"{3})`,
"blockStart": `(?m)^((?:\s{4,})?[r]?["']{3}.*)$`,
"blockEnd": `(.*["']{3})`,
},
".ps1": {
"inline": `(#.+)`,
"blockStart": `(<#.*)`,
"blockEnd": `(.*#>)`,
},
".php": {
"inline": `(//.+)|(/\*.+\*/)|(#.+)`,
"blockStart": `(/\*.*)`,
"blockEnd": `(.*\*/)`,
},
".lua": {
"inline": `(-- .+)`,
"blockStart": `(-{2,3}\[\[.*)`,
"blockEnd": `(.*\]\])`,
},
".hs": {
"inline": `(-- .+)`,
"blockStart": `(\{-.*)`,
"blockEnd": `(.*-\})`,
},
".rb": {
"inline": `(#.+)`,
"blockStart": `(^=begin)`,
"blockEnd": `(^=end)`,
},
".jl": {
"inline": `(# .+)`,
"blockStart": `(^#=)|(^(?:@doc )?(?:raw)?["']{3}.*)`,
"blockEnd": `(^=#)|(.*["']{3})`,
},
}
CommentsByNormedExt determines what parts of a file we should lint -- e.g., we only want to lint // or /* comments in a C++ file. Multiple formats are mapped to a single extension (e.g., .java -> .c) because many languages use the same comment delimiters.
var FormatByExtension = map[string][]string{
`\.(?:[rc]?py[3w]?|[Ss][Cc]onstruct)$`: {".py", "code"},
`\.(?:adoc|asciidoc|asc)$`: {".adoc", "markup"},
`\.(?:cpp|cc|c|cp|cxx|c\+\+|h|hpp|h\+\+)$`: {".c", "code"},
`\.(?:cs|csx)$`: {".c", "code"},
`\.(?:clj|cljs|cljc|cljd)$`: {".clj", "code"},
`\.(?:css)$`: {".css", "code"},
`\.(?:go)$`: {".c", "code"},
`\.(?:html|htm|shtml|xhtml)$`: {".html", "markup"},
`\.(?:rb|Gemfile|Rakefile|Brewfile|gemspec)$`: {".rb", "code"},
`\.(?:java|bsh)$`: {".c", "code"},
`\.(?:js|jsx)$`: {".c", "code"},
`\.(?:lua)$`: {".lua", "code"},
`\.(?:md|mdown|markdown|markdn)$`: {".md", "markup"},
`\.(?:php)$`: {".php", "code"},
`\.(?:pl|pm|pod)$`: {".r", "code"},
`\.(?:ps1|psm1|psd1)$`: {".ps1", "code"},
`\.(?:r|R)$`: {".r", "code"},
`\.(?:rs)$`: {".rs", "code"},
`\.(?:rst|rest)$`: {".rst", "markup"},
`\.(?:swift)$`: {".c", "code"},
`\.(?:ts|tsx)$`: {".c", "code"},
`\.(?:txt)$`: {".txt", "text"},
`\.(?:sass|less)$`: {".c", "code"},
`\.(?:scala|sbt)$`: {".c", "code"},
`\.(?:hs)$`: {".hs", "code"},
`\.(?:xml)$`: {".xml", "markup"},
`\.(?:dita)$`: {".dita", "markup"},
`\.(?:org)$`: {".org", "markup"},
`\.(?:jl)$`: {".jl", "code"},
}
FormatByExtension associates a file extension with its "normed" extension and its format (markup, code or text).
var LevelToInt = map[string]int{
"suggestion": 0,
"warning": 1,
"error": 2,
}
LevelToInt allows us to easily compare levels in lint.go.
Functions ¶
func AllStringsInSlice ¶
AllStringsInSlice determines if `slice` contains the `strings`.
func CondSprintf ¶
CondSprintf is sprintf, ignores extra arguments.
func FileExists ¶
FileExists determines if the path given by `filename` exists.
func FindAsset ¶
FindAsset tries to locate a Vale-related resource by looking in the user-defined StylesPath.
func FormatAlert ¶
FormatAlert ensures that all required fields have data.
func FormatFromExt ¶
FormatFromExt takes a file extension and returns its [normExt, format] list, if supported.
func FormatMessage ¶
FormatMessage inserts `subs` into `msg`.
func FromString ¶ added in v2.30.0
FromString loads an INI configuration from a string.
func GetPackages ¶ added in v2.16.0
Get the user-defined packages from a `.vale.ini` file.
func HasAnySuffix ¶ added in v2.29.3
func IntInSlice ¶
IntInSlice determines if `slice` contains the int `a`.
func IsPhrase ¶
IsPhrase returns `true` is s is a phrase-like token.
This is used to differentiate regex tokens from non-regex.
func NewE100 ¶
NewE100 creates a new, formatted "unexpected" error.
Since E100 errors can occur anywhere, we include a "context" that makes it clear where exactly the error was generated.
func NewE201 ¶
NewE201 creates a formatted user-generated error.
201 errors involve a specific configuration asset and should contain parsable location information on their last line of the form:
<path>:<line>:<start>:<end>
func NewE201FromPosition ¶
NewE201FromPosition creates a new E201 error from an in-file location.
func NewE201FromTarget ¶
NewE201FromTarget creates a new E201 error from a target string.
func NewError ¶
NewError creates a colored error from the given information.
The standard format is ¶
``` <code> [<context>] <title>
<msg> ```
func ReplaceAllStringSubmatchFunc ¶ added in v2.16.1
func ShouldIgnoreDirectory ¶
ShouldIgnoreDirectory will check if directory should be ignored
func SplitLines ¶
SplitLines splits on CRLF, CR not followed by LF, and LF.
func StringInSlice ¶
StringInSlice determines if `slice` contains the string `a`.
func StringsToInterface ¶
func StringsToInterface(strings []string) []interface{}
StringsToInterface converts a slice of strings to an interface.
func Substitute ¶
Substitute replaces the substring `sub` with a string of asterisks.
func TextToContext ¶ added in v2.10.3
func TextToContext(text string, meta *nlp.Info) []nlp.TaggedWord
func ToSentence ¶
ToSentence converts a slice of terms into sentence.
func WhitespaceToSpace ¶
WhitespaceToSpace converts newlines and multiple spaces (e.g., " ") into a single space.
Types ¶
type Action ¶
type Action struct { Name string // the name of the action -- e.g, 'replace' Params []string // a slice of parameters for the given action }
An Action represents a possible solution to an Alert.
type Alert ¶
type Alert struct { Action Action // a possible solution Span []int // the [begin, end] location within a line Offset []string `json:"-"` // tokens to ignore before this match Check string // the name of the check Description string // why `Message` is meaningful Link string // reference material Message string // the output message Severity string // 'suggestion', 'warning', or 'error' Match string // the actual matched text Line int // the source line Limit int `json:"-"` // the max times to report Hide bool `json:"-"` // should we hide this alert? }
An Alert represents a potential error in prose.
type ByPosition ¶
type ByPosition []Alert
ByPosition sorts Alerts by line and column.
func (ByPosition) Len ¶
func (a ByPosition) Len() int
func (ByPosition) Less ¶
func (a ByPosition) Less(i, j int) bool
func (ByPosition) Swap ¶
func (a ByPosition) Swap(i, j int)
type CLIFlags ¶
type CLIFlags struct { AlertLevel string Built string Glob string InExt string Output string Path string Sources string Filter string Local bool NoExit bool Normalize bool Relative bool Remote bool Simple bool Sorted bool Wrap bool Version bool Help bool }
CLIFlags holds the values that are defined at runtime by the user.
For example, `vale --minAlertLevel=error`.
type Config ¶
type Config struct { // General configuration BlockIgnores map[string][]string // A list of blocks to ignore Checks []string // All checks to load Formats map[string]string // A map of unknown -> known formats Asciidoctor map[string]string // A map of asciidoctor attributes FormatToLang map[string]string // A map of format to lang ID GBaseStyles []string // Global base style GChecks map[string]bool // Global checks IgnoredClasses []string // A list of HTML classes to ignore IgnoredScopes []string // A list of HTML tags to ignore MinAlertLevel int // Lowest alert level to display Vocab []string // The active project RuleToLevel map[string]string // Single-rule level changes SBaseStyles map[string][]string // Syntax-specific base styles SChecks map[string]map[string]bool // Syntax-specific checks SkippedScopes []string // A list of HTML blocks to ignore Stylesheets map[string]string // XSLT stylesheet StylesPath string // Directory with Rule.yml files TokenIgnores map[string][]string // A list of tokens to ignore WordTemplate string // The template used in YAML -> regexp list conversions RootINI string // the path to the project's .vale.ini file AcceptedTokens map[string]struct{} `json:"-"` // Project-specific vocabulary (okay) RejectedTokens map[string]struct{} `json:"-"` // Project-specific vocabulary (avoid) DictionaryPath string // Location to search for dictionaries. FallbackPath string `json:"-"` SecToPat map[string]glob.Glob `json:"-"` Styles []string `json:"-"` Paths []string `json:"-"` Root string `json:"-"` NLPEndpoint string // An external API to call for NLP-related work. // Command-line configuration Flags *CLIFlags `json:"-"` StyleKeys []string `json:"-"` RuleKeys []string `json:"-"` }
Config holds the configuration values from both the CLI and `.vale.ini`.
func (*Config) AddWordListFile ¶
AddWordListFile adds vocab terms from a provided file.
type File ¶
type File struct { NLP nlp.Info // - Summary bytes.Buffer // holds content to be included in summarization checks Alerts []Alert // all alerts associated with this file BaseStyles []string // base style assigned in .vale Lines []string // the File's Content split into lines Sequences []string // tracks various info (e.g., defined abbreviations) Content string // the raw file contents Format string // 'code', 'markup' or 'prose' NormedExt string // the normalized extension (see util/format.go) Path string // the full path Transform string // XLST transform RealExt string // actual file extension Checks map[string]bool // syntax-specific checks assigned in .vale ChkToCtx map[string]string // maps a temporary context to a particular check Comments map[string]bool // comment control statements Metrics map[string]int // count-based metrics Lookup bool // - // contains filtered or unexported fields }
A File represents a linted text file.
func (*File) ComputeMetrics ¶ added in v2.12.0
ComputeMetrics returns all of f's metrics.
func (*File) QueryComments ¶
QueryComments checks if there has been an in-text comment for this check.
func (*File) ResetComments ¶
func (f *File) ResetComments()
ResetComments resets the state of all checks back to active.
func (*File) SortedAlerts ¶
SortedAlerts returns all of f's alerts sorted by line and column.
func (*File) UpdateComments ¶
UpdateComments sets a new status based on comment.