Documentation ¶
Index ¶
- Variables
- func AllStringsInSlice(strings []string, slice []string) bool
- func CheckAndClose(file *os.File) bool
- func CheckError(err error) bool
- func CheckPOS(loc []int, expected, text string) bool
- func ContainsAny(text string, slice []string) bool
- func CopyDir(srcFs afero.Fs, srcDirPath string, destFs afero.Fs, destDirPath string) error
- func CopyFile(srcFs afero.Fs, srcFilePath string, destFs afero.Fs, destFilePath string) error
- func DeterminePath(configPath string, keyPath string) string
- func DumpConfig(config *Config) string
- func FileExists(filename string) bool
- func FormatAlert(a *Alert, level int, name string)
- func FormatFromExt(path string, mapping map[string]string) (string, string)
- func FormatMessage(msg string, subs ...string) string
- func HasAnyPrefix(text string, slice []string) bool
- func InRange(n int, r []int) bool
- func Indent(text, indent string) string
- func IsDir(filename string) bool
- func IsLetter(s string) bool
- func JaroWinkler(ctx, sub string) (int, string)
- func LooksLikeStdin(s string) bool
- func Max(a, b int) int
- func Min(a, b int) int
- func PrepText(txt string) string
- func SlicesEqual(a, b []string) bool
- func SplitLines(data []byte, atEOF bool) (adv int, token []byte, err error)
- func Stat() bool
- func StringInSlice(a string, slice []string) bool
- func StringsToInterface(strings []string) []interface{}
- func Substitute(src, sub string, char rune) (string, bool)
- func TextToWords(text string) []string
- func Which(cmds []string) string
- type Alert
- type ByName
- type ByPosition
- type Config
- type File
- func (f *File) AddAlert(a Alert, ctx, txt string, lines, pad int)
- func (f *File) FindLoc(ctx, s string, pad, count int, loc []int) (int, []int)
- func (f *File) QueryComments(check string) bool
- func (f *File) ResetComments()
- func (f *File) SortedAlerts() []Alert
- func (f *File) UpdateComments(comment string)
- type Glob
- type Plugin
- type Selector
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": `(//.+)|(/\*.+\*/)`,
"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})`,
},
".php": {
"inline": `(//.+)|(/\*.+\*/)|(#.+)`,
"blockStart": `(/\*.*)`,
"blockEnd": `(.*\*/)`,
},
".lua": {
"inline": `(-- .+)`,
"blockStart": `(-{2,3}\[\[.*)`,
"blockEnd": `(.*\]\])`,
},
".hs": {
"inline": `(-- .+)`,
"blockStart": `(\{-.*)`,
"blockEnd": `(.*-\})`,
},
".rb": {
"inline": `(#.+)`,
"blockStart": `(^=begin)`,
"blockEnd": `(^=end)`,
},
}
CommentsByNormedExt determines what parts of a file we should lint -- e.g., we only want to lint // or /* comments in a C++ file. Multiple syntaxes are mapped to a single extension (e.g., .java -> .c) because many languages use the same comment delimiters.
var ExeDir string
ExeDir is our starting location.
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"},
`\.(?:css)$`: {".css", "code"},
`\.(?:go)$`: {".c", "code"},
`\.(?:html|htm|shtml|xhtml)$`: {".html", "markup"},
`\.(?:rb|Gemfile|Rakefile|Brewfile|gemspec)$`: {".rb", "code"},
`\.(?:java|bsh)$`: {".c", "code"},
`\.(?:js)$`: {".c", "code"},
`\.(?:lua)$`: {".lua", "code"},
`\.(?:md|mdown|markdown|markdn)$`: {".md", "markup"},
`\.(?:php)$`: {".php", "code"},
`\.(?:pl|pm|pod)$`: {".r", "code"},
`\.(?:r|R)$`: {".r", "code"},
`\.(?:rs)$`: {".rs", "code"},
`\.(?:rst|rest)$`: {".rst", "markup"},
`\.(?:swift)$`: {".c", "code"},
`\.(?:txt)$`: {".txt", "text"},
`\.(?:sass|less)$`: {".c", "code"},
`\.(?:scala|sbt)$`: {".c", "code"},
`\.(?:hs)$`: {".hs", "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.
var SentenceTokenizer = tokenize.NewPunktSentenceTokenizer()
SentenceTokenizer splits text into sentences.
var Tagger *tag.PerceptronTagger
Tagger tags a sentence.
We wait to initilize it until we need it since it's slow (~1s) and we may not need it.
var WordTokenizer = tokenize.NewRegexpTokenizer( `[\p{L}[\p{N}]+(?:\.\w{2,4}\b)|(?:[A-Z]\.){2,}|[\p{L}[\p{N}]+'[\p{L}[\p{N}]+|[\p{L}[\p{N}@]+`, false, true)
WordTokenizer splits text into words.
Functions ¶
func AllStringsInSlice ¶ added in v0.3.1
AllStringsInSlice determines if `slice` contains the `strings`.
func CheckAndClose ¶ added in v0.3.1
CheckAndClose closes `file` and prints any errors to stdout. A return value of true => no error.
func CheckError ¶ added in v0.3.1
CheckError prints any errors to stdout. A return value of true => no error.
func CheckPOS ¶ added in v0.11.0
CheckPOS determines if a match (as found by an extension point) also matches the expected part-of-speech in text.
func ContainsAny ¶ added in v0.5.0
ContainsAny determines if `text` contains any string in `slice`.
func DeterminePath ¶ added in v1.0.0
DeterminePath decides if `keyPath` is relative or absolute.
func DumpConfig ¶ added in v0.3.1
DumpConfig returns Vale's configuration in JSON format.
func FileExists ¶ added in v0.3.1
FileExists determines if the path given by `filename` exists.
func FormatAlert ¶ added in v1.4.0
FormatAlert ensures that all required fields have data.
func FormatFromExt ¶ added in v0.3.1
FormatFromExt takes a file extension and returns its [normExt, format] list, if supported.
func FormatMessage ¶ added in v0.3.1
FormatMessage inserts `subs` into `msg`.
func HasAnyPrefix ¶ added in v0.3.1
HasAnyPrefix determines if `text` has any prefix contained in `slice`.
func IsLetter ¶ added in v0.11.0
IsLetter returns `true` if s contains all letter characters and false if not.
func JaroWinkler ¶ added in v0.5.0
JaroWinkler searches `ctx` line-by-line for a JaroWinkler distance score greater than a particular threshold.
func LooksLikeStdin ¶ added in v0.11.0
LooksLikeStdin determines if s appears to be a string.
func SlicesEqual ¶ added in v0.11.0
SlicesEqual determines if the slices a and b are equal.
func SplitLines ¶ added in v0.4.1
SplitLines splits on CRLF, CR not followed by LF, and LF.
func StringInSlice ¶ added in v0.3.1
StringInSlice determines if `slice` contains the string `a`.
func StringsToInterface ¶ added in v0.3.1
func StringsToInterface(strings []string) []interface{}
StringsToInterface converts a slice of strings to an interface.
func Substitute ¶ added in v0.3.1
Substitute replaces the substring `sub` with a string of asterisks.
func TextToWords ¶ added in v0.11.0
TextToWords convert raw text into a slice of words.
Types ¶
type Alert ¶
type Alert struct { Check string // the name of the check Description string // why `Message` is meaningful Line int // the source line Link string // reference material Message string // the output message Severity string // 'suggestion', 'warning', or 'error' Span []int // the [begin, end] location within a line Hide bool // should we hide this alert? Match string // the actual matched text }
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 Config ¶ added in v0.3.1
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 GBaseStyles []string // Global base style GChecks map[string]bool // Global checks IgnoredScopes []string // A list of HTML tags to ignore MinAlertLevel int // Lowest alert level to display Parsers map[string]string // A map of syntax -> commands Path string // The location of the config file 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 StylesPath string // Directory with Rule.yml files TokenIgnores map[string][]string // A list of tokens to ignore Whitelist map[string]struct{} // Project-specific vocabulary (okay) Blacklist map[string]struct{} // Project-specific vocabulary (avoid) WordTemplate string // The template used in YAML -> regexp list conversions SecToPat map[string]glob.Glob `json:"-"` FsWrapper *afero.Afero `json:"-"` FallbackPath string `json:"-"` // Command-line configuration Output string // (optional) output style ("line" or "CLI") Wrap bool // (optional) wrap output when CLI style NoExit bool // (optional) don't return a nonzero exit code on lint errors Sorted bool // (optional) sort files by their name for output Normalize bool // (optional) replace each path separator with a slash ('/') Simple bool // (optional) lint all files line-by-line InExt string // (optional) extension to associate with stdin Relative bool // (optional) return relative paths }
Config holds Vale's configuration, both from the CLI and its config file.
func LoadConfig ¶ added in v0.7.1
LoadConfig reads the .vale/_vale file.
type File ¶
type File struct { Alerts []Alert // all alerts associated with this file BaseStyles []string // base style assigned in .vale 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 Content string // the raw file contents Counts map[string]int // word counts Format string // 'code', 'markup' or 'prose' Lines []string // the File's Content split into lines Command string // a user-provided parsing CLI command NormedExt string // the normalized extension (see util/format.go) Path string // the full path RealExt string // actual file extension Scanner *bufio.Scanner // used by lintXXX functions Sequences []string // tracks various info (e.g., defined abbreviations) Simple bool Summary bytes.Buffer // holds content to be included in summarization checks // contains filtered or unexported fields }
A File represents a linted text file.
func (*File) AddAlert ¶ added in v0.3.2
AddAlert calculates the in-text location of an Alert and adds it to a File.
func (*File) QueryComments ¶ added in v0.4.2
QueryComments checks if there has been an in-text comment for this check.
func (*File) ResetComments ¶ added in v0.4.2
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 ¶ added in v0.4.2
UpdateComments sets a new status based on comment.
type Glob ¶ added in v0.3.1
Glob represents a glob pattern passed via `--glob`.