• Stars
    star
    1,126
  • Rank 39,749 (Top 0.9 %)
  • Language
    Objective-C
  • License
    Other
  • Created almost 9 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Commit fully-formatted Objective-C as a team without even trying.

[ Space Commander]

[ Space Commander] provides tools which enable a team of iOS developers to commit Objective-C code to a git repository using a unified style format, without requiring any manual fixup.

Corgi image

You can use it to:

  • Enforce formatting conventions before code is committed.
  • Format code with a single command (both individual files or the entire repo).
  • Fail a build (during a pull request) if unformatted code made it into the branch.

At Square, [ Space Commander] has streamlined iOS development, especially when it comes to pull requests. Applying formatting standards no longer requires manual developer attention; that time is better spent elsewhere!

You may wish to fork [ Space Commander] to apply your team's particular set of formatting rules (more details below), or clone to enjoy Square's flavor of Objective-C formatting.

Installation Locally

To add formatting pre-commit checks to your repo, from the target repo, run path/to/spacecommander/setup-repo.sh.

Usage

After running setup-repo.sh, formatting checks will run automatically before every commit.

To format an individual file and modify it in place, run format-objc-file.sh <file>. To format it without modification, run format-objc-file-dry-run.sh <file>

To format all of the Objective-C files in your repository in-place, run format-objc-files-in-repo.sh.

Details

To install the pre-commit hook, each developer on the project runs the setup script. This installs a precommit hook which will verify that code is formatted before the commit succeeds.

If there were formatting errors during the commit, a script to fixup code automatically can be run in order to commit without error.

At Square, this formatting repository is referenced as a submodule of a larger iOS project, so that the formatting rules and scripts are locked to a revision of the parent repository. This way, we can check the formatting as part of the build process, and fail the build if the formatting is not current (we can also check out older SHAs without any difficulty).

clang-format expects the custom rules file to exist in the same directory that the command is run from, and so a .gitignore-d symlink of the rules file is added to the target repository. It is a symlink so that the developer only needs to update the git SHA of the formatting repository to get the latest formatting rules from upstream.

Configuration

To format files only within selected directories, specify the name each directory in a file named .formatting-directory, separated by newlines (and without whitespace escaped). Otherwise, all Objective-C files tracked in the repo will be checked.

To ignore files within directories, add the name of each directory on a new line to a file named .formatting-directory-ignore.

To modify the formatting output, edit the following:

  • .clang-format for built in clang-format options.
  • format-objc-file-dry-run.sh and format-objc-file.sh for rules that are implemented in custom/.
  • Testing Support/ files to validate your changes.

Add #pragma Formatter Exempt or // MARK: Formatter Exempt as the first line of the file if the formatter should ignore it.

Installation for Pull Request Validation

The following instructions are Square-specific. We use a build system called mobuild. The hook that we use, which can be integrated into other build systems, is format-objc-mobuild

If you want style checking as a mandatory step to get a mergeable PR, do the following:

  • Add this repository as a cocoapod, or add it as a submodule in a Scripts/ directory.
  • Ensure that your repository has setup .sqiosbuild.json and .stashkins files at the top level (more info on the Square wiki page titled All About Mobuild).
  • The build machines are setup to check for the above conditions, and if they're met, automatically run format-objc-mobuild.
  • Open a PR with a modified Objective-C file to verify these checks are running.

Updating Style Options

Change formatting policies by modifying .clang-format. Available style options are listed on the clang website.

Please also update UnformattedExample.m (under ./Testing Support/) with an example of code that your formatting changes should correct.

Then, update FormattedExample.m (in the same place) with the expected result, and verify that your changes produce the desired result by running a simple test: ./test.sh

Custom Formatters

clang-format is fantastic and we love it, but it has some limitations. We've added our own ad-hoc formatting capabilities through scripts which live in custom/. If you add a custom file formatting script to custom/, invoke it in format-objc-file.sh and format-objc-file-dry-run.sh and add examples of input / output to files in Testing Support/.

Undesired Result?

The formatter can't do everything. It may occasionally produce an undesirable result, in which case you can either:

  • Refactor code to produce a line that is simpler and less confusing to the formatter.
  • Use // clang-format off and // clang-format on to selectively enable/disable clang-format for specific lines of a file.
  • Add #pragma Formatter Exempt or // MARK: Formatter Exempt as the first line of the file, and it will not be formatted at all.
  • Wislawa Szymborska said "All imperfection is easier to tolerate if served up in small doses." [ Space Commander] will remove nearly all formatting imperfections, but you may need to tolerate an occasional deviation from the expected result.

Contributing

We’re glad you’re interested in [ Space Commander], and we’d love to see where you take it. Please read our contributing guidelines prior to submitting a Pull Request.

Thanks, and happy formatting!

More Repositories

1

okhttp

Square’s meticulous HTTP client for the JVM, Android, and GraalVM.
Kotlin
45,250
star
2

retrofit

A type-safe HTTP client for Android and the JVM
HTML
42,581
star
3

