diff --git a/support/coding/check_style_guide.py b/support/coding/check_style_guide.py index f60a477b7e..524c1d2350 100644 --- a/support/coding/check_style_guide.py +++ b/support/coding/check_style_guide.py @@ -40,6 +40,7 @@ guards for correctness. At the moment this includes: * The correct submodule is used * Checking for duplicates between all files * Checking that no file includes glm header directly + * Checking whether any files starts with the UTF-8 Byte-order mark If this script is executed from the base directory of OpenSpace, no arguments need to be passed, otherwise the first and only argument has to point to the base directory. @@ -175,6 +176,15 @@ def check_copyright(lines): +def check_byte_order_mark_character(lines): + c = lines[0][0] + if c == 'ï': + return 'File contains UTF-8 byte mark order character' + + return '' + + + def check_naming_convention_component(lines, component): ifndef_symbol, _ = get_ifndef_symbol(lines) @@ -233,6 +243,8 @@ def check_glm_header(lines, file): else: return '' + + def check_core_dependency(lines, component): if component != "openspace_core": return '' @@ -244,6 +256,8 @@ def check_core_dependency(lines, component): else: return '' + + def check_using_namespace(lines): index = [i for i,s in enumerate(lines) if "using namespace" in s.strip()] @@ -253,6 +267,7 @@ def check_using_namespace(lines): return '' + previousSymbols = {} def check_header_file(file, component): with open(file, 'r+') as f: @@ -318,6 +333,12 @@ def check_header_file(file, component): if using_namespaces: print(file, '\t', 'Using namespace found in header file') + bom = check_byte_order_mark_character(lines) + if bom: + print(file, '\t', 'Byte order mark failed:', bom) + + + def check_inline_file(file, component): with open(file, 'r+') as f: lines = f.readlines() @@ -334,6 +355,10 @@ def check_inline_file(file, component): if core_dependency: print(file, '\t', 'Wrong dependency (core depends on module)', core_dependency) + bom = check_byte_order_mark_character(lines) + if bom: + print(file, '\t', 'Byte order mark failed:', bom) + if (not '_doc.inl' in file): # The _doc.inl files are allowed to use using namespace as they are inclued # from the cpp files and thus don't leak it @@ -342,6 +367,7 @@ def check_inline_file(file, component): print(file, '\t', 'Using namespace found in inline file') + def check_source_file(file, component): with open(file, 'r+') as f: lines = f.readlines() @@ -358,6 +384,9 @@ def check_source_file(file, component): if copyright: print(file, '\t', 'Copyright check failed', '\t', copyright) + bom = check_byte_order_mark_character(lines) + if bom: + print(file, '\t', 'Byte order mark failed:', bom) @@ -373,6 +402,7 @@ def check_files(positiveList, negativeList, component, check_function): + basePath = './' if len(sys.argv) > 1: basePath = sys.argv[1] + '/' diff --git a/support/coding/remove_byte_order_mark.py b/support/coding/remove_byte_order_mark.py new file mode 100644 index 0000000000..d61a4c44a2 --- /dev/null +++ b/support/coding/remove_byte_order_mark.py @@ -0,0 +1,49 @@ +""" +OpenSpace + +Copyright (c) 2014-2017 + +Permission is hereby granted, free of charge, to any person obtaining a copy of this +software and associated documentation files (the "Software"), to deal in the Software +without restriction, including without limitation the rights to use, copy, modify, +merge, publish, distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE +OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +This script removes a UTF-8 byte-mark order character 'ï' from the passed file +""" + +import sys + +if len(sys.argv) == 1: + print('Usage: remove_byte_order_mark.py ') +else: + remove_bom = False + file = sys.argv[1] + l = [] + with open(file, 'r+') as f: + lines = f.readlines() + c = lines[0][0] + if c == 'ï': + remove_bom = True + l = lines + else: + print('No UTF-8 BOM present in this file') + + if remove_bom: + with open(file, 'w') as f: + print('Removing UTF-8 BOM from file') + # We the representation of the BOM is three characters long + lines[0] = lines[0][3:] + f.write(''.join(lines))