Skip to content

Commit 8242020

Browse files
authored
Fix None file path for added files, empty diff and empty parameters for missing_command_example (#503)
* fix none path for added files
1 parent 9475f51 commit 8242020

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

HISTORY.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
33
Release History
44
===============
5+
0.1.93
6+
++++++
7+
* `azdev linter`: Fix `None` path for added files in `git diff` for `missing_command_example` rule
8+
59
0.1.92
610
++++++
711
* `azdev linter`: Add `missing_command_example` rule

azdev/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
# license information.
55
# -----------------------------------------------------------------------------
66

7-
__VERSION__ = '0.1.92'
7+
__VERSION__ = '0.1.93'

azdev/operations/linter/linter.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,13 @@ def check_missing_command_example(self):
237237
cmd_help = self._loaded_help.get(cmd, None)
238238
if not cmd_help:
239239
continue
240-
# parameters = cmd_help.parameters
241-
# add if future parameter set required
242240
cmd_suffix = cmd.split()[-1]
243241
cmd_example_threshold = get_cmd_example_threshold(cmd_suffix, cmd_example_config)
244242
if cmd_example_threshold == 0:
245243
continue
244+
if not hasattr(cmd_help, "parameters") or len(cmd_help.parameters) == 0:
245+
# skip cmd without parameters
246+
continue
246247
if not hasattr(cmd_help, "examples") or len(cmd_help.examples) < cmd_example_threshold:
247248
violations.append(f'Command `{cmd}` should have at least {cmd_example_threshold} example(s)')
248249
if violations:
@@ -427,7 +428,9 @@ def _detect_modified_command(self):
427428
modified_commands = set()
428429
diff_patches = diff_branch_file_patch(repo=self.git_repo, target=self.git_target, source=self.git_source)
429430
for change in diff_patches:
430-
file_path, filename = self._split_path(change.a_path)
431+
if not change.b_path or not change.diff:
432+
continue
433+
file_path, filename = self._split_path(change.b_path)
431434
if "commands.py" not in filename and "aaz" not in file_path:
432435
continue
433436
current_lines = self._read_blob_lines(change.b_blob)
@@ -462,6 +465,8 @@ def _get_diffed_patches(self):
462465
return
463466
diff_patches = diff_branch_file_patch(repo=self.git_repo, target=self.git_target, source=self.git_source)
464467
for change in diff_patches:
468+
if not change.diff:
469+
continue
465470
patch = change.diff.decode("utf-8")
466471
added_lines = [line for line in patch.splitlines() if line.startswith('+') and not line.startswith('+++')]
467472
self.diffed_lines |= set(added_lines)

0 commit comments

Comments
 (0)