bandit icon indicating copy to clipboard operation
bandit copied to clipboard

config file as described in README.rst does not work

Open davidak opened this issue 7 years ago • 5 comments

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

  1. create .bandit file with content:
[bandit]
tests: B101,B102,B301

  1. run bandit -c .bandit -r module/
  2. get error: [main] ERROR .bandit : Error parsing file.

Expected behavior working as described in readme

Bandit version

bandit 1.4.0

Additional context Docs say it should be YAML and not INI. https://bandit.readthedocs.io/en/latest/config.html

davidak avatar Jun 18 '18 14:06 davidak

want to take this one on @davidak ?

lukehinds avatar Jun 18 '18 14:06 lukehinds

https://github.com/PyCQA/bandit/issues/318 is needed to use a sane name. I might find the time to do it then, but feel free to do it yourself.

davidak avatar Jun 18 '18 15:06 davidak

This bug seems to be caused by inconsistent behavior of Bandit (and incomplete documentation).

If you use .bandit file, you need to start the file with text “[bandit]” and then add the arguments. For example:

[bandit]
exclude: \tests,\doc,\misc
tests: B101,B102,B104 

But if you want to use separate config file with "–configfile" argument on the command line, you have to remove the text “[bandit]”, replace “exclude” with “exclude_dirs” and add the values inside square brackets like this:

exclude_dirs: [\tests,\doc,\misc]
tests: [B101,B102,B104]

lassejar avatar Aug 30 '18 10:08 lassejar

Hi, the following may be helpful to configure bandit, for example, to avoid raising B101 assert_used warnings on python tests

  • https://github.com/PyCQA/bandit/issues/603#issuecomment-971057519

diegovalenzuelaiturra avatar Nov 17 '21 01:11 diegovalenzuelaiturra

https://bandit.readthedocs.io/en/latest/config.html says .bandit should be an INI file (which uses = instead of :). The only thing incorrect is that it implies you don't need to use -c .bandit because that's --ini .bandit and not needed when using -r which is false here. I suggest Bandit prefer .bandit, pyproject.toml, and setup.cfg by default, overridable with arguments like -c, and to replace --ini with -c or --config (aka --configfile).

CTimmerman avatar Aug 20 '22 10:08 CTimmerman