Skip to content

Commit

Permalink
Add maximum size check (lyft#47)
Browse files Browse the repository at this point in the history
* Add maximum size check

* Bump version
  • Loading branch information
soffes authored and keith committed Jul 11, 2019
1 parent eeb5ae6 commit 249b2c6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ in the .xib or .storyboard file.

- `strict_font_sizes`

Ensures all fonts are above a minimum font size. Configure `minimum_size` (default is `10`) in a custom rule configuration using `rules_config` (see below).
Ensures all fonts are above a minimum font size. Configure `minimum_size` (default is `0`) and/or `maximum_size` (default is `1000`) in a custom rule configuration using `rules_config` (see below).

- `unavailable_custom_classes`

Expand Down
2 changes: 1 addition & 1 deletion xiblint/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.9.6'
__version__ = '0.9.7'
38 changes: 21 additions & 17 deletions xiblint/rules/strict_font_sizes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,35 @@ class StrictFontSizes(Rule):
Example configuration:
{
"minimum_size": 13
"minimum_size": 13,
"maximum_size": 30
}
"""
def check(self, context): # type: (XibContext) -> None
minimum_size = self.config.get('minimum_size', 10)
minimum_size = self.config.get('minimum_size', 0)
maximum_size = self.config.get('maximum_size', 1000)

for element in context.tree.findall(".//font"):
# Skip <font> tags nested in a localization comment
container = element.parent.parent.parent
if container.tag == 'attributedString' and container.get('key') == 'userComments':
continue
for element in context.tree.findall('.//font') + context.tree.findall('.//fontDescription'):
attribute_name = None

size = element.get('size')
if size is None:
context.error(element, "Invalid <font> found. Must have a size.")
continue
if element.tag == 'font':
# Skip <font> tags nested in a localization comment
container = element.parent.parent.parent
if container.tag == 'attributedString' and container.get('key') == 'userComments':
continue

if int(size) < minimum_size:
context.error(element, '"{}" is smaller than the allowed minimum size ({})'.format(size, minimum_size))
attribute_name = 'size'
else:
attribute_name = 'pointSize'

for element in context.tree.findall(".//fontDescription"):
size = element.get('pointSize')
size = element.get(attribute_name)
if size is None:
context.error(element, "Invalid <fontDescription> found. Must have a pointSize.")
context.error(element, 'Invalid <{}> found. Must have a {}.'.format(element.tag), attribute_name)
continue

if int(size) < minimum_size:
point_size = int(size)

if point_size < minimum_size:
context.error(element, '"{}" is smaller than the allowed minimum size ({})'.format(size, minimum_size))
elif point_size > maximum_size:
context.error(element, '"{}" is larger than the allowed maximum size ({})'.format(size, maximum_size))

0 comments on commit 249b2c6

Please sign in to comment.