leakcanary

A memory leak detection library for Android.
Kotlin
29,130
star
4

picasso

A powerful image downloading and caching library for Android
Kotlin
18,656
star
5

javapoet

A Java API for generating .java source files.
Java
10,691
star
6

moshi

A modern JSON library for Kotlin and Java.
Kotlin
9,502
star
7

okio

A modern I/O library for Android, Java, and Kotlin Multiplatform.
Kotlin
8,667
star
8

dagger

A fast dependency injector for Android and Java.
Java
7,317
star
9

crossfilter

Fast n-dimensional filtering and grouping of records.
JavaScript
6,222
star
10

PonyDebugger

Remote network and data debugging for your native iOS app using Chrome Developer Tools
Objective-C
5,867
star
11

maximum-awesome

Config files for vim and tmux.
Ruby
5,706
star
12

otto

An enhanced Guava-based event bus with emphasis on Android support.
Java
5,174
star
13

cubism

Cubism.js: A JavaScript library for time series visualization.
JavaScript
4,930
star
14

sqlbrite

A lightweight wrapper around SQLiteOpenHelper which introduces reactive stream semantics to SQL operations.
Java
4,574
star
15

android-times-square

Standalone Android widget for picking a single date from a calendar view.
Java
4,437
star
16

wire

gRPC and protocol buffers for Android, Kotlin, Swift and Java.
Kotlin
4,174
star
17

Valet

Valet lets you securely store data in the iOS, tvOS, or macOS Keychain without knowing a thing about how the Keychain works. It’s easy. We promise.
Swift
3,957
star
18

cube

Cube: A system for time series visualization.
JavaScript
3,912
star
19

kotlinpoet

A Kotlin API for generating .kt source files.
Kotlin
3,805
star
20

java-code-styles

IntelliJ IDEA code style settings for Square's Java and Android projects.
Shell
2,957
star
21

flow

Name UI states, navigate between them, remember where you've been.
Java
2,789
star
22

spoon

Distributing instrumentation tests to all your Androids.
HTML
2,700
star
23

keywhiz

A system for distributing and managing secrets
Java
2,614
star
24

tape

A lightning fast, transactional, file-based FIFO for Android and Java.
Java
2,459
star
25

certstrap

Tools to bootstrap CAs, certificate requests, and signed certificates.
Go
2,194
star
26

mortar

A simple library that makes it easy to pair thin views with dedicated controllers, isolated from most of the vagaries of the Activity life cycle.
Java
2,159
star
27

go-jose

An implementation of JOSE standards (JWE, JWS, JWT) in Go
1,981
star
28

Cleanse

Lightweight Swift Dependency Injection Framework
Swift
1,773
star
29

assertj-android

A set of AssertJ helpers geared toward testing Android.
Java
1,578
star
30

haha

DEPRECATED Java library to automate the analysis of Android heap dumps.
Java
1,436
star
31

phrase

Phrase is an Android string resource templating library
Java
1,403
star
32

cane

Code quality threshold checking as part of your build
Ruby
1,325
star
33

seismic

Android device shake detection.
Java
1,275
star
34

anvil

A Kotlin compiler plugin to make dependency injection with Dagger 2 easier.
Kotlin
1,265
star
35

sudo_pair

Plugin for sudo that requires another human to approve and monitor privileged sudo sessions
Rust
1,230
star
36

square.github.io

A simple, static portal which outlines our open source offerings.
CSS
1,108
star
37

workflow

A Swift and Kotlin library for making composable state machines, and UIs driven by those state machines.
Shell
1,107
star
38

workflow-kotlin

A Swift and Kotlin library for making composable state machines, and UIs driven by those state machines.
Kotlin
982
star
39

certigo

A utility to examine and validate certificates in a variety of formats
Go
917
star
40

logcat

I CAN HAZ LOGZ?
Kotlin
893
star
41

radiography

Text-ray goggles for your Android UI.
Kotlin
831
star
42

whorlwind

Makes fingerprint encryption a breeze.
Java
819
star
43

dagger-intellij-plugin

An IntelliJ IDEA plugin for Dagger which provides insight into how injections and providers are used.
Java
798
star
44

cycler

Kotlin
793
star
45

Paralayout

Paralayout is a set of simple, useful, and straightforward utilities that enable pixel-perfect layout in iOS. Your designers will love you.
Swift
771
star
46

apropos

A simple way to serve up appropriate images for every visitor.
Ruby
766
star
47

shift

shift is an application that helps you run schema migrations on MySQL databases
Ruby
735
star
48

coordinators

Simple MVWhatever for Android
Java
703
star
49

subzero

Block's Bitcoin Cold Storage solution.
C
667
star
50

Blueprint

Declarative UI construction for iOS, written in Swift
Swift
659
star
51

shuttle

String extraction, translation and export tools for the 21st century. "Moving strings around so you don't have to"
Ruby
657
star
52

gifencoder

A pure Java library implementing the GIF89a specification. Suitable for use on Android.
Java
654
star
53

pollexor

Java client for the Thumbor image service which allows you to build URIs in an expressive fashion using a fluent API.
Java
633
star
54

intro-to-d3

a D3.js tutorial
CSS
603
star
55

kochiku

Shard your builds for fun and profit
Ruby
602
star
56

curtains

Lift the curtain on Android Windows!
Kotlin
570
star
57

RxIdler

An IdlingResource for Espresso which wraps an RxJava Scheduler.
Java
512
star
58

svelte-store

TypeScript
494
star
59

field-kit

FieldKit lets you take control of your text fields.
JavaScript
463
star
60

burst

A unit testing library for varying test data.
Java
462
star
61

SuperDelegate

SuperDelegate provides a clean application delegate interface and protects you from bugs in the application lifecycle
Swift
454
star
62

otto-intellij-plugin

An IntelliJ IDEA plugin to navigate between events posted by Otto.
Java
453
star
63

js-jose

JavaScript library to encrypt/decrypt data in JSON Web Encryption (JWE) format and to sign/verify data in JSON Web Signature (JWS) format. Leverages Browser's native WebCrypto API.
JavaScript
424
star
64

sharkey

Sharkey is a service for managing certificates for use by OpenSSH
Go
390
star
65

connect-api-examples

Code samples demonstrating the functionality of the Square Connect API
JavaScript
381
star
66

fdoc

Documentation format and verification
Ruby
379
star
67

ETL

Extract, Transform, and Load data with Ruby
Ruby
377
star
68

lgtm

Simple object validation for JavaScript.
JavaScript
366
star
69

laravel-hyrule

Object-oriented, composable, fluent API for writing validations in Laravel
PHP
341
star
70

in-app-payments-flutter-plugin

Flutter Plugin for Square In-App Payments SDK
Objective-C
332
star
71

papa

PAPA: Performance of Android Production Applications
Kotlin
331
star
72

pysurvival

Open source package for Survival Analysis modeling
HTML
319
star
73

pylink

Python Library for device debugging/programming via J-Link
Python
317
star
74

workflow-swift

A Swift and Kotlin library for making composable state machines, and UIs driven by those state machines.
Swift
302
star
75

rails-auth

Modular resource-based authentication and authorization for Rails/Rack
Ruby
288
star
76

cocoapods-generate

A CocoaPods plugin that allows you to easily generate a workspace from a podspec.
Ruby
272
star
77

inspect

inspect is a collection of metrics gathering, analysis utilities for various subsystems of linux, mysql and postgres.
Go
267
star
78

Aardvark

Aardvark is a library that makes it dead simple to create actionable bug reports.
Objective-C
257
star
79

jetpack

jet.pack: package your JRuby rack app for Jetty.
Ruby
249
star
80

gradle-dependencies-sorter

A CLI app and Gradle plugin to sort the dependencies in your Gradle build scripts
Kotlin
242
star
81

luhnybin

Shell
232
star
82

auto-value-redacted

An extension for Google's AutoValue that omits redacted fields from toString().
Java
211
star
83

protoparser

Java parser for .proto schema declarations.
Java
209
star
84

squalor

Go SQL utility library
Go
203
star
85

p2

Platypus Platform: Tools for Scalable Deployment
Go
196
star
86

mimecraft

Utility for creating RFC-compliant multipart and form-encoded HTTP request bodies.
Java
195
star
87

Listable

Declarative list views for iOS apps.
Swift
189
star
88

git-fastclone

git clone --recursive on steroids
Ruby
185
star
89

zapp

Continuous Integration for KIF
Objective-C
179
star
90

metrics

Metrics Query Engine
Go
170
star
91

ruby-rrule

RRULE expansion for Ruby
Ruby
168
star
92

quotaservice

The purpose of a quota service is to prevent cascading failures in micro-service environments. The service acts as a traffic cop, slowing down traffic where necessary to prevent overloading services. For this to work, remote procedure calls (RPCs) between services consult the quota service before making a call. The service isn’t strictly for RPCs between services, and can even be used to apply quotas to database calls, for example.
Go
154
star
93

wire-gradle-plugin

A Gradle plugin for generating Java code for your protocol buffer definitions with Wire.
Groovy
153
star
94

goprotowrap

A package-at-a-time wrapper for protoc, for generating Go protobuf code.
Go
148
star
95

beancounter

Utility to audit the balance of Hierarchical Deterministic (HD) wallets. Supports multisig + segwit wallets.
Go
143
star
96

womeng_handbook

Everything you need to start or expand a women in engineering group in your community.
129
star
97

cocoapods-check

A CocoaPods plugin that shows differences between locked and installed Pods
Ruby
126
star
98

rce-agent

gRPC-based Remote Command Execution Agent
Go
125
star
99

spincycle

Automate and expose complex infrastructure tasks to teams and services.
Go
118
star
100

in-app-payments-react-native-plugin

Objective-C
116
star