Run automated checks on repositories to improve code quality.
10K+
Run automated checks on repositories to improve code quality.
To run checks on every push with Gitlab,
add this on top of your .gitlab-ci.yml file:
validate:
image: gramener/builderrors
script: builderrors
From the folder you want check, run this command on Linux:
docker run --rm -it -v $(pwd):/src gramener/builderrors
On Windows Command Prompt:
docker run --rm -it -v %cd%:/src gramener/builderrors
On Windows PowerShell:
docker run --rm -it -v ${PWD}:/src gramener/builderrors
In bash or Git Bash, run:
git clone https://code.gramener.com/cto/builderrors.git
cd builderrors
npm install
pip install -r requirements.txt
From your project folder, run this in bash or Git Bash:
bash /path/to/builderrors [OPTIONS]
builderrors only runs on a git repository with committed files.
It WON'T check untracked or .gitignored files.
You can pass options as command-line parameters. For example:
# Skip flake8. Report errors only if minified code characters > 100,000
docker run --rm -it -v $(pwd):/src gramener/builderrors \
builderrors --skip-flake8 --code-chars-error=100000
# Skip Git LFS, eslint and stylelint
bash /path/to/builderrors --skip-lfs --skip-eslint --skip-stylelint
You can also pass options as environment variables. (Command line overrides environment variables.) For example:
# Skip flake8. Report errors only if minified code characters > 100,000
docker run --rm -it -v $(pwd):/src \
-e SKIP_FLAKE8=1 -e CODE_CHARS_ERROR=100000 \
builderrors gramener/builderrors
# Skip Git LFS, eslint and stylelint
SKIP_LFS=1 SKIP_ESLINT=1 SKIP_STYLELINT=1 bash /path/to/builderrors
On Gitlab, set environment variables under Settings > CI / CD > Variables.
| Environment variable | Command line | Meaning |
|---|---|---|
VERBOSE | --verbose | Show config used and progress |
SKIP_LIB | --skip-lib | Skip libraries check |
SKIP_MINIFIED | --skip-minified | Skip minified file check |
SKIP_LFS | --skip-lfs | Skip Git LFS check |
SKIP_PRETTIER | --skip-prettier | Skip Prettier check |
SKIP_USELESS | --skip-useless | Skip useless files check |
SKIP_DUPLICATE_FILES | --skip-duplicate-files | Skip duplicate files check |
SKIP_DUPLICATE_LINES | --skip-duplicate-lines | Skip duplicate lines check |
SKIP_PY_FILENAMES | --skip-py-filenames | Skip Python filename check |
SKIP_BLACK | --skip-black | Skip Python Black check |
SKIP_FLAKE8 | --skip-flake8 | Skip flake8 check |
SKIP_BANDIT | --skip-bandit | Skip bandit check |
SKIP_ESLINT | --skip-eslint | Skip eslint check |
SKIP_ESLINT_DEFAULT | --skip-eslint-default | Skip default eslint checks (HTML & template plugins) |
SKIP_STYLELINT | --skip-stylelint | Skip stylelint check |
SKIP_HTMLHINT | --skip-htmlhint | Skip htmlhint check |
SKIP_CSS_CHARS | --skip-css-chars | Skip CSS size check |
SKIP_CODE_CHARS | --skip-code-chars | Skip code size check |
LFS_SIZE | --lfs-size=num | Files over num bytes should use Git LFS (default: 1,000,000) |
DUPLICATE_FILESIZE | --duplicate-filesize=num | Files over num bytes should not be duplicated (default: 100) |
DUPLICATE_LINES | --duplicate-lines=num | Duplicate code over num lines are not allowed (default: 50) |
PY_LINE_LENGTH | --py-line-length=num | Approx line length of Python code used by Black (default: 99) |
BANDIT_CONFIDENCE | --bandit-confidence=low | Show bandit errors with low or more confidence. medium, high, all are allowed |
BANDIT_SEVERITY | --bandit-severity=low | Show bandit errors with low or more severity. medium, high, all are allowed |
CSS_CHARS_ERROR | --css-chars-error=num | Minified CSS should be less than num bytes (default: 10,000) |
CODE_CHARS_ERROR | --code-chars-error=num | Minified Python + JS code should be less than num bytes (default: 50,000) |
builderrors reports these errors:
node_modules (or bower_components) should be installed via npm install in each environment
git rm -rf node_modules/ bower_components/ to remove the librariesbower_components/ and node_modules/ to your .gitignorebuilderrors --skip-libraries (e.g. to share a git repo for offline installation)Minified files are not source code and shouldn't be version-controlled. They're generated
git rm jquery.min.js ...other.min.js to remove the filenpm install your-package-name to install the packagenode_modules/<lib>/dist/<lib>.min.js)builderrors --skip-minified (e.g. if the package is not on npm)Git stores copies of every version. LFS stores pointers instead
git lfs install on your repogit lfs track <large-file> on each of these large filesbuilderrors --skip-lfs (e.g. if you can't use LFS)Thumbnails (thumbs.db), backups (*~), etc don't need to be committed. Nor logs (*.log)
git rm <useless.file> to remove it<useless.file> to your .gitignorebuilderrors --skip-useless (e.g. if you DO need to commit .log files)You can re-use the same file
git rm <duplicate.file> to remove it<duplicate.file> with the retained file in your codebuilderrors --duplicate-filesize=1000builderrors --skip-duplicate-files (e.g. if you need duplicate files for test cases)You can re-use the same code
builderrors --duplicate-lines=100builderrors --skip-duplicate-lines (e.g. if you need duplicate code for test cases)It's important to have consistent formatting for readability. We use prettier.
Use the VS Code Prettier - Code Formatter plugin to auto-format your code.
To format manually:
npm install -g prettier to install prettier (one-time)npx --yes prettier --write . to fix most errors in the current folder (.).prettierrc file.prettierignore filebuilderrors --skip-prettier (e.g. if you temporarily need the build to pass)It's important to have consistent formatting for readability. We use black for Python files.
Use the VS Code Prettier - Black plugin to auto-format your code.
To format manually:
pip install black to install black (one-time)black --skip-string-normalization --line-length=99 . to fix all errors.pyproject.toml filebuilderrors --skip-prettier (e.g. if you temporarily need the build to pass)Otherwise you can't import the file.
_)builderrors --skip-py-filenames (e.g. if you won't be importing the module)Flake8 reports Python errors.
pip install autopep8 and then autopep8 -iv --max-line-length 99 *.py to auto-fix the file.
Then reformat with black# noqa at the end.flake8 file
extend-ignore = E203,E501 for consistency with blackbuilderrors --skip-flake8 (e.g. if you temporarily need the build to pass)Common errors:
{'x': 1, 'x': 2}. That's wrong.print in production code.Bandit reports security errors in Python.
# nosec at the end.bandit filebuilderrors --bandit-confidence=high (or medium)builderrors --bandit-severity=high (or medium)builderrors --skip-bandit (e.g. if there are too many false-positives)ESLint reports JavaScript errors in JS and HTML files -- including HTML templates.
eslint --fix to automatically fix eslint errors where possible.// eslint-disable-line at the end.eslintrc.js file based on the defaultbuilderrors --skip-eslint (e.g. if you temporarily need the build to pass)Common errors:
'x' is not defined. [Error/no-undef]
.js: /* globals x, ... */..eslintrc.js for libraries like d3, $, _, etc.: "globals": {"d3": "readonly", ...}'x' is assigned a value but never used. [Error/no-unused-vars]
.js: /* exported x, ... */ (or don't assign to the variable)stylelint reports CSS and SASS errors.
/* stylelint-disable-line */ at the end.stylelintrc.js file based on the defaultbuilderrors --skip-stylelint (e.g. if you're using third-party provided CSS)htmlhint checks HTML and reports errors.
.htmlhintrc file based on the defaultbuilderrors --skip-htmllint (e.g. if you're building a Lodash template library)You have too much CSS code, even after minifying with clean-css.
builderrors --css-chars-error=10000builderrors --skip-css-charsYou have too much Python / JavaScript code
builderrors --code-chars-error=80000builderrors --skip-code-charsComprehensive multi-linting tools are available at:
Content type
Image
Digest
sha256:2168d696c…
Size
538.3 MB
Last updated
over 2 years ago
docker pull gramener/builderrors