Objective-C style checker

Related tags

Code Quality ocstyle
Overview

ocstyle

Objective-C style checker

Installation

pip install ocstyle

Example

If you have a file called test.m like this:

@implementation SomeClass

+(void) someMessage:(NSString*)subdomain {
    NSString *ShouldStartLowerCase;
    // ...
}

@end

and test.h like this:

@interface SomeClass

+ (void)someMessage:(NSString*)subdomain;

@property NSInteger value;

@end

You can check style like this:

$ ocstyle test.*
test.h
ERROR: 0:-97 [0] - ExpectedInterfaceDocInHeader - Interface requires /** documentation */
ERROR: 3:30 [51] - MissingSpace - Expected 1, got 0
ERROR: 5:1 [65] - ExpectedPropertyDocInHeader - Property requires /** documentation */

test.m
ERROR: 3:2 [28] - MissingSpace - Expected 1, got 0
ERROR: 3:9 [35] - ExtraSpace - Did not expect ' ' here
ERROR: 3:30 [56] - MissingSpace - Expected 1, got 0
ERROR: 3:42 [68] - MissingNewline - Should have newline after ;
ERROR: 3:42 [68] - MissingSemicolon - Expected a semicolon
ERROR: 4:35 [104] - BadLocalVariableName - Local variable must start with a lower case letter```

Goal

Make it easy to share and enforce style rules for Objective C. The less human time we spend thinking about whitespace and naming the better! Also enforces the existence of basic documentation.

At Cue we use this as a git pre-commit hook. This way we ensure everyone maintains a consistent coding style with a minimum of effort.

Related

OCLint runs static analysis that helps to detect common logic errors. Use it alongside ocstyle!

Status

This is a pretty early stage project. We fully expect bugs and feature requests!

One notable absence is that right now style rules are not configurable. For example, we use the following style for message implementations:

+(void) someMessage:(NSString*)subdomain;
{
}

Note the inclusion of the ; and the { being on the next line. We like this style because it makes it easy to copy and paste from .h to .m and back, but maybe you have your own preferences. We'd be very happy to accept pull requests that make ocstyle more configurable.

For the motivated pull requesters out there, other notable TODOs include:

  • Allow inline disabling of specific errors.

  • Fix various whitespace false negatives noted in test files

Links

ocstyle is built using parcon, a really nice parser generator library for Python.

Other linters and style checkers we use at Cue include:

License

Apache License version 2.0

Authors

Cue

You might also like...
Style Art library process images using COREML with a set of pre trained machine learning models and convert them to Art style.
Style Art library process images using COREML with a set of pre trained machine learning models and convert them to Art style.

StyleArt Style Art is a library that process images using COREML with a set of pre trained machine learning models and convert them to Art style. Prev

STPopup provides STPopupController, which works just like UINavigationController in popup style, for both iPhone and iPad. It's written in Objective-C and compatible with Swift.
STPopup provides STPopupController, which works just like UINavigationController in popup style, for both iPhone and iPad. It's written in Objective-C and compatible with Swift.

STPopup STPopup provides STPopupController, which works just like UINavigationController in popup style, for both iPhone and iPad. It's written in Obj

The Objective-C Style Guide used by The New York Times

NYTimes Objective-C Style Guide This style guide outlines the coding conventions of the iOS teams at The New York Times. We welcome your feedback in i

Style guide & coding conventions for Objective-C projects

This repository is no longer active. These guidelines build on Apple's existing Coding Guidelines for Cocoa. Unless explicitly contradicted below, ass

Objective-c code Apple style documentation set generator.

About appledoc IMPORTANT NOTICE: collaborators needed appledoc is command line tool that helps Objective-C developers generate Apple-like source code

Airbnb's Swift Style Guide.

Airbnb Swift Style Guide Goals Following this style guide should: Make it easier to read and begin understanding unfamiliar code. Make code easier to

LinkedIn's Official Swift Style Guide

Swift Style Guide Make sure to read Apple's API Design Guidelines. Specifics from these guidelines + additional remarks are mentioned below. This guid

 The Official raywenderlich.com Swift Style Guide.
The Official raywenderlich.com Swift Style Guide.

The Official raywenderlich.com Swift Style Guide. Updated for Swift 5 This style guide is different from others you may see, because the focus is cent

Arrow  🏹 Parse JSON with style
Arrow 🏹 Parse JSON with style

Arrow 🏹 Parse JSON with style

Rough lets you draw in a sketchy, hand-drawn-like, style.
Rough lets you draw in a sketchy, hand-drawn-like, style.

Rough (Swift) Rough lets you draw in a sketchy, hand-drawn-like, style. It is Swift clone of Rough.js. The library defines primitives to draw lines, c

A tool to enforce Swift style and conventions.
A tool to enforce Swift style and conventions.

SwiftLint A tool to enforce Swift style and conventions, loosely based on the now archived GitHub Swift Style Guide. SwiftLint enforces the style guid

💾 A collection of classic-style UI components for iOS
💾 A collection of classic-style UI components for iOS

A collection of classic-style UI components for UIKit, influenced by Windows 95 Introduction This is a little exploration into applying '90s-era desig

Kit for building custom gauges + easy reproducible Apple's style ring gauges.
Kit for building custom gauges + easy reproducible Apple's style ring gauges.

GaugeKit ##Kit for building custom gauges + easy reproducible Apple's style ring gauges. - Example Usage Open GaugeKit.xcworkspace and change the sch

A simple style messages/notifications, in Swift.
A simple style messages/notifications, in Swift.

Demo Example To show notifications use the following code: self.showMessage("Something success", type: .success) To display a notice on a view: view.s

A simple, customizable popup dialog for iOS written in Swift. Replaces UIAlertController alert style.
A simple, customizable popup dialog for iOS written in Swift. Replaces UIAlertController alert style.

Introduction Popup Dialog is a simple, customizable popup dialog written in Swift. Features Easy to use API with hardly any boilerplate code Convenien

Elegant Apply Style by Swift Method Chain.🌙
Elegant Apply Style by Swift Method Chain.🌙

ApplyStyleKit ApplyStyleKit is a library that applies styles to UIKit using Swifty Method Chain. Normally, when applying styles to UIView etc.,it is n

A fully customizable popup style menu for iOS 😎
A fully customizable popup style menu for iOS 😎

Guide Check out the documentation and guides for details on how to use. (Available languages:) English 简体中文 What's a better way to know what PopMenu o

Demonstrates hosting SwiftUI in a UISplitViewController to gain the sidebar style in Mac Catalyst
Demonstrates hosting SwiftUI in a UISplitViewController to gain the sidebar style in Mac Catalyst

Really trivial example showing how to wrap SwiftUI in a UISplitViewController, so that you can use the correct sidebar background style when building for macOS.

BDD-style framework for Swift
BDD-style framework for Swift

Sleipnir Sleipnir is a BDD-style framework for Swift. Sleipnir is highly inspired by Cedar. Also In Norse mythology, Sleipnir is Odin's steed, is the

Comments
  • Why does it expect newlines?

    Why does it expect newlines?

    So I was looking at your example and I'm confused about something

    So I copied in the text for test.m and kept fixing things until it ended up being this @implementation SomeClass

    • (void)someMessage:(NSString *)subdomain { NSString *shouldStartLowerCase; }

    @end

    But then you get the error

    ERROR: 3:43 [69] - MissingNewline - Should have newline after ; ERROR: 3:43 [69] - MissingSemicolon - Expected a semicolon

    Does it think that the .m file is a .h file or am I missing some kinda style that I don't fully comprehend here?

    opened by HaloZero 2
  • Allow users to specify maximum line length on the command-line.

    Allow users to specify maximum line length on the command-line.

    We use an 80 character line length at Maginatics, and I'd like ocstyle to enforce that. This pull request adds support for specifying the maximum line length on the command-line. I'm open to any suggestions and improvements you may have.

    (Thanks for open-sourcing ocstyle! I'm a big believer in automating these sort of processes.)

    opened by vibhav 1
  • Support for other code Format

    Support for other code Format

    I feel following is the more used standard code format for methods -

        + (void)someMessage:(NSString *)subdomain {
        }
    

    Is it possible to select different coding style ?

    opened by leapfrog-bishalghimire 3
Owner
Cue
Cue
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 unif

Square 1.1k Nov 17, 2022
A static source code analysis tool to improve quality and reduce defects for C, C++ and Objective-C

OCLint - https://oclint.org OCLint is a static code analysis tool for improving quality and reducing defects by inspecting C, C++ and Objective-C code

The OCLint Static Code Analysis Tool 3.6k Dec 29, 2022
JSPatch bridge Objective-C and Javascript using the Objective-C runtime. You can call any Objective-C class and method in JavaScript by just including a small engine. JSPatch is generally used to hotfix iOS App.

JSPatch 中文介绍 | 文档 | JSPatch平台 请大家不要自行接入 JSPatch,统一接入 JSPatch 平台,让热修复在一个安全和可控的环境下使用。原因详见 这里 JSPatch bridges Objective-C and JavaScript using the Object

bang 11.4k Jan 1, 2023
RxValidator Easy to Use, Read, Extensible, Flexible Validation Checker.

RxValidator Easy to Use, Read, Extensible, Flexible Validation Checker. It can use without Rx. Requirements RxValidator is written in Swift 4.

GeumSang Yoo 153 Nov 17, 2022
Updeto is a simple package that help update checker for iOS Apps

Updeto is a simple package that will help you to check if the currently installed version is the same as the latest one available on App Store.

Manuel Sánchez 8 Jul 8, 2022
Comment-Spell-Checker - Xcode extension for spell checking and auto-correcting code comments.

Comment Spell Checker An Xcode Source Editor extension that runs spell check and auto correct on your code comments. Features Supports mutliple commen

Velislava Yanchina 157 Aug 28, 2022
Cryptocurrency price checker, build with UIKit and MVC + Delegate pattern.

Coin Check Cryptocurrency price checker. The app fetch from CoinAPI.io the latest coin prices, build with UIKit and MVC + Delegate pattern. Features S

Anibal Ventura 0 Jan 10, 2022
SwiftDependencyChecker - Swift Dependency Checker

SwiftDependencyChecker SwiftDependencyChecker can be installed with homebrew wit

Kristiina 34 Dec 6, 2022
SwiftPublicSuffixList - Public Suffix List domain name checker in Swift

SwiftPublicSuffixList This library is a Swift implementation of the necessary co

Dave Poirier 0 Jan 31, 2022
SwiftLint - A tool to enforce Swift style and conventions, loosely based on Swift Style Guide.

SwiftLint - A tool to enforce Swift style and conventions, loosely based on Swift Style Guide.

Realm 16.9k Dec 30, 2022