Compare commits
3 Commits
072582d9cb
...
e98272c218
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e98272c218 | ||
|
|
12b5f7491f | ||
|
|
e45933a3d4 |
2
bin/test
2
bin/test
@@ -1,2 +1,2 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
go test github.com/amyboyd/editorconfig-cli/editorconfig $*
|
go test git.lab.xmaxsmi.dev/xmaxsmi/editorconfig-cli/editorconfig $*
|
||||||
|
|||||||
@@ -50,12 +50,18 @@ func FixCommand(c *cli.Context) error {
|
|||||||
// Run line checkers and fixers.
|
// Run line checkers and fixers.
|
||||||
lines := SplitIntoLines(fileContent)
|
lines := SplitIntoLines(fileContent)
|
||||||
lineNo := 1
|
lineNo := 1
|
||||||
for _, line := range lines {
|
for i, line := range lines {
|
||||||
for ruleName, ruleValue := range rules {
|
for ruleName, ruleValue := range rules {
|
||||||
if lineChecker, ok := lineCheckers[ruleName]; ok {
|
if lineChecker, ok := lineCheckers[ruleName]; ok {
|
||||||
result := lineChecker(ruleValue, line)
|
result := lineChecker(ruleValue, line)
|
||||||
if !result.isOk {
|
if !result.isOk {
|
||||||
fmt.Println(f + ": line " + strconv.Itoa(lineNo) + ": " + ruleName + ": " + result.messageIfNotOk)
|
if result.fixer != nil {
|
||||||
|
lines[i] = result.fixer(ruleValue, line)
|
||||||
|
hasChanged = true
|
||||||
|
fmt.Println(f + ": line " + strconv.Itoa(lineNo) + ": " + ruleName + ": fixed")
|
||||||
|
} else {
|
||||||
|
fmt.Println(f + ": line " + strconv.Itoa(lineNo) + ": " + ruleName + ": " + result.messageIfNotOk)
|
||||||
|
}
|
||||||
// Don't show more than 1 error per line.
|
// Don't show more than 1 error per line.
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -63,14 +69,19 @@ func FixCommand(c *cli.Context) error {
|
|||||||
}
|
}
|
||||||
lineNo++
|
lineNo++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Rejoin the lines if any were changed
|
||||||
|
if hasChanged {
|
||||||
|
fileContent = strings.Join(lines, "\n")
|
||||||
|
}
|
||||||
|
|
||||||
if hasChanged {
|
if hasChanged {
|
||||||
fileHandler, err := os.Open(f)
|
err := os.WriteFile(f, []byte(fileContent), 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Could not write to " + f)
|
fmt.Println("Could not write to " + f + ": " + err.Error())
|
||||||
|
} else {
|
||||||
|
fmt.Println("Wrote to " + f)
|
||||||
}
|
}
|
||||||
fileHandler.WriteString(fileContent)
|
|
||||||
fmt.Println("Wrote to " + f)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -69,6 +69,21 @@ func FindSourceFiles(searchPaths []string) ([]string, error) {
|
|||||||
return nil, cli.NewExitError(errMessage, 2)
|
return nil, cli.NewExitError(errMessage, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if this is a specific file path (exists and is a file)
|
||||||
|
if fileInfo, err := os.Stat(searchPath); err == nil && !fileInfo.IsDir() {
|
||||||
|
// Don't run on files inside dot directories.
|
||||||
|
if !containsDotDirectoryRegex.MatchString(searchPath) {
|
||||||
|
// For explicitly specified files, always include them regardless of extension
|
||||||
|
files = append(files, searchPath)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the file doesn't exist, skip it silently (don't error out)
|
||||||
|
if _, err := os.Stat(searchPath); err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
_ = filepath.Walk(searchPath, func(path string, fileInfo os.FileInfo, err error) error {
|
_ = filepath.Walk(searchPath, func(path string, fileInfo os.FileInfo, err error) error {
|
||||||
// Don't add paths that don't exist.
|
// Don't add paths that don't exist.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -1,4 +1,4 @@
|
|||||||
module github.com/amyboyd/editorconfig-cli
|
module git.lab.xmaxsmi.dev/xmaxsmi/editorconfig-cli
|
||||||
|
|
||||||
go 1.25.0
|
go 1.25.0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user