Skip to content

Commit

Permalink
Update test_enforce_style.py
Browse files Browse the repository at this point in the history
  • Loading branch information
bittlingmayer authored Jan 13, 2024
1 parent 6a5acc2 commit f021598
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions .github/tests/test_enforce_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from .find_missing_links import walk_directory

# Checks that we use UK spellings for words that differ between the UK and US
# Permits US spellings for proper nouns.

# Load the English language model for Spacy
NLP = spacy.load("en_core_web_sm")
Expand Down Expand Up @@ -54,16 +56,21 @@ def check_spellings(file_path):
raw_word = re.sub(r'^[^a-zA-Z\'-]*|[^a-zA-Z\'-]*$', '', word)

if raw_word:
# Skip words that have the same spelling in both US and UK English or are wrong for both
if ((us.check(raw_word) == uk.check(raw_word)) or (uk.check(raw_word) and not us.check(raw_word))):
continue

# Skip CamelCase and all-uppercase words
if is_camel_case(raw_word) or raw_word.isupper():
continue
# Check if the word is a proper noun in context
assert is_proper_noun_in_context(_line, raw_word), \
f'US-specific spelling: "{raw_word}" in {file_path} \n\n\t at the line: {line} \n\n\tsuggestions: {uk.suggest(raw_word)} \n'

# If a US word but not a UK word
if us.check(raw_word) and not uk.check(raw_word)

# Check if the word is a proper noun in context
# This is a relatively expensive check.
assert is_proper_noun_in_context(_line, raw_word), f'''US-specific spelling:
"{ raw_word }" in { file_path }
line: { line }
suggestions: { uk.suggest(raw_word) }
'''

EXCLUDE_DIRS = ['vendor']
EXCLUDE_FILES = ['README.md', 'CHANGELOG.md']
Expand Down

0 comments on commit f021598

Please sign in to comment.