-
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
Merged
Merged
SQF Lint Cleanup Pass #5157
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
638bd80
SQF Lint Cleanup Pass
PabstMirror f3831de
Fix var in TRACE
PabstMirror ad547a8
Add basic python tool
PabstMirror e01950b
Simplify
PabstMirror 1f496ff
Hit space key 6 times
PabstMirror dfa28d3
Fix error in dropNozzle
PabstMirror 6b96f68
handle error message exceptions
PabstMirror d5c50d0
Fix py
PabstMirror 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 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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/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): | ||
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 -1 | ||
|
||
exceptions = sqf.analyzer.analyze(result).exceptions | ||
if (exceptions): | ||
print("{}:".format(filename)) | ||
for e in exceptions: | ||
writer.write(' [%d,%d]:%s\n' % (e.position[0], e.position[1] - 1, e.message)) | ||
return len(exceptions) | ||
|
||
return 0 | ||
|
||
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: | ||
ret = analyze(filename) | ||
if (ret < 0): | ||
all_errors = all_errors + 1 | ||
else: | ||
all_warnings = all_warnings + ret | ||
|
||
print ("Parse Errors {0} - Warnings {1}".format(all_errors,all_warnings)) | ||
|
||
# return (all_errors + all_warnings) | ||
return all_errors | ||
|
||
if __name__ == "__main__": | ||
main() |
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.
2 space instead of 4 space indentation.