Giter Site home page Giter Site logo

xiblint's Introduction

xiblint

The xiblint script will test .xib and .storyboard files for compliance with best practices and team policies.

The linter messages contain the position within the XML files, and if applicable, an Object ID which can be used in conjunction with Xcode's Find in Workspace to jump to the problematic object in the .xib or .storyboard file.

Rules

  • accessibility_format

    Checks for incorrect use of Lyft extensions accessibilityFormat and accessibilitySources.

  • accessibility_labels_for_images

    Checks for images with accessibility enabled and no accessibility label. In this case, VoiceOver will announce the image asset's name, which might be unwanted.

  • accessibility_labels_for_image_buttons

    Checks for image buttons with no accessibility label. In this case, VoiceOver will announce the image asset's name, which might be unwanted.

  • accessibility_labels_for_text_with_placeholder

    Checks for text fields and views with a placeholder and no accessibility label. This addresses common confusion about placeholderText coming instead of accessibilityLabel.

  • autolayout_frames

    Checks for ambiguous and misplaced views.

  • automation_identifiers

    Makes sure that interactive views have accessibility identifiers, to support testing through UI Automation.

  • automation_identifiers_for_outlet_labels

    Checks for labels with outlets into a view controller that have no accessibility identifiers. Labels with outlets might get dynamic text, and therefore should be accessible to UI testing.

  • enforce_runtime_attributes

    Ensures a runtime attribute is set to one of the allowed values. Configure runtime_attributes in a custom rule configuration using rules_config (see below). Use null as an option to allow no value.

  • enforce_system_properties

    Ensures a property in a system type is set to one of the allowed values. Configure system_properties in a custom rule configuration using rules_config (see below). Use null as an option to allow default value.

  • named_colors

    Ensures all colors are using named colors from an asset catalog. Configure allowed_colors to limit the colors to a subset (default is all named colors are allowed), allow_system_colors (default is false), allow_clear_color (default is false) and ignore_alpha (default is false) in a custom rule configuration using rules_config (see below).

  • no_trait_variations

    Ensures Trait Variations are disabled.

  • simulated_metrics_retina4_0

    Ensures simulated metrics are for the iPhone SE, which is currently the smallest display profile.

  • no_view_controller_links_to_other_bundles

    Ensures there are no links to other storyboards in different bundles.

  • strict_fonts

    Ensures all font names and sizes are in an allowed set. Configure allowed_fonts with an array of dictionaries containing a name and size in a custom rule configuration using rules_config (see below).

  • strict_font_names

    Ensures all font namess are in an allowed set. Configure allowed_fonts and allow_system_fonts (default is true) in a custom rule configuration using rules_config (see below). This is a good option if strict_fonts is too strict.

  • strict_font_sizes

    Ensures all font sizes 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). This is a good option if strict_fonts is too strict.

  • unavailable_custom_classes

    Prevent a list of classes from appearing as custom classes. Configure custom_classes in a custom rule configuration using rules_config (see below). This is a mapping of the full name of the class (ModuleName.ClassName) to the suggested replacement.

  • unavailable_system_classes

    Ensures a system type uses a set of custom clases. Configure system_classes in a custom rule configuration using rules_config (see below).

Usage

For a list of available rules, run xiblint -h.

Place a configuration file named .xiblint.json into the root of your source repository. A sample configuration file would be:

{
  "rules": [
    "accessibility_format",
    "autolayout_frames"
  ],
  "paths": {
    "Pods": {
      "rules": []
    },
    "InaccessibleFeature": {
      "excluded_rules": [
        "accessibility_*"
      ]
    },
    "Modules": {
      "rules": ["some_rule"],
      "rules_config": {
        "some_rule": {
          "some_rule_specific_option": true
        }
      }
    }
  }
}

Then simply invoke xiblint in the source repository.

--reporter

If you find yourself in need of a different structure of the output, there is the --reporter option. You are able to choose from the default one, raw, or a json one. To switch between them, use the following:

xiblint --reporter json
xiblint --reporter raw

Specyfing paths

Sometimes you want to lint only a few files and forget about the rest - for instance, when you want to lint only delta changes. For this case you can specify your files after the xiblint command:

xiblint "Project/Base.lproj/LaunchScreen.storyboard" "Project/Base.lproj/Main.storyboard"

If you want to combine paths with the reporter option, don't forget to put the option before listing the paths:

xiblint --reporter json "Project/Base.lproj/LaunchScreen.storyboard" "Project/Base.lproj/Main.storyboard"

Installation

Using pip:

pip install xiblint

Manual:

git clone https://github.com/lyft/xiblint.git
cd xiblint && python setup.py install

Contributing

Code of conduct

This project is governed by Lyft's code of conduct. All contributors and participants agree to abide by its terms.

Sign the Contributor License Agreement (CLA)

We require a CLA for code contributions, so before we can accept a pull request we need to have a signed CLA. Please visit our CLA service and follow the instructions to sign the CLA.

File issues in GitHub

