-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Tidy improvements #21619
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
Tidy improvements #21619
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1ce8665
mk: Split tidy into multiple tidy rules
brson 0e16ad8
Polish errorck and featureck UI
brson 290b79c
Clean up tidy scripts, coverage, performance
brson 29be938
mk: Remove redundant valgrind notices in build
brson 62c90fc
mk: Add tidy commands to 'make tips'
brson 4368f61
mk: Add version number to output. Useful for logs
brson 68ddd73
testparser has long lines
brson 1364919
mk: Print test summary after tidy when running 'make check'
brson 3454c50
Address review feedback
brson d0e82a6
Tidy fixes
brson 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
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
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
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
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
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
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 |
---|---|---|
|
@@ -51,78 +51,155 @@ def do_license_check(name, contents): | |
if not check_license(name, contents): | ||
report_error_name_no(name, 1, "incorrect license") | ||
|
||
|
||
file_names = [s for s in sys.argv[1:] if (not s.endswith("_gen.rs")) | ||
and (not ".#" in s)] | ||
|
||
current_name = "" | ||
current_contents = "" | ||
check_tab = True | ||
check_cr = True | ||
check_linelength = True | ||
|
||
if len(sys.argv) < 2: | ||
print "usage: tidy.py <src-dir>" | ||
sys.exit(1) | ||
|
||
src_dir = sys.argv[1] | ||
|
||
try: | ||
for line in fileinput.input(file_names, | ||
count_lines = 0 | ||
count_non_blank_lines = 0 | ||
|
||
interesting_files = ['.rs', '.py', '.js', '.sh', '.c', '.h'] | ||
|
||
file_counts = {ext: 0 for ext in interesting_files} | ||
file_counts['other'] = 0 | ||
|
||
def update_counts(current_name): | ||
global file_counts | ||
_, ext = os.path.splitext(current_name) | ||
|
||
if ext in file_counts: | ||
file_counts[ext] += 1 | ||
else: | ||
file_counts['other'] += 1 | ||
|
||
all_paths = set() | ||
|
||
for (dirpath, dirnames, filenames) in os.walk(src_dir): | ||
|
||
# Skip some third-party directories | ||
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. Similarly, we could probably define a set/list of skippable directories near the start of the file. skippable_dirs = {
'src/jemalloc',
'src/llvm',
# ...
'src/rust-installer'
}
if any(d in dirpath for d in skippable_dirs):
continue |
||
skippable_dirs = { | ||
'src/jemalloc', | ||
'src/llvm', | ||
'src/gyp', | ||
'src/libbacktrace', | ||
'src/libuv', | ||
'src/compiler-rt', | ||
'src/rt/hoedown', | ||
'src/rustllvm', | ||
'src/rt/valgrind', | ||
'src/rt/msvc', | ||
'src/rust-installer' | ||
} | ||
|
||
if any(d in dirpath for d in skippable_dirs): | ||
continue | ||
|
||
def interesting_file(f): | ||
if "miniz.c" in f \ | ||
or "jquery" in f \ | ||
or "rust_android_dummy" in f: | ||
return False | ||
|
||
return any(os.path.splitext(f)[1] == ext for ext in interesting_files) | ||
|
||
file_names = [os.path.join(dirpath, f) for f in filenames | ||
if interesting_file(f) | ||
and not f.endswith("_gen.rs") | ||
and not ".#" is f] | ||
|
||
if not file_names: | ||
continue | ||
|
||
for line in fileinput.input(file_names, | ||
openhook=fileinput.hook_encoded("utf-8")): | ||
|
||
if "tidy.py" not in fileinput.filename(): | ||
filename = fileinput.filename() | ||
|
||
if "tidy.py" not in filename: | ||
if "TODO" in line: | ||
report_err("TODO is deprecated; use FIXME") | ||
match = re.match(r'^.*/(\*|/!?)\s*XXX', line) | ||
if match: | ||
report_err("XXX is no longer necessary, use FIXME") | ||
match = re.match(r'^.*//\s*(NOTE.*)$', line) | ||
if match and "TRAVIS" not in os.environ: | ||
m = match.group(1) | ||
if "snap" in m.lower(): | ||
report_warn(match.group(1)) | ||
match = re.match(r'^.*//\s*SNAP\s+(\w+)', line) | ||
if match: | ||
hsh = match.group(1) | ||
date, rev = snapshot.curr_snapshot_rev() | ||
if not hsh.startswith(rev): | ||
report_err("snapshot out of date (" + date | ||
+ "): " + line) | ||
else: | ||
if "SNAP" in line: | ||
report_warn("unmatched SNAP line: " + line) | ||
|
||
if cr_flag in line: | ||
check_cr = False | ||
if tab_flag in line: | ||
check_tab = False | ||
if linelength_flag in line: | ||
check_linelength = False | ||
if "TODO" in line: | ||
report_err("TODO is deprecated; use FIXME") | ||
match = re.match(r'^.*/(\*|/!?)\s*XXX', line) | ||
if match: | ||
report_err("XXX is no longer necessary, use FIXME") | ||
match = re.match(r'^.*//\s*(NOTE.*)$', line) | ||
if match and "TRAVIS" not in os.environ: | ||
m = match.group(1) | ||
if "snap" in m.lower(): | ||
report_warn(match.group(1)) | ||
match = re.match(r'^.*//\s*SNAP\s+(\w+)', line) | ||
if match: | ||
hsh = match.group(1) | ||
date, rev = snapshot.curr_snapshot_rev() | ||
if not hsh.startswith(rev): | ||
report_err("snapshot out of date (" + date | ||
+ "): " + line) | ||
else: | ||
if "SNAP" in line: | ||
report_warn("unmatched SNAP line: " + line) | ||
|
||
if check_tab and ('\t' in line and | ||
"Makefile" not in fileinput.filename()): | ||
report_err("tab character") | ||
if check_cr and not autocrlf and '\r' in line: | ||
report_err("CR character") | ||
if line.endswith(" \n") or line.endswith("\t\n"): | ||
report_err("trailing whitespace") | ||
line_len = len(line)-2 if autocrlf else len(line)-1 | ||
|
||
if check_linelength and line_len > cols: | ||
report_err("line longer than %d chars" % cols) | ||
|
||
if fileinput.isfirstline() and current_name != "": | ||
do_license_check(current_name, current_contents) | ||
|
||
if fileinput.isfirstline(): | ||
current_name = fileinput.filename() | ||
current_contents = "" | ||
check_cr = True | ||
check_tab = True | ||
check_linelength = True | ||
|
||
current_contents += line | ||
|
||
if check_tab and ('\t' in line and | ||
"Makefile" not in filename): | ||
report_err("tab character") | ||
if check_cr and not autocrlf and '\r' in line: | ||
report_err("CR character") | ||
if line.endswith(" \n") or line.endswith("\t\n"): | ||
report_err("trailing whitespace") | ||
line_len = len(line)-2 if autocrlf else len(line)-1 | ||
|
||
if check_linelength and line_len > cols: | ||
report_err("line longer than %d chars" % cols) | ||
|
||
if fileinput.isfirstline(): | ||
# This happens at the end of each file except the last. | ||
if current_name != "": | ||
update_counts(current_name) | ||
assert len(current_contents) > 0 | ||
do_license_check(current_name, current_contents) | ||
|
||
current_name = filename | ||
current_contents = "" | ||
check_cr = True | ||
check_tab = True | ||
check_linelength = True | ||
|
||
# Put a reasonable limit on the amount of header data we use for | ||
# the licenseck | ||
if len(current_contents) < 1000: | ||
current_contents += line | ||
|
||
count_lines += 1 | ||
if line.strip(): | ||
count_non_blank_lines += 1 | ||
|
||
if current_name != "": | ||
update_counts(current_name) | ||
assert len(current_contents) > 0 | ||
do_license_check(current_name, current_contents) | ||
|
||
except UnicodeDecodeError as e: | ||
report_err("UTF-8 decoding error " + str(e)) | ||
|
||
for ext in file_counts: | ||
print "* linted " + str(file_counts[ext]) + " " + ext + " files" | ||
print "* total lines of code: " + str(count_lines) | ||
print "* total non-blank lines of code: " + str(count_non_blank_lines) | ||
|
||
sys.exit(err) |
Oops, something went wrong.
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.
I think that using a dictionary to track the file counts will make it easier to maintain in the long run.