Skip to content

Commit

Permalink
Add linting directories.
Browse files Browse the repository at this point in the history
  • Loading branch information
candid82 committed Oct 31, 2019
1 parent b1a3eca commit 9596f74
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 6 deletions.
1 change: 1 addition & 0 deletions core/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ type (
unusedFnParameters bool
fnWithEmptyBody bool
ignoredUnusedNamespaces Set
IgnoredFileRegexes []*regexp.Regexp
}
Keywords struct {
tag Keyword
Expand Down
32 changes: 27 additions & 5 deletions core/procs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1697,18 +1697,21 @@ func ProcessReplData() {
}

func findConfigFile(filename string, workingDir string, findDir bool) string {
var err error
configName := ".joker"
if findDir {
configName = ".jokerd"
}
filename, err := filepath.Abs(filename)
if err != nil {
fmt.Fprintln(Stderr, "Error reading config file "+filename+": ", err)
return ""
if filename != "" {
filename, err = filepath.Abs(filename)
if err != nil {
fmt.Fprintln(Stderr, "Error reading config file "+filename+": ", err)
return ""
}
}

if workingDir != "" {
workingDir, err = filepath.Abs(workingDir)
workingDir, err := filepath.Abs(workingDir)
if err != nil {
fmt.Fprintln(Stderr, "Error resolving working directory"+workingDir+": ", err)
return ""
Expand Down Expand Up @@ -1801,6 +1804,25 @@ func ReadConfig(filename string, workingDir string) {
return
}
}
ok, ignoredFileRegexes := configMap.Get(MakeKeyword("ignored-file-regexes"))
if ok {
seq, ok1 := ignoredFileRegexes.(Seqable)
if ok1 {
s := seq.Seq()
for !s.IsEmpty() {
regex, ok2 := s.First().(Regex)
if !ok2 {
printConfigError(configFileName, ":ignored-file-regexes elements must be regexes, got "+s.First().GetType().ToString(false))
return
}
WARNINGS.IgnoredFileRegexes = append(WARNINGS.IgnoredFileRegexes, regex.R)
s = s.Rest()
}
} else {
printConfigError(configFileName, ":ignored-file-regexes value must be a vector, got "+ignoredFileRegexes.GetType().ToString(false))
return
}
}
ok, knownNamespaces := configMap.Get(MakeKeyword("known-namespaces"))
if ok {
if _, ok1 := knownNamespaces.(Seqable); !ok1 {
Expand Down
61 changes: 60 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,58 @@ func lintFile(filename string, dialect Dialect, workingDir string) {
}
}

func matchesDialect(path string, dialect Dialect) bool {
ext := ".clj"
switch dialect {
case CLJS:
ext = ".cljs"
case JOKER:
ext = ".joke"
case EDN:
ext = ".edn"
}
return strings.HasSuffix(path, ext)
}

func isIgnored(path string) bool {
for _, r := range WARNINGS.IgnoredFileRegexes {
m := r.FindStringSubmatchIndex(path)
if len(m) > 0 {
if m[1]-m[0] == len(path) {
return true
}
}
}
return false
}

func lintDir(dirname string, dialect Dialect) {
var err error
phase := PARSE
if dialect == EDN {
phase = READ
}
ns := GLOBAL_ENV.CurrentNamespace()
ReadConfig("", dirname)
configureLinterMode(dialect, "", dirname)
filepath.Walk(dirname, func(path string, info os.FileInfo, err error) error {
if err != nil {
fmt.Fprintln(Stderr, "Error: ", err)
return nil
}
if !info.IsDir() && matchesDialect(path, dialect) && !isIgnored(path) {
GLOBAL_ENV.CoreNamespace.Resolve("*loaded-libs*").Value = EmptySet()
err = processFile(path, phase)
GLOBAL_ENV.SetCurrentNamespace(ns)
}
return nil
})
if err == nil {
WarnOnUnusedNamespaces()
WarnOnUnusedVars()
}
}

func dialectFromArg(arg string) Dialect {
switch strings.ToLower(arg) {
case "clj":
Expand Down Expand Up @@ -774,7 +826,14 @@ func main() {
if dialect == UNKNOWN {
dialect = detectDialect(filename)
}
lintFile(filename, dialect, workingDir)
if filename != "" {
lintFile(filename, dialect, workingDir)
} else if workingDir != "" {
lintDir(workingDir, dialect)
} else {
fmt.Fprintf(Stderr, "Error: Missing --file or --working-dir argument.\n")
ExitJoker(16)
}
if PROBLEM_COUNT > 0 {
ExitJoker(1)
}
Expand Down

0 comments on commit 9596f74

Please sign in to comment.