Version 1.0🔗
Warning
The hook bibclean is renamed bibclean-check. The hook bibclean-fix
no longer accepts --exit-non-zero-on-fix, as exiting with a non-zero code
after writing a file is the default: remove args: [--exit-non-zero-on-fix]
from .pre-commit-config.yaml when upgrading, or the hook fails with a usage
error.
bibclean 1.0 is a rewrite. It is a linter and formatter for BibTeX files, with its own lossless parser, a canonical format, fifteen rules and automatic configuration discovery. There is no public Python API.
Enhancements🔗
New
bibclean checkandbibclean fixcommands, accepting any number of files. A file that cannot be read is reported and the batch continues.Files are parsed by
bibcleanitself. Like BibTeX andpybtex, every@starts a block, including one in a%line. A file with a block that cannot be parsed, or that defines a@stringmacro twice, is reported and never rewritten.One canonical format, with a two-space indent, braced values, sorted entries and sorted fields, described in Canonical format.
Fifteen rules, each disabled by name with
ignoreor--ignore, described in Rules: syntax-error, doi-prefix, empty-field, strip-field, url-with-doi, month-format, pages-range, unescaped-percent, duplicate-field, duplicate-key, duplicate-doi, duplicate-string, undefined-string, author-format and required-field.The configuration is discovered from
pyproject.toml,bibclean.tomlor.bibclean.tomlnext to the files, described in Configuration.--configoverrides it and--isolatedignores it.New options
--diff,--ignore,--isolatedand--quiet. Violations are reported one per line with their position, followed by a summary line, in colour on a terminal and honouringNO_COLOR.Two pre-commit hooks,
bibclean-checkandbibclean-fix, running on thepre-commit,pre-merge-commit,pre-pushandmanualstages.
Bugs🔗
--exit-non-zero-on-fixnever fired, because it compared a value with itself.Non-standard entry types such as
@softwareand@online,@stringmacros,@preambleblocks and comments were dropped or inlined; they are now preserved.
API and behavior changes🔗
bibclean FILE [-o OUT] [--overwrite] [-c CFG] [--exit-non-zero-on-fix]becomesbibclean fix FILES... [-c CFG] [--diff]; the files are always rewritten in place.bibclean-check FILEbecomesbibclean check FILES.... The console scriptsbibclean-checkandbibclean-sys_infoare removed.Exit codes are now 0 for a clean run, 1 for a violation or a written file, and 2 for a configuration error, an unreadable file or a usage error. A syntax error in a
.bibfile exits 1, not 2.The configuration key
exclude_typeis renamedexclude-types, and the configuration is discovered instead of requiring-c. A configuration file other thanpyproject.tomlholds its keys at the top level, not under[tool.bibclean].The Python API
check_bib_database,clean_bib_database,load_bibandsave_bibis removed.Entries are written with a two-space indent instead of one space, and months with the macro
febinstead of{February}. The firstbibclean fixafter upgrading therefore rewrites the whole file once.The only runtime dependency is
click:bibtexparser,numpy,packaging,psutilandtomlare removed.The minimum supported Python version is 3.11.