Coder Social home page Coder Social logo

ocstyle's Introduction

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

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.