Skip to content

Commit

Permalink
Add -a flag (for autofix)
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandrone committed May 3, 2020
1 parent 90e37fc commit 090ccb8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 28 deletions.
29 changes: 25 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,40 @@ See the [#Docker](#Docker) section for instructions on Docker usage.

> This is a project in development. Use it at your own risk!
Run it and pass a list of file or directories as argument:
Run it and pass a list of file or directories as argument.

```console
linelint .
$ linelint .
[EOF Rule] File "LICENSE" has lint errors
[EOF Rule] Ignoring file "README.md": in rule ignore path
[EOF Rule] File "linter/eof.go" has lint errors

Total of 2 lint errors!
```

Or:

```console
linelint README.md LICENSE linter/config.go
$ linelint README.md LICENSE linter/config.go
[EOF Rule] File "LICENSE" has lint errors

Total of 1 lint errors!
```

In case any rule fails, Linelint will fail with an error (exit code 1).

If the `autofix` option is set to `true` (it is `false` by default, activate it with the `-a` flag), it will attempt to fix any file with error.

```console
$ linelint -a .
[EOF Rule] File "LICENSE" has lint errors
[EOF Rule] File "LICENSE" lint errors fixed
[EOF Rule] Ignoring file "README.md": in rule ignore path
[EOF Rule] File "linter/eof.go" has lint errors
[EOF Rule] File "linter/eof.go" lint errors fixed
```

In case any rule fails, it will end with an error (exit code 1). If the `autofix` option is set to `true` (it is `false` by default), it will attempt to fix any file with error. If all files are fixed, the program will terminate successfully.
When all files are fixed successfully, Linelint terminates with with a success as well (exit code 0).

## Configuration

Expand Down
24 changes: 22 additions & 2 deletions linelint.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bufio"
"flag"
"fmt"
"io/ioutil"
"os"
Expand All @@ -10,16 +11,35 @@ import (
"github.com/fernandrone/linelint/linter"
)

const helpMsg = `usage of %s [-a] [FILE_OR_DIR [FILE_OR_DIR ...]]
Validates simple newline and whitespace rules in all sorts of files.
positional arguments:
FILE_OR_DIR files to format
optional arguments:
`

func main() {
var flagAutofix bool
flag.BoolVar(&flagAutofix, "a", false, "(autofix) will automatically fix files with errors in place")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, helpMsg, os.Args[0])
flag.PrintDefaults()
}
flag.Parse()

var args, paths []string

if len(os.Args[1:]) == 0 {
if flag.NArg() == 0 {
args = []string{"."}
} else {
args = os.Args[1:]
args = flag.Args()
}

config := linter.NewConfig()
config.AutoFix = flagAutofix

// get paths to ignore
ignore := linter.MustCompileIgnoreLines(config.Ignore...)
Expand Down
22 changes: 0 additions & 22 deletions linelint.yml

This file was deleted.

0 comments on commit 090ccb8

Please sign in to comment.