diff --git a/README.md b/README.md index 4b1bc97..2278e5a 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/linelint.go b/linelint.go index 8223af7..3267ee8 100644 --- a/linelint.go +++ b/linelint.go @@ -2,6 +2,7 @@ package main import ( "bufio" + "flag" "fmt" "io/ioutil" "os" @@ -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...) diff --git a/linelint.yml b/linelint.yml deleted file mode 100644 index 879a33d..0000000 --- a/linelint.yml +++ /dev/null @@ -1,22 +0,0 @@ -# 'true' will fix files -autofix: true - -# list of paths to ignore, uses gitignore syntaxes -ignore: - - .git/ - -rules: - # checks if file ends in a newline character - end-of-file: - # set to true to enable this rule - enable: true - - # set to true to disable autofix (if enabled globally) - disable-autofix: false - - # will merge with global configuration - ignore: - - README.md - - # if true also checks if file ends in a single newline character - single-new-line: true