-
Notifications
You must be signed in to change notification settings - Fork 581
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
SpaceConsistencyBear: Add leading_blankline option #2222
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ def run(self, | |
file, | ||
use_spaces: bool, | ||
allow_trailing_whitespace: bool=False, | ||
allow_leading_blanklines: bool=False, | ||
indent_size: int=SpacingHelper.DEFAULT_TAB_WIDTH, | ||
enforce_newline_at_EOF: bool=True): | ||
''' | ||
|
@@ -29,6 +30,9 @@ def run(self, | |
True if spaces are to be used instead of tabs. | ||
:param allow_trailing_whitespace: | ||
Whether to allow trailing whitespace or not. | ||
:param allow_leading_blanklines: | ||
Whether to allow leading blanklines | ||
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. blank lines not blanklines |
||
at start of file or not. | ||
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. at the start not at start |
||
:param indent_size: | ||
Number of spaces per indentation level. | ||
:param enforce_newline_at_EOF: | ||
|
@@ -38,7 +42,50 @@ def run(self, | |
result_texts = [] | ||
additional_info_texts = [] | ||
|
||
for line_number, line in enumerate(file, start=1): | ||
def get_blanklines_nr_end(): | ||
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. Can we come up with a better name for the function? This name is quite misleading. |
||
line_nr_end = False | ||
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. Again a better name for the variable. |
||
enumerated_zip_obj = zip(range(1, len(file) + 1), | ||
file) | ||
enumerated_tuple = tuple(enumerated_zip_obj) | ||
|
||
for line_number, line in enumerated_tuple: | ||
replacement = line | ||
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. There is no need for a temporary variable. Python uses Call by Object Reference and not Pass by reference. |
||
if replacement.strip() == '': | ||
line_nr_end = line_number | ||
else: | ||
break | ||
|
||
return line_nr_end | ||
|
||
if allow_leading_blanklines: | ||
start_line_of_file = 1 | ||
|
||
else: | ||
blanklines_nr_end = get_blanklines_nr_end() | ||
start_line_of_file = 1 | ||
if blanklines_nr_end: | ||
start_line_of_file = blanklines_nr_end + 1 | ||
result_texts.append('Leading blanklines.') | ||
additional_info_texts.append( | ||
'Your source code contains leading blanklines.' | ||
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. Again blank lines |
||
'Those usually have no meaning. Please consider' | ||
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. You missed a space after |
||
'removing them.') | ||
diff = Diff(file) | ||
diff.delete_lines(1, blanklines_nr_end) | ||
inconsistencies = ''.join('\n- ' + string | ||
for string in result_texts) | ||
yield Result.from_values( | ||
self, | ||
'Line contains following spacing inconsistencies:' | ||
+ inconsistencies, | ||
diffs={filename: diff}, | ||
file=filename, | ||
additional_info='\n\n'.join(additional_info_texts)) | ||
result_texts = [] | ||
additional_info_texts = [] | ||
|
||
for line_number, line in enumerate(file[start_line_of_file - 1:], | ||
start=start_line_of_file): | ||
replacement = line | ||
|
||
if enforce_newline_at_EOF: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
from bears.c_languages.ClangBear import ClangBear | ||
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 as well ;) 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. @newbazz as I told you before :) this patch was shown in CI just because of feature that I have added ;) |
||
from coalib.testing.LocalBearTestHelper import verify_local_bear | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
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. Why this change? I think you sud file a new issue for this or just include this in a different commit |
||
from bears.go.GoImportsBear import GoImportsBear | ||
from coalib.testing.LocalBearTestHelper import verify_local_bear | ||
|
||
|
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.
add spaces around
=
; new style requirement.