Bloombox/Swift

View on GitHub

Showing 103 of 106 total issues

Function closing brace should be isolated on a separate line
Open

  func prepare() { /* default: no-op */ }
Severity: Minor
Found in Sources/Client/RPCLogic.swift by tailor

brace-style

Definitions of - class - struct - function - Control flow constructs (if, else if, else, switch, for, while, repeat-while) - init - protocol - enum - closure - Getters and Setters (set, get) - extension

should follow the One True Brace Style (1TBS): each construct has its opening brace one the same line along with the same indentation level as its header, the statements within the braces are indented, and the closing brace at the end is on the same indentation level as the header of the function at a line of its own. Braces are not omitted for a control statement with only a single statement in its scope. Every opening brace must also have one space preceding it.

Classes

Preferred

class SomeClass {
}

class SomeClass: SomeSuperClass {
}

Not Preferred

class SomeClass
{
}

class SomeClass: SomeSuperClass{
}

Structs

Preferred

struct SomeStruct {
}

struct SomeStruct : SomeParentStruct {
}

Not Preferred

struct SomeStruct
{
}

struct SomeStruct : SomeParentStruct  {
}

Functions

Preferred

func someMethod() {
}

func someOtherFunction () -> () {
}

Not Preferred

func someMethod()
{
}

func someOtherFunction () -> ()
{
}

Control flow constructs

  • if, else if, and else statement

Preferred

if SomeCondition {

} else if someOtherCondition {
} else {
}

Not Preferred

if SomeCondition
{

}
else if someOtherCondition
{
}
else
{
}
  • switch statement

Preferred

switch SomeData {
    default:
        break
}

Not Preferred

switch SomeData
{
    default:
        break
}
  • for loop

Preferred

for var i = 0; i < 10; i+=1 {

}

Not Preferred

for var i = 0; i < 10; i+=1
{

}
  • while loop

Preferred

while SomeCondition {

}

Not Preferred

while SomeCondition
{

}
  • repeat-while loop

Preferred

repeat {

} while SomeCondition

Not Preferred

repeat
{

} while SomeCondition

Initializers

Preferred

init(someParameter:Double, someOtherParameter:Double) {
   self.someMember = someParameter
   self.someOtherMember = someOtherParameter
}

Not Preferred

init(someParameter:Double, someOtherParameter:Double)
{
   self.someMember = someParameter
   self.someOtherMember = someOtherParameter
}

Protocols

Preferred

protocol SomeProtocol {

}

protocol SomeOtherProtocol : X {

}

Not Preferred

protocol SomeProtocol
{

}

protocol SomeOtherProtocol : X
{
}

Enums

Preferred

enum SomeEnum {
    case A, B, C, D
}

enum SomeEnum {
    case A
    case B
    case C
    case D
}

enum SomeEnum: Int {
    case A, B, C = 5, D
}

Not Preferred

enum SomeEnum
{
    case A, B, C, D
}

enum SomeEnum
{
    case A
    case B
    case C
    case D
}

enum SomeEnum: Int
{
    case A, B, C = 5, D
}

Closures

Preferred

func someFunction () -> () {
// closure
}

Not Preferred

func someFunction () -> ()
{
// closure
}

Setters and Getters

  • set

Preferred

set {
    oldValue = newValue / 2
}

Not Preferred

set
{
    oldValue = newValue / 2
}
  • get

Preferred

get {
    return value * 2
}

Not Preferred

get
{
    return value * 2
}

Extensions

Preferred

extension someExtension {
}

Not Preferred

extension someExtension
{
}

Multiline comment should end with whitespace
Open

**/

comment-whitespace

Prefer at least one whitespace character after a comment opening symbol (//, ///, /*, or /**) and at least one whitespace character before a comment closing symbol (*/).

Preferred

// This is a comment

/// This is a documentation comment

/* This is a
multi-line comment */

/* This is a
multi-line comment
*/

/** This is a
documentation multi-line
comment
*/

Not Preferred

//This is a comment

///This is a documentation comment

/*This is a
multi-line comment*/

/**This is a multi-line
documentation comment */

Initializer expression should not be enclosed within parentheses
Open

    let eventPayload: ProtobufStruct? = (

redundant-parentheses

Control flow constructs (if, else if, switch, for, while, repeat-while, and guard statements), Exception handling constructs (throw, and do/catch statements), and Initializers (array, dictionary, initializer patterns) should not be enclosed in parentheses.

Additionally, method calls with no parameters and a trailing closure should not have empty parentheses following the method name.

Control flow constructs

  • if, else if statement

Preferred

if SomeCondition {

} else if SomeOtherCondition {
}

Not Preferred

if (SomeCondition) {

} else if (SomeOtherCondition) {
}
  • switch statement

Preferred

switch SomeData {
    default:
        break
}

Not Preferred

switch (SomeData) {
    default:
        break
}
  • for loop

Preferred

for var i = 0; i < 10; i+=1 {

}

Not Preferred

for (var i = 0; i < 10; i+=1) {

}
  • while loop

Preferred

while SomeCondition {

}

Not Preferred

while (SomeCondition) {

}
  • repeat-while loop

Preferred

repeat {

} while SomeCondition

Not Preferred

repeat {

} while (SomeCondition)
  • guard clause

Preferred

guard true else {   }

Not Preferred

guard (true) else {   }

Exception handling constructs

  • do/catch statement

Preferred

do  {

} catch SomeException {

}

Not Preferred

do  {

} catch (SomeException) {

}
  • throw statement

Preferred

throw SomeException

Not Preferred

throw (SomeException)

Initializers

  • array items

Preferred

var shoppingList: [String] = ["Eggs", "Milk"]

Not Preferred

var shoppingList: [String] = [("Eggs"), ("Milk")]
  • dictionary items

Preferred

var airports: [String: String] = ["YYZ": "Toronto Pearson", "DUB": "Dublin"]

Not Preferred

var airports: [String: String] = [("YYZ"): ("Toronto Pearson"), ("DUB"): ("Dublin")]
  • initializer patterns

Preferred

var x: Int = 2
var y: String = "Sleekbyte"
var x = 2

Not Preferred

var x: Int = (2)
var y: String = ("Sleekbyte")
var x = (2)

Method calls

Preferred

items.map {
  item in item.transform()
}

Not Preferred

items.map() {
  item in item.transform()
}
Severity
Category
Status
Source
Language