ini "exclude" config is ignored
See original GitHub issueDescribe the bug exclude configuration inside .bandit ini file is always ignored due to default cli argument.
To Reproduce Steps to reproduce the behavior:
- Create . bandit file with the following.
[bandit]
targets: .
exclude: ./tests
- Run CLI with
bandit --ini .bandit -rin a directory with .bandit file. - You should now see that Bandit is prefer CLI argument for exclude over ini.
[main] INFO Using command line arg for excluded paths
[main] INFO Using ini file for selected targets
Expected behavior
Bandit should use .bandit configuration as there’s no CLI argument supplied then append default value to it as specified in argparse.
-x EXCLUDED_PATHS, --exclude EXCLUDED_PATHS
comma-separated list of paths (glob patterns supported) to exclude
from scan (note that these are in addition to the excluded paths
provided in the config file) (default:
.svn,CVS,.bzr,.hg,.git,__pycache__,.tox,.eggs,*.egg)
Bandit version
bandit 1.7.0
python version = 3.8.0 (default, Sep 3 2020, 18:08:13) [Clang 11.0.3 (clang-1103.0.32.62)]
Additional context
I believe this happens due to the default value for -x given to argparse. This means the ini configuration is always ignored as the code take default value as supplied CLI.
Workaround
Supplied exclude via CLI when running Bandit regardless of your ini. bandit -x ./tests --ini .bandit -r .
Issue Analytics
- State:
- Created 3 years ago
- Reactions:19
- Comments:11
Top Results From Across the Web
Exclude tests in pytest configuration file - Stack Overflow
As has been noted in the comments, --ignore takes a path (relative or absolute), not just a module name. From the output of...
Read more >The mypy configuration file - mypy 0.991 documentation
The configuration file format is the usual ini file format. ... names and paths which mypy should ignore while recursively discovering files to...
Read more >Configuring Flake8 — flake8 6.0.0 documentation
In our case, we keep our Flake8 configuration in tox.ini . ... flake8 --extend-ignore E203 \ --exclude .git,__pycache__,docs/source/conf.py,old,build,dist ...
Read more >Ignoring Files And Directories – TortoiseGit – Documentation
More examples include user-specific workspace settings *.suo, *.user (Visual ... Write the ignore entries in .git/info/exclude in repository metadata.
Read more >[Gerrit] flake8/pep8 should ignore *.egg in root directory
pywikibot/date.py +exclude = .tox,.git,./*.egg,ez_setup.py,externals,user-config.py,./scripts/i18n/*,./pywikibot/date.py max_line_length = 256 [pep8] ignore ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Coupled with https://github.com/PyCQA/bandit/issues/595, https://github.com/PyCQA/bandit/issues/657, and https://github.com/PyCQA/bandit/issues/488 (unceremoniously closed for no reason), I’d venture to say ‘exclude’ is pretty much nonfunctional at this point.
As a workaoround I call
bandit -x ""So that_log_option_sourcedoesn’t get the defaults. Or for.pre-commit-config.yaml: