Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A security blanket for Xcode project files

License

NotificationsYou must be signed in to change notification settings

americanexpress/xcprojectlint

Repository files navigation

Overview

This project provides a security blanket, ensuring neither your co-workers, norgit screw up your Xcode project file. Some of the settings are arguably a matterof personal taste. Fortunately, each option can be enabled separately.xcprojectlintcurrently supports these checks:

  • build-settings-externalized

    This mode ensures there are no settings configured at the project level,instead encouraging the use of xcconfig files.

  • dangling-source-files

    Ensures all source code files are members of a target.

  • disk-layout-matches-project

    This mode ensures the project references reflect actual file systemlocations. There are some occasions where you may not be able to exactly mapa folder to disk (Frameworks and Products are common examples). For this,there is an additional parameter you can pass:--skip-folders, followed bya list of folders to ignore.

  • files-exist-on-disk

    This mode finds file references in the project which are not backed by files.

  • empty-groups

    This mode reports groups that contain no additional items.

  • items-in-alpha-order

    This mode ensures the project files and folders are in proper order.There are some occasions where you may not be able to exactly sort itemsin specific folders (Frameworks and Products are common examples). For this,there is an additional parameter you can pass:--skip-folders, followed bya list of folders to ignore.

  • no-white-space-specifications

    This mode ensures that no file or project contains whitespace specifications of:indentWidth, tabWidth, usesTabs, or lineEnding.

  • all

    For convenience, this mode runs all of the above tests.

When a failing condition is detected, as much useful context as possible isemitted toSTDOUT, enabling Xcode to display the errors, in place. Further, itoptionally can returnEX_SOFTWARE, preventing the build from succeeding untilthe problem is addressed.

Building the Code

To buildxcprojectlint tool, run

$ swift package update$ make build

To work with the projects and tests in Xcode, run

$ xed.

Usage Examples

as a build script phase:

bin/xcprojectlint --report error --validations all --project$PROJECT_FILE_PATH

as a shell command:

xcprojectlint --report error --validations files-exist-on-disk items-in-alpha-order--project /tmp/Example/Example.xcproject

The Nitty Gritty

xcprojectlint is operating on an undocumented file format. Years of looking at brokengit merges has given us a reasonable confidence that we know how the parts allwork together. That said, it is still a best guess, so there may be oversights.Fortunately, these linting operations are read-only, and will not modify yourproject file.

Each run starts by parsing the project file into a series of collections, whichrepresent our understanding of how a project file is composed. It uses both theproperty list structure, and the comments Xcode writes into the project toassemble its data. Afterwards, xcprojectlint applies validity tests to the extractedcollections, ensuring that the rules specified are met.

Clues to Fix By

As much as possible, xcprojectlint will attempt to tell you how to locate the problem.It’ll tell you which build configuration has settings, what the expected orderof a group is, and whatever else it can squeeze out of the available context.Sometimes, it’ll even tell you the line number in the project file to look at.This is great, butdo not attempt to view the project within Xcode. Terrible,terrible things will happen. Instead, use your favorite text editor to peerinside.

The Rules

  • Build Settings Externalized

    We iterate all theBuildConfiguration blobs, and investigate theirBuildSettings entry. Empty settings are A-OK. Any found settings are inerror.

  • Dangling Source Files

    Iterating through all the source files that appear in the Project Navigator ofa project file, and ensures all are associated with a target within the sameproject/workspace. Any dangling files found will result in an error. This isparticularly useful for test files.

  • Disk Layout Matches Project

    This test grabs theMainGroup out of the project, then recursivelytraverses the children. If the child node is a file, we retrieve theFileReference by id, then check for aname value. The presence of a nameindicates this file reference does not have a matching file on disk.

  • Files Exist on Disk

    This uses a similar recursion to the Layout test, but instead ofinvestigating thename value, it builds a URL to where the file shouldappear on disk. This is done by assembling the path that led to the file,then appending that to a path derived from the project’s path on disk, thenfinally testing for the presence of a file at that location.

  • Empty Groups

    One of the simpler tests. We again recurse theMainGroup, but this timelook for entries that have zero children.

  • Items in Alpha Order

    We expect our project nodes to contain alphabetized Folders, followed byalphabetized files. We check on that by again recursing the groups, and ateach level sifting the entries intogroupNames,fileNames, andallNames. We sort the groups and files, contatenate them, then comparethat to the list of everything.

  • No White Space Specifications

    Xcode has a way to, at the user-level, specify custom settings for tabs, spaces,indentation amount, and line endings withinPreferences -> Text Editing -> Indentation. Formatting preferences can also be set at a file or project level,altering the experience for team-members if passed through PR unnoticed. Thisrule aims to alieviate the existence of any whitespace specification and providesthe appropriate messages for each and their location within the project file.

Contributing

We welcome your interest in the American Express Open Source Community on Github.Any contributor to any Open Source Project managed by the American Express OpenSource Community must accept and sign an agreement indicating agreement to theterms below. Except for the rights granted in this agreement to American Expressand to recipients of software distributed by American Express, You reserve allright, title, and interest, if any, in and to your contributions. Pleasefillout the agreement.

Please feel free to open pull requests. Before submitting a PR, please run yourcode throughswiftformat with the config file provided:swiftformat --config swiftformat.config Sources/ Tests/

License

Any contributions made under this project will be governed by theApache License2.0.

Code of Conduct

This project adheres to theAmerican Express CommunityGuidelines.By participating, you are expected to honor these guidelines.

About

A security blanket for Xcode project files

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors11


[8]ページ先頭

©2009-2025 Movatter.jp