Skip to content

Instantly share code, notes, and snippets.

@sydcurie
Forked from raphaelmor/checkstyleRules.md
Created August 12, 2011 02:45
Show Gist options
  • Save sydcurie/1141333 to your computer and use it in GitHub Desktop.
Save sydcurie/1141333 to your computer and use it in GitHub Desktop.
Rules for an Objective-C checkstyle tool

#Formating options for .h / .m

##File

###Rules

  • No EmptyLine at begining of file
  • No EmptyLine at end of file
  • Must start with FileCommentBlock
  • Must end with @end

##EmptyLine

###Identification

  • Contains only space, tabs and newline

##FileCommentBlock

###Rules

  • First line must be //
  • Second line must be // ${filename}
  • Third line must be // ${projectname}
  • Fourth line must be //
  • Fifth line must be // Created by ${author} on ${date}.
  • Sixth line must be // Copyright ${year} ${company}. All rights reserved.
  • Seventh line must be//
  • Other lines must be // ${anything}
  • Last line must be //
  • Must be followed by an EmptyLine

##ImportLine (optional)

###Identification

  • Starts with 0+ whitespaces then #import

###Rules

  • Must be preceded by EmptyLine or another ImportLine
  • Must start with #import
  • Must be followed by EmptyLine or another ImportLine

##DefineLine (optional)

###Identification

  • Starts with 0+ whitespaces then #define

###Rules

  • Must be preceded by EmptyLine or another DefineLine
  • Must start with #define
  • Must be followed by EmptyLine or another DefineLine

##ClassCommentLine

###Identification

  • Starts with 0+ whitespaces then //
  • Followed by a ClassCommentLine or an InterfaceLine

###Rules

  • Must be preceded by ClassCommentLine of EmptyLine
  • Must start with //
  • Must be followed by ClassCommentLine of InterfaceLine

##InterfaceLines

###Identification

  • Starts with 0+ whitespaces then @interface

Rules

  • Must end with {
  • Must be preceded by ClassCommentLine
  • Must start with @interface
  • if contains : then must have : (space+colon+space)
  • if contains < then must have < (no space around <) and > (no space around >)
  • Must end with { (space+brace)
  • Must be followed by EmptyLine

##CommentLine

###Identification

  • Starts with 0+ whitespaces then //

##ScopeLine

###Identification

  • Contains @private or @public

###Rules

  • Must be preceded by EmptyLine or CommentLine
  • Must start with @public or @private

##EndBraceTopLevel

###Identification

  • Starts with } (no space in front)

###Rules

  • Must be preceded by EmptyLine or CommentLine
  • Must be followed by EmptyLine

##PropertyLine

###Identification

  • contains @property

###Rules

  • Must be preceded by EmptyLine or CommentLine or PropertyLine
  • Must end with ; (no space)
  • Must be followed by EmptyLine or PropertyLine

##MethodCommentLine

###Identification

  • Starts with // (no space before)
  • Followed by 0 or more MethodCommentLine then an MethodDeclarationLine

###Rules

  • Must be preceded by MethodCommentLine of EmptyLine
  • Must be followed by MethodCommentLine of MethodDeclarationLine

##MethodDeclarationLine

###Identification

  • Starts with 0+ whitespaces then - or +
  • Does not contain {
  • Is not followed by 0+ EmptyLine then a line that starts with {

###Rules

  • Must be preceded by MethodCommentLine
  • Must have no space before sign
  • Must have a space after sign
  • If contains : then must have no space before or after
  • If contains ( then must have no space before or after
  • If contains ) then must have no space before or after
  • If contains ; then ** Must have no space before ; ** Must be followed by EmptyLine
  • If doesn't contain ; ** Must contain : ** Must be followed by PartialDeclarationLine

##PartialDeclarationLine

###Identification

  • Preceded by PartialDeclarationLine or MethodDeclarationLine
  • Starts with 0+ whitespaces then letters
  • Contains :, ( and )

###Rules

  • Must not have spaces around : :, ( and )
  • If contains ; ** Must have no space before ; ** Must be followed by EmptyLine
  • If doesn't contain ; ** Must be followed by PartialDeclarationLine

##EndLine

###Identification

  • Contains @end

###Rules

  • Must be preceded by EmptyLine or CommentLine

##TODO

  • Write implementation (.m) file rules
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment