util

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2017 License: MIT Imports: 11 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 struct {
	Output string // (optional) output style ("line" or "CLI")
	Wrap   bool   // (optional) wrap output when CLI style
	Debug  bool   // (optional) prints dubugging info to stdout
	NoExit bool   // (optional) don't return a nonzero exit code on lint errors
}

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)$`:                     {".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).

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 LookupSyntaxName = map[string]string{
	`(?:(?i)C|C\+\+|C#|Java|JavaScript|js|Swift|Go|sass|less|scala)$`: ".c",
	`(?:(?i)lua)$`:        ".lua",
	`(?:(?i)PHP)$`:        ".php",
	`(?:(?i)Python|py)$`:  ".py",
	`(?:(?i)R|perl)$`:     ".r",
	`(?:(?i)Rust)$`:       ".rs",
	`(?:(?i)Haskell|hs)$`: ".hs",
	`(?:(?i)Ruby|rb)$`:    ".rb",
}

LookupSyntaxName associates a syntax name with an extension used to get its comment delimiters from CommentsByNormedExt. An example use case is Markdown codeblocks: given a syntax (e.g., ```python), we use this to get its associated comments.

View Source
var MatchIgnoreByByExtension = map[string]string{
	".md":   "`([^`]+)`",
	".rst":  "``([^`]+)``|:.+:`[^`]+`",
	".adoc": "`([^`]+)`",
}

MatchIgnoreByByExtension maps an inline ignore pattern to its format (such as `foo` in Markdown).

Functions

func AllStringsInSlice

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

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

func CheckAndClose

func CheckAndClose(file *os.File) bool

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

func CheckError

func CheckError(err error, context string) bool

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

func DumpConfig added in v0.2.1

func DumpConfig() string

DumpConfig returns Vale's configuration in JSON format.

func ExtFromSyntax

func ExtFromSyntax(name string) string

ExtFromSyntax takes a syntax's name (e.g., "Python") and returns its extension (if found).

func FileExists

func FileExists(filename string) bool

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

func FindLoc

func FindLoc(count int, ctx string, s string, ext string, loc []int, pad int) (int, []int)

FindLoc calculates the line and span of an Alert.

func FormatFromExt

func FormatFromExt(path string) (string, string)

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

func FormatMessage added in v0.2.1

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

FormatMessage inserts `subs` into `msg`.

func HasAnyPrefix

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

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

func IsDir

func IsDir(filename string) bool

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

func NewLogger

func NewLogger() *logrus.Logger

NewLogger creates and returns an instance of logrus.Logger. If the `--debug` command flag was not provided, we set the level to Error.

func PrepText

func PrepText(txt string) string

PrepText prepares text for our check functions.

func StringInSlice

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

StringInSlice determines if `slice` contains the string `a`.

func StringsToInterface added in v0.2.1

func StringsToInterface(strings []string) []interface{}

StringsToInterface converts a slice of strings to an interface.

Types

This section is empty.

Jump to

Keyboard shortcuts

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