Skip to content

Commit da28780

Browse files
authored
azdev linter: Fix list index out of range in missing_command_test_coverage regex (#523)
* fix * Update __init__.py * Create pull_request_template.md * Update regex.py
1 parent f533ade commit da28780

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

.github/pull_request_template.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
**Related command**
2+
<!--- Please provide the related command with azdev {command} if you can. --->
3+
4+
**Description**<!--Mandatory-->
5+
<!--Why this PR? What is changed? What is the effect? etc. A high-quality description can accelerate the review process.-->
6+
7+
8+
---
9+
10+
This checklist is used to make sure that common guidelines for a pull request are followed.
11+
12+
- [ ] `pylint azdev --rcfile=.pylintrc -r n`
13+
14+
- [ ] `flake8 --statistics --append-config=.flake8 azdev`

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.2.3
6+
++++++
7+
* `azdev linter`: Fix `list index out of range` in missing_command_test_coverage regex
8+
59
0.2.2
610
++++++
711
* Update dependency `azure-cli-diff-tool` to `0.1.0`.

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.2.2'
7+
__VERSION__ = '0.2.3'

azdev/operations/regex.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ def get_all_tested_commands_from_regex(lines):
5454
if re_idx is None and re.findall(CMD_PATTERN[3], lines[row_num]):
5555
re_idx = 3
5656
if re_idx is not None:
57-
command = re.findall(CMD_PATTERN[re_idx], lines[row_num])[0]
57+
matches = re.findall(CMD_PATTERN[re_idx], lines[row_num])
58+
command = matches[0] if matches else ''
5859
while row_num < total_lines:
5960
if (re_idx in [0, 1] and not re.findall(END_PATTERN, lines[row_num])) or \
6061
(re_idx == 2 and (row_num + 1) < total_lines and
@@ -105,14 +106,17 @@ def search_argument_context(row_num, lines):
105106
# Match `with self.argument_context(scope) as c:`
106107
if ref1:
107108
sub_pattern = r'for scope in (.*):'
108-
cmds = json.loads(
109-
re.findall(sub_pattern, lines[row_num - 1])[0].replace('\'', '"'))
109+
matches = re.findall(sub_pattern, lines[row_num - 1])
110+
if matches:
111+
cmds = json.loads(matches[0].replace('\'', '"'))
110112
break
111113
# Match `with self.argument_context(['"]{} stop['"].format(scope)) as c:',
112114
if ref2:
113115
sub_pattern = r'for scope in (.*):'
114-
format_strings = json.loads(
115-
re.findall(sub_pattern, lines[row_num - 1])[0].replace('\'', '"'))
116+
format_strings = ''
117+
matches = re.findall(sub_pattern, lines[row_num - 1])
118+
if matches:
119+
format_strings = json.loads(matches[0].replace('\'', '"'))
116120
for c in ref2:
117121
for f in format_strings:
118122
cmds.append(c.replace('{}', f))

0 commit comments

Comments
 (0)