Skip to content
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 8 commits into from
May 14, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions tools/sqf_linter.py
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))
Copy link
Member

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.


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()