Skip to content

Commit

Permalink
Merge pull request #3 from samdmarshall/error-support
Browse files Browse the repository at this point in the history
adding support for changing warnings into errors
  • Loading branch information
samdmarshall authored Nov 14, 2016
2 parents e994cee + ccd8733 commit f3c3135
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
6 changes: 3 additions & 3 deletions nslocalizer/Executor/Executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ def run(cls, arguments) -> None:
if arguments.find_missing:
missing_strings = cls.findMissingStrings(xcodeproj_file, desired_targets)
# log data to xcode console
Reporter.logMissingStrings(missing_strings, arguments.ignore)
Reporter.logMissingStrings(missing_strings, arguments.ignore, arguments.error)

if arguments.find_unused:
unused_strings = cls.findUnusedStrings(xcodeproj_file, desired_targets)
# log data to xcode console
Reporter.logUnusedStrings(unused_strings)
Reporter.logUnusedStrings(unused_strings, arguments.error)

else: # pragma: no cover
missing_targets = [target for target in arguments.target if target not in desired_targets]
Expand Down Expand Up @@ -102,7 +102,7 @@ def findUnusedStrings(cls, project, targets) -> list:

for source_code_file in code_files:
data = FileOperations.getData(source_code_file)
matches = re.findall(r"NSLocalizedString\(@?\"(.*?)\",", data)
matches = re.findall(r'NSLocalizedString\(@?\"(.*?)\",', data)
Logger.write().debug('%s: %i results' % (os.path.basename(source_code_file), len(matches)))
known_strings.update(matches)
unused_strings = [lstring for lstring in base_language.strings if lstring.string not in known_strings]
Expand Down
8 changes: 4 additions & 4 deletions nslocalizer/Reporter/Reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,24 @@ def logError(file_name, line_number, message_string) -> None:
def logWarning(file_name, line_number, message_string) -> None:
log(file_name, line_number, 'warning', message_string)

def logMissingStrings(warnings_dictionary, ignore_languages, is_warning=True) -> None:
def logMissingStrings(warnings_dictionary, ignore_languages, is_error=False) -> None:
keys = list(warnings_dictionary.keys())
keys.sort(key=lambda string: string.line_number)
for key in keys:
locale_names = [language.name for language in warnings_dictionary.get(key) if language.code not in ignore_languages]
if len(locale_names):
message = ', '.join(locale_names)
message_string = 'String "%s" missing for: %s' % (key.string, message)
if is_warning is True:
if is_error is False:
logWarning(key.base.strings_file, key.line_number, message_string)
else:
logError(key.base.strings_file, key.line_number, message_string)

def logUnusedStrings(unused_strings_list, is_warning=True) -> None:
def logUnusedStrings(unused_strings_list, is_error=False) -> None:
unused_strings_list.sort(key=lambda string: string.line_number)
for unused_string in unused_strings_list:
message = 'String "%s" is not used' % unused_string.string
if is_warning is True:
if is_error is False:
logWarning(unused_string.base.strings_file, unused_string.line_number, message)
else:
logError(unused_string.base.strings_file, unused_string.line_number, message)
6 changes: 6 additions & 0 deletions nslocalizer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ def main(argv=sys.argv[1:]):
default=False,
action='store_true'
)
parser.add_argument(
'--error',
help='Changes warnings to errors',
default=False,
action='store_true'
)
parser.add_argument(
'--debug',
help=argparse.SUPPRESS,
Expand Down
2 changes: 1 addition & 1 deletion nslocalizer/version_info.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
remote_origin = '[email protected]:samdmarshall/nslocalizer.git'
commit_hash = '81f71eb'
commit_hash = 'e994cee'

0 comments on commit f3c3135

Please sign in to comment.