Documentation ¶
Index ¶
- Variables
- func AllStringsInSlice(strings []string, slice []string) bool
- func CheckAndClose(file *os.File) bool
- func CheckError(err error, message string) bool
- func DumpConfig() string
- func FileExists(filename string) bool
- func FindLoc(count int, ctx string, s string, ext string, loc []int, pad int) (int, []int)
- func FormatFromExt(path string) (string, string)
- func FormatMessage(msg string, subs ...string) string
- func HasAnyPrefix(text string, slice []string) bool
- func IsDir(filename string) bool
- func PrepText(txt string) string
- func StringInSlice(a string, slice []string) bool
- func StringsToInterface(strings []string) []interface{}
- func Substitute(src string, repl string, char string) string
- func Which(cmds []string) string
- type Alert
- type ByName
- type ByPosition
- type File
- type Glob
- 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 CLConfig struct { 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 }
CLConfig holds our command-line configuration.
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 Config = loadOptions()
Config holds our .vale configuration.
var ExeDir string
ExeDir is our starting location.
var FormatByExtension = map[string][]string{
`\.(?:[rc]?py[3w]?|[Ss][Cc]onstruct)$`: {".py", "code"},
`\.(?:adoc|asciidoc)$`: {".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"},
`\.(?:java|bsh)$`: {".c", "code"},
`\.(?:js)$`: {".c", "code"},
`\.(?:ltx|tex)$`: {".tex", "markup"},
`\.(?: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"},
`\.(?:rb|Gemfile|Rakefile|Brewfile|gemspec)$`: {".rb", "code"},
`\.(?: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.
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 DumpConfig ¶ added in v0.3.1
func DumpConfig() string
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 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 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 `repl` with `char`s.
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 }
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 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 .txtint Counts map[string]int // word counts Format string // 'code', 'markup' or 'prose' 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) }
A File represents a linted text file.
func (*File) SortedAlerts ¶
SortedAlerts returns all of f's alerts sorted by line and column.