Use GitHub issue to file bugs or enhancement requests. You may also use GitHub issues to discuss before implementing a change.

Submit pull requests

Our only method of accepting code changes is through GitHub pull requests.

xiblint's People

Contributors

adamawolf avatar asottile avatar codeman9 avatar dirtyhabits97 avatar dschaller avatar gabriellanata avatar ikonst avatar keith avatar sberrevoets avatar soffes avatar sunshinejr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

xiblint's Issues

Custom rule

How to add a new custom rule to check if accessibility is enabled on all controllers present in xib/storyboard ?

Feature request: single view XIB

When developing I usually follow the pattern to have only a single view in XIB & it's class is the same as XIB name as well.

Moreover if XIB contains table view cell then it's reuse identifier matches class name.

I'd be more than happy to implement those if they're welcomed.

ExpatError: no element found: line 1, column 0

I installed xiblint 0.9.1 and am trying to run it against a codebase of a few hundred xibs and storyboards. I'm getting this error that's preventing it from proceeding.

Error

Traceback (most recent call last):
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/xml/etree/ElementTree.py", line 1637, in close
    self.parser.Parse("", 1) # end of data
xml.parsers.expat.ExpatError: no element found: line 1, column 0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/xiblint", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.7/site-packages/xiblint/__main__.py", line 67, in main
    errors += process_file(file_path, config)
  File "/usr/local/lib/python3.7/site-packages/xiblint/__main__.py", line 79, in process_file
    context = XibContext(file_path)
  File "/usr/local/lib/python3.7/site-packages/xiblint/xibcontext.py", line 10, in __init__
    self.tree = parse_xml(path)
  File "/usr/local/lib/python3.7/site-packages/xiblint/xmlutils.py", line 32, in parse_xml
    tree = ElementTree.parse(file_path, parser=parser)
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/xml/etree/ElementTree.py", line 1197, in parse
    tree.parse(source, parser)
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/xml/etree/ElementTree.py", line 605, in parse
    self._root = parser.close()
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/xml/etree/ElementTree.py", line 1639, in close
    self._raiseerror(v)
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/xml/etree/ElementTree.py", line 1531, in _raiseerror
    raise err
xml.etree.ElementTree.ParseError: no element found: line 1, column 0

.xiblint.json:

{
    "rules": [
        "accessibility_labels_for_image_buttons",
        "accessibility_labels_for_images",
        "accessibility_labels_for_text_with_placeholder",
        "autolayout_frames",
        "automation_identifiers",
        "automation_identifiers_for_outlet_labels",
        "no_simulated_metrics",
        "no_trait_variations",
        "simulated_metrics_retina4_0"
    ],
    "include_paths": [
        "Apps",
        "Customer Apps",
        "Features",
        "Infrastructure",
        "Shared Frameworks"
    ]
}

Running on macOS High Sierra with Xcode 10 beta 5 as my command line tools. I am running Python 3.7 installed via Homebrew. Please let me know if you need any additional information

PyPI version is out of date

Hey, I was messing around with this to see if it could work for my team and I ran into a weird parsing bug. I went to verify the issue and I discovered that the version of xiblint on PyPI is 0.7.0, when the latest tag appears to be 0.9.1. Is there a reason for this, and if there isn't, could a maintainer please update the index?

Unavailable system classes rule

I'm trying incorporate xiblint in an app, and was having trouble getting the unavailable_system_classes rule to work. From the code, it looks like we just include a system_classes key, with the objects we're looking for.
I currently have something like

{
    "rules":[unavailable_system_classes]
    "system_classes": {
        "button": ["MyModule.RandomButtonClass"]
    }
}

shouldn't it looks for buttons in the xibs that don't have customClass set to RandomButtonClass? I looked in the xib code, and they have button tags, but i'm unable to produce any xiblint errors

Cannot run xiblint

Hi there,

I would like to try xiblint (sounds like a nice tool), but I could not get it to run.

I keep getting this error:

Traceback (most recent call last):
  File "/Users/bogdanp/.pyenv/versions/3.6.10/bin/xiblint", line 8, in <module>
    sys.exit(main())
  File "/Users/bogdanp/.pyenv/versions/3.6.10/lib/python3.6/site-packages/xiblint/__main__.py", line 27, in main
    from patch_element_tree import patch_element_tree
ModuleNotFoundError: No module named 'patch_element_tree'

I tried running it with python 2, 3.6 and even 3.7, same error.
I tried installing via pip or even cloning locally the git repo + python setup.py install, same error.

Can you assist me, please?

My current environment:

MacOS Catalina 10.15.4
Xcode 11.3.1
pyenv 1.2.18
python 3.6.10
pip 20.0.2
xiblint 0.9.14

I see the patch_element_tree.py is there on disk, but apparently it's not getting imported.

ls ~/.pyenv/versions/3.6.10/lib/python3.6/site-packages/xiblint/
__init__.py
__main__.py
__pycache__
config.py
patch_element_tree.py
rules
xibcontext.py
xibutils.py
xmlutils.py

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.