diff options
author | Sushobhit <31987769+sushobhit27@users.noreply.github.com> | 2019-08-22 18:46:48 +0530 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2019-08-22 15:16:48 +0200 |
commit | 6b3afd4f6d75debd7f286f0d3c760ed10ab1e79f (patch) | |
tree | fae404576e796b3a1f188a0a7a1fc313d9b118f4 /pylint/checkers/refactoring.py | |
parent | 827181602716f64ae226761bf36328cdf67ef782 (diff) | |
download | pylint-git-6b3afd4f6d75debd7f286f0d3c760ed10ab1e79f.tar.gz |
Added a new check, consider-using-sys-exit, close #2925 (#3062)
Close #2925
Diffstat (limited to 'pylint/checkers/refactoring.py')
-rw-r--r-- | pylint/checkers/refactoring.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/pylint/checkers/refactoring.py b/pylint/checkers/refactoring.py index 6291e9126..98dd80827 100644 --- a/pylint/checkers/refactoring.py +++ b/pylint/checkers/refactoring.py @@ -273,6 +273,11 @@ class RefactoringChecker(checkers.BaseTokenChecker): "consider using the list, dict or set constructor. " "It is faster and simpler.", ), + "R1722": ( + "Consider using sys.exit()", + "consider-using-sys-exit", + "Instead of using exit() or quit(), consider using the sys.exit().", + ), } options = ( ( @@ -641,10 +646,16 @@ class RefactoringChecker(checkers.BaseTokenChecker): "stop-iteration-return", "consider-using-dict-comprehension", "consider-using-set-comprehension", + "consider-using-sys-exit", ) def visit_call(self, node): self._check_raising_stopiteration_in_generator_next_call(node) self._check_consider_using_comprehension_constructor(node) + self._check_quit_exit_call(node) + + def _check_quit_exit_call(self, node): + if isinstance(node.func, astroid.Name) and node.func.name in ("quit", "exit"): + self.add_message("consider-using-sys-exit", node=node) def _check_raising_stopiteration_in_generator_next_call(self, node): """Check if a StopIteration exception is raised by the call to next function |