Move reusable regexp constants to utils.go.
This commit is contained in:
@@ -2,7 +2,6 @@ package editorconfig
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/saintfish/chardet"
|
"github.com/saintfish/chardet"
|
||||||
"regexp"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -20,10 +19,6 @@ type FullFileCheckResult struct {
|
|||||||
messageIfNotOk string
|
messageIfNotOk string
|
||||||
}
|
}
|
||||||
|
|
||||||
var lfRegexp = regexp.MustCompile(`\n`)
|
|
||||||
var crRegexp = regexp.MustCompile(`\r`)
|
|
||||||
var crlfRegexp = regexp.MustCompile(`\r\n`)
|
|
||||||
|
|
||||||
func CheckEndOfLineRule(ruleValue string, fileContent string) *FullFileCheckResult {
|
func CheckEndOfLineRule(ruleValue string, fileContent string) *FullFileCheckResult {
|
||||||
// Valid rules values are "lf", "cr", or "crlf". The values are case insensitive.
|
// Valid rules values are "lf", "cr", or "crlf". The values are case insensitive.
|
||||||
ruleValueLowercase := strings.ToLower(ruleValue)
|
ruleValueLowercase := strings.ToLower(ruleValue)
|
||||||
@@ -63,8 +58,6 @@ func CheckEndOfLineRule(ruleValue string, fileContent string) *FullFileCheckResu
|
|||||||
return &FullFileCheckResult{isOk: true}
|
return &FullFileCheckResult{isOk: true}
|
||||||
}
|
}
|
||||||
|
|
||||||
var endsWithFinalNewLineRegexp = regexp.MustCompile(`(\n|\r|\r\n)$`)
|
|
||||||
|
|
||||||
func CheckInsertFinalNewLineRule(ruleValue string, fileContent string) *FullFileCheckResult {
|
func CheckInsertFinalNewLineRule(ruleValue string, fileContent string) *FullFileCheckResult {
|
||||||
// Valid rules values are "true" or "false". The values are case insensitive.
|
// Valid rules values are "true" or "false". The values are case insensitive.
|
||||||
ruleValueLowercase := strings.ToLower(ruleValue)
|
ruleValueLowercase := strings.ToLower(ruleValue)
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package editorconfig
|
package editorconfig
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"regexp"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -23,13 +22,6 @@ type LineCheckResult struct {
|
|||||||
messageIfNotOk string
|
messageIfNotOk string
|
||||||
}
|
}
|
||||||
|
|
||||||
var hasIndentationRegexp = regexp.MustCompile(`^[\t ]`)
|
|
||||||
var hasNoIndentationRegexp = regexp.MustCompile(`^([^\t ]|$)`)
|
|
||||||
var indentedWithMixedTabsAndSpacesRegexp = regexp.MustCompile(`^(\t+ +| +\t+)`)
|
|
||||||
var indentedWithTabsRegexp = regexp.MustCompile(`^\t+`)
|
|
||||||
var indentedWithTabsThenCommentLineRegexp = regexp.MustCompile(`^\t+ \*`)
|
|
||||||
var indentedWithSpacesRegexp = regexp.MustCompile(`^ +`)
|
|
||||||
|
|
||||||
func HasIndentation(s string) bool {
|
func HasIndentation(s string) bool {
|
||||||
return hasIndentationRegexp.MatchString(s)
|
return hasIndentationRegexp.MatchString(s)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,19 @@ var filePathSeparatorRegex = regexp.QuoteMeta(string(filepath.Separator))
|
|||||||
|
|
||||||
var endOfPathRegex, _ = regexp.Compile(`[` + filePathSeparatorRegex + `][^` + filePathSeparatorRegex + `]+$`)
|
var endOfPathRegex, _ = regexp.Compile(`[` + filePathSeparatorRegex + `][^` + filePathSeparatorRegex + `]+$`)
|
||||||
|
|
||||||
|
var lfRegexp = regexp.MustCompile(`\n`)
|
||||||
|
var crRegexp = regexp.MustCompile(`\r`)
|
||||||
|
var crlfRegexp = regexp.MustCompile(`\r\n`)
|
||||||
|
|
||||||
|
var endsWithFinalNewLineRegexp = regexp.MustCompile(`(\n|\r|\r\n)$`)
|
||||||
|
|
||||||
|
var hasIndentationRegexp = regexp.MustCompile(`^[\t ]`)
|
||||||
|
var hasNoIndentationRegexp = regexp.MustCompile(`^([^\t ]|$)`)
|
||||||
|
var indentedWithMixedTabsAndSpacesRegexp = regexp.MustCompile(`^(\t+ +| +\t+)`)
|
||||||
|
var indentedWithTabsRegexp = regexp.MustCompile(`^\t+`)
|
||||||
|
var indentedWithTabsThenCommentLineRegexp = regexp.MustCompile(`^\t+ \*`)
|
||||||
|
var indentedWithSpacesRegexp = regexp.MustCompile(`^ +`)
|
||||||
|
|
||||||
func GetParentDir(path string) string {
|
func GetParentDir(path string) string {
|
||||||
return endOfPathRegex.ReplaceAllString(path, "")
|
return endOfPathRegex.ReplaceAllString(path, "")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user