core

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 5, 2017 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AlertLevels = []string{"suggestion", "warning", "error"}

AlertLevels holds the possible values for "level" in an external rule.

View Source
var CLConfig = clConfig{}

CLConfig holds our command-line configuration.

View Source
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.

View Source
var Config = loadOptions()

Config holds our .vale configuration.

View Source
var ExeDir string

ExeDir is our starting location.

View Source
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"},
	`\.(?: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"},
	`\.(?: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).

View Source
var LevelToInt = map[string]int{
	"suggestion": 0,
	"warning":    1,
	"error":      2,
}

LevelToInt allows us to easily compare levels in lint.go.

View Source
var SentenceTokenizer, _ = english.NewSentenceTokenizer(nil)

SentenceTokenizer splits text into sentences.

Functions

func AllStringsInSlice added in v0.3.1

func AllStringsInSlice(strings []string, slice []string) bool

AllStringsInSlice determines if `slice` contains the `strings`.

func CheckAndClose added in v0.3.1

func CheckAndClose(file *os.File) bool

CheckAndClose closes `file` and prints any errors to stdout. A return value of true => no error.

func CheckError added in v0.3.1

func CheckError(err error) bool

CheckError prints any errors to stdout. A return value of true => no error.

func ContainsAny added in v0.5.0

func ContainsAny(text string, slice []string) bool

ContainsAny determines if `text` contains any string in `slice`.

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

func FileExists(filename string) bool

FileExists determines if the path given by `filename` exists.

func FormatFromExt added in v0.3.1

func FormatFromExt(path string) (string, string)

FormatFromExt takes a file extension and returns its [normExt, format] list, if supported.

func FormatMessage added in v0.3.1

func FormatMessage(msg string, subs ...string) string

FormatMessage inserts `subs` into `msg`.

func HasAnyPrefix added in v0.3.1

func HasAnyPrefix(text string, slice []string) bool

HasAnyPrefix determines if `text` has any prefix contained in `slice`.

func IsDir added in v0.3.1

func IsDir(filename string) bool

IsDir determines if the path given by `filename` is a directory.

func JaroWinkler added in v0.5.0

func JaroWinkler(ctx, sub string) (int, string)

JaroWinkler searches `ctx` line-by-line for a JaroWinkler distance score greater than a particular threshold.

func Max added in v0.4.0

func Max(a, b int) int

Max returns the max of `a` and `b`.

func Min added in v0.4.0

func Min(a, b int) int

Min returns the min of `a` and `b`.

func PrepText added in v0.3.1

func PrepText(txt string) string

PrepText prepares text for our check functions.

func SplitLines added in v0.4.1

func SplitLines(data []byte, atEOF bool) (adv int, token []byte, err error)

SplitLines splits on CRLF, CR not followed by LF, and LF.

func Stat added in v0.4.0

func Stat() bool

Stat checks if we have anything waiting in stdin.

func StringInSlice added in v0.3.1

func StringInSlice(a string, slice []string) bool

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

func Substitute(src, sub string, char rune) (string, bool)

Substitute replaces the substring `sub` with a string of asterisks.

func Which added in v0.3.1

func Which(cmds []string) string

Which checks for the existence of any command in `cmds`.

Types

type Alert

type Alert struct {
	Check       string // the name of the check
	Context     string // the surrounding text
	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 ByName added in v0.3.1

type ByName []*File

ByName sorts Files by their path.

func (ByName) Len added in v0.3.1

func (a ByName) Len() int

func (ByName) Less added in v0.3.1

func (a ByName) Less(i, j int) bool

func (ByName) Swap added in v0.3.1

func (a ByName) Swap(i, j int)

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 .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
	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 NewFile added in v0.4.2

func NewFile(src string) *File

NewFile initilizes a File.

func (*File) AddAlert added in v0.3.2

func (f *File) AddAlert(a Alert, ctx string, txt string, lines int, pad int)

AddAlert calculates the in-text location of an Alert and adds it to a File.

func (*File) FindLoc added in v0.4.2

func (f *File) FindLoc(ctx, s string, pad, count int, loc []int) (int, []int, string)

FindLoc calculates the line and span of an Alert.

func (*File) QueryComments added in v0.4.2

func (f *File) QueryComments(check string) bool

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 ...

func (*File) SortedAlerts

func (f *File) SortedAlerts() []Alert

SortedAlerts returns all of f's alerts sorted by line and column.

func (*File) UpdateComments added in v0.4.2

func (f *File) UpdateComments(comment string)

UpdateComments sets a new status based on comment.

type Glob added in v0.3.1

type Glob struct {
	Negated bool
	Pattern glob.Glob
}

Glob represents a glob pattern passed via `--glob`.

func NewGlob added in v0.4.1

func NewGlob(pat string) Glob

NewGlob creates a Glob from the string pat.

func (Glob) Match added in v0.4.1

func (g Glob) Match(query string) bool

Match returns whether or not the Glob g matches the string query.

type Selector

type Selector struct {
	Value string // e.g., text.comment.line.py
}

A Selector represents a named section of text.

func (Selector) Contains

func (s Selector) Contains(sel Selector) bool

Contains determines if all if sel's sections are in s.

func (Selector) Equal

func (s Selector) Equal(sel Selector) bool

Equal determines if sel == s.

func (Selector) Has

func (s Selector) Has(scope string) bool

Has determines if s has a part equal to scope.

func (Selector) Sections

func (s Selector) Sections() []string

Sections splits a Selector into its parts -- e.g., text.comment.line.py -> []string{"text", "comment", "line", "py"}.

Jump to

Keyboard shortcuts

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