-
Notifications
You must be signed in to change notification settings - Fork 740
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
SQF Lint Cleanup Pass #5157
SQF Lint Cleanup Pass #5157
Changes from 7 commits
638bd80
f3831de
ad547a8
e01950b
1f496ff
dfa28d3
6b96f68
d5c50d0
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Requires: https://github.com/LordGolias/sqf | ||
|
||
import fnmatch | ||
import os | ||
import sys | ||
import argparse | ||
from sqf.parser import parse | ||
import sqf.analyzer | ||
from sqf.exceptions import SQFParserError | ||
|
||
|
||
def analyze(filename, writer=sys.stdout): | ||
warnings = 0 | ||
errors = 0 | ||
with open(filename, 'r') as file: | ||
code = file.read() | ||
try: | ||
result = parse(code) | ||
except SQFParserError as e: | ||
print("{}:".format(filename)) | ||
writer.write(' [%d,%d]:%s\n' % (e.position[0], e.position[1] - 1, e.message)) | ||
return 0, -1 | ||
|
||
exceptions = sqf.analyzer.analyze(result).exceptions | ||
if (exceptions): | ||
print("{}:".format(filename)) | ||
for e in exceptions: | ||
if (e.message.startswith("error")): | ||
errors = errors + 1 | ||
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.
|
||
else: | ||
warnings = warnings + 1 | ||
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.
|
||
writer.write(' [%d,%d]:%s\n' % (e.position[0], e.position[1] - 1, e.message)) | ||
|
||
return warnings, errors | ||
|
||
def main(): | ||
print("#########################") | ||
print("# Lint Check #") | ||
print("#########################") | ||
|
||
sqf_list = [] | ||
all_warnings = 0 | ||
all_errors = 0 | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('-m','--module', help='only search specified module addon folder', required=False, default=".") | ||
args = parser.parse_args() | ||
|
||
for root, dirnames, filenames in os.walk('../addons' + '/' + args.module): | ||
for filename in fnmatch.filter(filenames, '*.sqf'): | ||
sqf_list.append(os.path.join(root, filename)) | ||
|
||
for filename in sqf_list: | ||
warnings, errors = analyze(filename) | ||
all_warnings = all_warnings + warnings | ||
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.
|
||
all_errors = all_errors + errors | ||
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.
|
||
|
||
print ("Parse Errors {0} - Warnings {1}".format(all_errors,all_warnings)) | ||
|
||
# return (all_errors + all_warnings) | ||
return all_errors | ||
|
||
if __name__ == "__main__": | ||
main() |
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.
What's the reason this returns a
-1
for number of errors? I feel like it should be 0, but perhaps I'm missing somethingThere 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.
-1 used to mean error, but I changed it, thanks for catching