-
Notifications
You must be signed in to change notification settings - Fork 216
use checker_state in trailing whitespace style check + add dedicated test #2160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,17 +43,25 @@ | |
|
|
||
| EB_CHECK = '_eb_check_' | ||
|
|
||
| COMMENT_REGEX = re.compile(r'^\s*#') | ||
| PARAM_DEF_REGEX = re.compile(r"^(?P<key>[a-z_]+)\s*=\s*") | ||
|
|
||
| # any function starting with _eb_check_ (see EB_CHECK variable) will be | ||
|
|
||
| # Any function starting with _eb_check_ (see EB_CHECK variable) will be | ||
| # added to the tests if the test number is added to the select list. | ||
| # | ||
| # Note: only functions that have a first argument named 'physical_line' or 'logical_line' | ||
| # will actually be used! | ||
| # | ||
| # The test number is definied as WXXX and EXXX (for warnings and errors) | ||
| # where XXX is a 3 digit number. | ||
| # | ||
| # It should be mentioned in the docstring as a single word. | ||
| # Read the pep8 docs to understand the arguments of these functions: | ||
| # https://pep8.readthedocs.org or more specifically: | ||
| # https://pep8.readthedocs.org/en/latest/developer.html#contribute | ||
| def _eb_check_trailing_whitespace(physical_line, lines, line_number, total_lines): # pylint:disable=unused-argument | ||
|
|
||
| def _eb_check_trailing_whitespace(physical_line, lines, line_number, checker_state): # pylint:disable=unused-argument | ||
| """ | ||
| W299 | ||
| Warn about trailing whitespace, except for the description and comments. | ||
|
|
@@ -62,27 +70,25 @@ def _eb_check_trailing_whitespace(physical_line, lines, line_number, total_lines | |
| The arguments are explained at | ||
| https://pep8.readthedocs.org/en/latest/developer.html#contribute | ||
| """ | ||
| comment_re = re.compile(r'^\s*#') | ||
| if comment_re.match(physical_line): | ||
| # apparently this is not the same as physical_line line?! | ||
| line = lines[line_number-1] | ||
|
|
||
| if COMMENT_REGEX.match(line): | ||
| return None | ||
|
|
||
| result = pep8.trailing_whitespace(physical_line) | ||
| result = pep8.trailing_whitespace(line) | ||
| if result: | ||
| result = (result[0], result[1].replace("W291", "W299")) | ||
| result = (result[0], result[1].replace('W291', 'W299')) | ||
|
|
||
| # keep track of name of last parameter that was defined | ||
| param_def = PARAM_DEF_REGEX.search(line) | ||
| if param_def: | ||
| checker_state['eb_last_key'] = param_def.group('key') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is nice! |
||
|
|
||
| # if the warning is about the multiline string of description | ||
| # we will not issue a warning | ||
| keys_re = re.compile(r"^(?P<key>[a-z_]+)\s*=\s*") | ||
|
|
||
| # starting from the current line and going to the top, | ||
| # check that if the first `key = value` that is found, has | ||
| # key == description, then let the test pass, else return | ||
| # the result of the general pep8 check. | ||
| for line in reversed(lines[:line_number]): | ||
| res = keys_re.match(line) | ||
| if res and res.group("key") == "description": | ||
| result = None | ||
| break | ||
| if checker_state.get('eb_last_key') == 'description': | ||
| result = None | ||
|
|
||
| return result | ||
|
|
||
|
|
@@ -112,7 +118,7 @@ def check_easyconfigs_style(easyconfigs, verbose=False): | |
| # on a line: the default of 79 is too narrow. | ||
| options.max_line_length = 120 | ||
| # we ignore some tests | ||
| # note that W291 has be replaced by our custom W299 | ||
| # note that W291 has been replaced by our custom W299 | ||
| options.ignore = ( | ||
| 'W291', # replaced by W299 | ||
| ) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why switch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because apparently this is not the same as
physical_line... I noticed that for thedescription =line, only the part after the=was included inphysical_line...