question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add an auto-fix or auto-correct feature

See original GitHub issue

Is 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:open
  • Created 5 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ericwbcommented, Dec 19, 2018

@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.

0reactions
ericwbcommented, Feb 13, 2022

Here’s a short example using libcst to auto-correct a problem in code, all while preserving the comments.

import libcst as cst

code = '''
from paramiko import client

class foo:
    def test(self):
        if True:
            ssh_client = client.SSHClient()
            # test test test
            ssh_client.set_missing_host_key_policy(client.AutoAddPolicy) # comment test
'''

class PolicyFix(cst.CSTTransformer):
    def leave_Call(self, original_node: cst.Call, updated_node: cst.Call) -> cst.Call:
        if (cst.ensure_type(original_node.func, cst.Attribute)
            and original_node.func.attr.value == "set_missing_host_key_policy"
            and original_node.args[0].value.attr.value == "AutoAddPolicy"
        ):
            return updated_node.with_deep_changes(
                old_node=updated_node.args[0].value,
                attr=cst.Name("RejectPolicy")
            )
        else:
            return original_node


tree = cst.parse_module(code)
new_tree = tree.visit(PolicyFix())
print(new_tree.code)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Turn AutoCorrect on or off in Word - Microsoft Support
Go to File > Options > Proofing and select AutoCorrect Options. Autocorrect options button on the Proofing dialog. On the AutoCorrect tab, select...
Read more >
How to use Auto-Correction and predictive text on your iPhone ...
Open the Settings app. Tap General > Keyboard. Turn on Auto-Correction. By default, Auto-Correction is on.
Read more >
Excel AutoCorrect: how to customize or turn off - Ablebits
How to add, change, and delete AutoCorrect entry · Click File > Options > Proofing > AutoCorrect Options. · In the AutoCorrect dialog...
Read more >
Excel AutoCorrect: A Complete Guide + Time Saving Examples
Excel autocorrect allows you to automatically correct mispelled words. You can also use this feature to insert symbols quickly or to write formulas...
Read more >
MS Word - Auto Correct Features - YouTube
MS Word - Auto Correct FeaturesWatch More Videos at: https://www.tutorialspoint.com/videotutorials/index.htmLecture By: Mr. Pavan Lalwani ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found