From 8aa96707af8ab6548db1ccb763da6f3fa5184f16 Mon Sep 17 00:00:00 2001 From: Zunli Hu Date: Tue, 9 Feb 2021 16:55:40 +0800 Subject: [PATCH 1/3] add new rule --- azdev/__main__.py | 2 +- azdev/operations/linter/linter.py | 11 +++++++++++ azdev/operations/linter/rules/command_rules.py | 6 ++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/azdev/__main__.py b/azdev/__main__.py index c319d843f..7c82c5e51 100644 --- a/azdev/__main__.py +++ b/azdev/__main__.py @@ -16,7 +16,7 @@ class AzDevCli(CLI): def get_cli_version(self): - from . import __VERSION__ + from azdev import __VERSION__ return __VERSION__ diff --git a/azdev/operations/linter/linter.py b/azdev/operations/linter/linter.py index 414ccd9fe..8fcaa301c 100644 --- a/azdev/operations/linter/linter.py +++ b/azdev/operations/linter/linter.py @@ -169,6 +169,17 @@ def _get_loaded_help_description(self, entry): return help_entry.short_summary or help_entry.long_summary return help_entry + def support_no_wait(self, command_name): + no_wait = self._command_loader.command_table[command_name].support_no_wait + op = self.get_op_handler() + import inspect + import re + source_code = inspect.getsource(op) + pattern = re.compile("sdk_no_wait") + support_no_wait = pattern.search(source_code) + if no_wait: + return command_name + return False # pylint: disable=too-many-instance-attributes class LinterManager(object): diff --git a/azdev/operations/linter/rules/command_rules.py b/azdev/operations/linter/rules/command_rules.py index f09dcc65c..e2b275802 100644 --- a/azdev/operations/linter/rules/command_rules.py +++ b/azdev/operations/linter/rules/command_rules.py @@ -35,3 +35,9 @@ def group_delete_commands_should_confirm(linter, command_name): if 'yes' not in linter.get_command_parameters(command_name): raise RuleError("If this command deletes a collection, or group of resources. " "Please make sure to ask for confirmation.") + + +@CommandRule(LinterSeverity.HIGH) +def no_wait_command(linter, command_name): + if linter.support_no_wait(command_name): + raise RuleError('Deprecated command is expired and should be removed.') \ No newline at end of file From 6ebd697d301ba0c2bd44421db52460bac9d18007 Mon Sep 17 00:00:00 2001 From: Zunli Hu Date: Fri, 9 Apr 2021 15:41:20 +0800 Subject: [PATCH 2/3] fix style --- azdev/operations/linter/linter.py | 1 + 1 file changed, 1 insertion(+) diff --git a/azdev/operations/linter/linter.py b/azdev/operations/linter/linter.py index 8fcaa301c..c6c3e336d 100644 --- a/azdev/operations/linter/linter.py +++ b/azdev/operations/linter/linter.py @@ -181,6 +181,7 @@ def support_no_wait(self, command_name): return command_name return False + # pylint: disable=too-many-instance-attributes class LinterManager(object): From 7eddeeb19b22645e3cad0e967108aaa6b169c381 Mon Sep 17 00:00:00 2001 From: Zunli Hu Date: Fri, 9 Apr 2021 15:44:29 +0800 Subject: [PATCH 3/3] fix style --- azdev/operations/linter/rules/command_rules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azdev/operations/linter/rules/command_rules.py b/azdev/operations/linter/rules/command_rules.py index e2b275802..e676b22d9 100644 --- a/azdev/operations/linter/rules/command_rules.py +++ b/azdev/operations/linter/rules/command_rules.py @@ -40,4 +40,4 @@ def group_delete_commands_should_confirm(linter, command_name): @CommandRule(LinterSeverity.HIGH) def no_wait_command(linter, command_name): if linter.support_no_wait(command_name): - raise RuleError('Deprecated command is expired and should be removed.') \ No newline at end of file + raise RuleError('Deprecated command is expired and should be removed.')