Add an auto-fix or auto-correct feature
See original GitHub issueIs your feature request related to a problem? Please describe. It’s nice that Bandit flags lines of code that require attention, but it would be even more valuable to suggest fixes for problem lines. Other linters such as ESLint provide a --fix command line option to automatically fix problems it finds.
See https://eslint.org/docs/user-guide/command-line-interface#options
Describe the solution you’d like A start might be that Bandit includes another field in the output data called suggested fix or something. It would include the modified line of code it found to be wrong with the proposed solution.
For example, if the yaml_load plugin found a case of yaml.load(), it would replace with yaml.load(Loader=yaml.SafeLoader).
Each plugin would need to handle fixes it could address.
Describe alternatives you’ve considered n/a
Additional context https://developer.ibm.com/articles/auto-fix-and-format-your-javascript-with-eslint/
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (5 by maintainers)

 Top Related Medium Post
Top Related Medium Post Top Related StackOverflow Question
Top Related StackOverflow Question
@lukehinds Yeah, I was thinking Bandit would output a new field of the suggested fix. But it could also have a command line option to actually make the changes in the file automatically. Similar to what ESLint offers.
Here’s a short example using libcst to auto-correct a problem in code, all while preserving the comments.