Skip to content

Commit

Permalink
Fix sqf_validator to work with # command (#1043)
Browse files Browse the repository at this point in the history
**When merged this pull request will:**
- Rename semiColumn to correct spelling semiColon
- Fix the # command to check if there is only whitespace before it, to differentiate between preprocessor command and select command.
  • Loading branch information
neilzar authored and jonpas committed Jan 5, 2019
1 parent cc91385 commit 85d9212
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions tools/sqf_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def popClosing():
inStringType = '';

lastIsCurlyBrace = False
checkForSemiColumn = False
checkForSemiColon = False
onlyWhitespace = True

# Extra information so we know what line we find errors at
lineNumber = 1
Expand All @@ -61,9 +62,10 @@ def popClosing():
for c in content:
if (lastIsCurlyBrace):
lastIsCurlyBrace = False
checkForSemiColumn = True
checkForSemiColon = True

if c == '\n': # Keeping track of our line numbers
onlyWhitespace = True # reset so we can see if # is for a preprocessor command
lineNumber += 1 # so we can print accurate line number information when we detect a possible error
if (isInString): # while we are in a string, we can ignore everything else, except the end of the string
if (c == inStringType):
Expand All @@ -87,7 +89,7 @@ def popClosing():
if (c == '"' or c == "'"):
isInString = True
inStringType = c
elif (c == '#'):
elif (c == '#' and onlyWhitespace):
ignoreTillEndOfLine = True
elif (c == '/'):
checkIfInComment = True
Expand Down Expand Up @@ -117,11 +119,14 @@ def popClosing():
print("ERROR: Tab detected at {0} Line number: {1}".format(filepath,lineNumber))
bad_count_file += 1

if (checkForSemiColumn):
if (c not in [' ', '\t', '\n']):
onlyWhitespace = False

if (checkForSemiColon):
if (c not in [' ', '\t', '\n', '/']): # keep reading until no white space or comments
checkForSemiColumn = False
checkForSemiColon = False
if (c not in [']', ')', '}', ';', ',', '&', '!', '|', '='] and not validKeyWordAfterCode(content, indexOfCharacter)): # , 'f', 'd', 'c', 'e', 'a', 'n', 'i']):
print("ERROR: Possible missing semi-column ';' detected at {0} Line number: {1}".format(filepath,lineNumber))
print("ERROR: Possible missing semicolon ';' detected at {0} Line number: {1}".format(filepath,lineNumber))
bad_count_file += 1

else: # Look for the end of our comment block
Expand Down

0 comments on commit 85d9212

Please sign in to comment.