-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add enforce_system_properties rule (#55)
* Add enforce_system_properties rule
- Loading branch information
1 parent
2e4b2bf
commit bc00cc1
Showing
3 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '0.9.12' | ||
__version__ = '0.9.13' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from xiblint.rules import Rule | ||
from xiblint.xibcontext import XibContext | ||
|
||
|
||
class EnforceSystemProperties(Rule): | ||
""" | ||
Ensures unavailable system properties are not used. | ||
Example configuration: | ||
{ | ||
"system_properties": { | ||
"label": { | ||
"adjustsFontForContentSizeCategory": ["YES"] | ||
}, | ||
"button": { | ||
"reversesTitleShadowWhenHighlighted": [null, "NO"] | ||
} | ||
} | ||
} | ||
""" | ||
def check(self, context): # type: (XibContext) -> None | ||
system_properties = self.config.get('system_properties', {}) | ||
|
||
for tag_name in system_properties.keys(): | ||
for element in context.tree.findall('.//{}'.format(tag_name)): | ||
tag_name = element.tag | ||
enforced_properties = system_properties.get(tag_name) | ||
for property_name in enforced_properties.keys(): | ||
property_allowed_values = enforced_properties.get(property_name) | ||
property_value = element.get(property_name) | ||
|
||
if property_value in property_allowed_values: | ||
continue | ||
|
||
options_string = '`, `'.join(map(str, property_allowed_values)) | ||
context.error(element, '`<{}>` property `{}` must use `{}` instead of `{}`.' | ||
.format(tag_name, property_name, options_string, property_value)) |