Awesome
nllint
Linter to check newlines at the end of files
<img width="870" alt="image" src="https://github.com/suzuki-shunsuke/nllint/assets/13323303/6962481e-d74e-47a6-bdd0-cd31edae1771">--
<img width="982" alt="image" src="https://github.com/suzuki-shunsuke/nllint/assets/13323303/5cc5cf3f-874b-4465-834c-5bba55285fa8">$ 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
Motivation
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
Install
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
- Download a prebuilt binary from GitHub Releases and install it into
$PATH
Usage
$ 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
:bulb: Auto Fix by CI
<img width="870" alt="image" src="https://github.com/suzuki-shunsuke/nllint/assets/13323303/6962481e-d74e-47a6-bdd0-cd31edae1771">--
<img width="982" alt="image" src="https://github.com/suzuki-shunsuke/nllint/assets/13323303/5cc5cf3f-874b-4465-834c-5bba55285fa8">It's useful to format code automatically with nllint and push a commit to the remote branch in CI.
- List changed files
- Run
nllint -f [-s] [<changed files>...]
- Push a commit to the remote branch
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