Linter to check newlines at the end of files
MIT License
Linter to check newlines at the end of files
--
$ echo -n {} > foo.json
$ echo -n "{}\n\n" > bar.json
$ nllint foo.json bar.json
ERRO[0000] a file is invalid error="a newline at the end of file is missing" file_path=foo.json nllint_version= program=nllint
# --trim-space (-s): Check leading and trailing white spaces in files
$ nllint -s foo.json bar.json
ERRO[0000] a file is invalid error="a newline at the end of file is missing" file_path=foo.json nllint_version= program=nllint
ERRO[0000] a file is invalid error="leading and trailing white spaces in files should be trimmed" file_path=bar.json nllint_version= program=nllint
# -fix (-f): Fix files and outputs fixed file paths to the stdout
$ nllint -s -fix foo.json bar.json
WARN[0000] a newline at the end of file is missing file_path=foo.json nllint_version= program=nllint
foo.json
WARN[0000] leading and trailing white spaces in files should be trimmed file_path=bar.json nllint_version= program=nllint
bar.json
Each line should have a newline of the end of line because that’s how the POSIX standard defines a line:
Please see https://stackoverflow.com/a/729795/6364492
nllint is a single binary written in Go. So you only need to install an execurable file into $PATH
.
brew install suzuki-shunsuke/nllint/nllint
scoop bucket add suzuki-shunsuke https://github.com/suzuki-shunsuke/scoop-bucket
scoop install nllint
aqua g -i suzuki-shunsuke/nllint
$PATH
$ nllint help
nllint - Check newlines at the end of files
https://github.com/suzuki-shunsuke/nllint
Usage:
nllint [-fix (-f)] [-trim-space (-s)] [-ignore-notfound (-i)] <file path> [<file path>...]
Options:
-help, -h Show help
-version, -v Show version
-fix, -f Fix files
-trim-space, -s Disallow leading and trailing white spaces in files
-ignore-notfound, -i Ignore not found files
--
It's useful to format code automatically with nllint and push a commit to the remote branch in CI.
nllint -f [-s] [<changed files>...]
Please refer to this repository's workflows as the example.
nllint
is enough fast, so we think it's also okay to lint all files instead of only changed files.
git ls-files | xargs nllint -f -s