JohnCoates/Aerial

View on GitHub
Aerial/Source/Views/PrefPanel/InfoTableSource.swift

Summary

Maintainability
A
1 hr
Test Coverage

Function tableView has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
        if tableColumn == tableView.tableColumns[0] {
            let cid = NSUserInterfaceItemIdentifier(rawValue: "InfoSourceCellID")

            if let cell = tableView.makeView(withIdentifier: cid, owner: self) as? NSTableCellView {
Severity: Minor
Found in Aerial/Source/Views/PrefPanel/InfoTableSource.swift - About 55 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function tableView has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    func tableView(_ tableView: NSTableView, acceptDrop info: NSDraggingInfo, row: Int, dropOperation: NSTableView.DropOperation) -> Bool {

        var oldIndexes = [Int]()
        info.enumerateDraggingItems(options: [], for: tableView, classes: [NSPasteboardItem.self], searchOptions: [:]) { dragItem, _, _ in
            if let str = (dragItem.item as! NSPasteboardItem).string(forType: self.dragDropType), let index = Int(str) {
Severity: Minor
Found in Aerial/Source/Views/PrefPanel/InfoTableSource.swift - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Force casts should be avoided
Open

            if let str = (dragItem.item as! NSPasteboardItem).string(forType: self.dragDropType), let index = Int(str) {

forced-type-cast

Avoid using the forced form of the type cast operator (as!) because Swift is not able to determine at compile time if the type conversion will succeed. In the event of an unsuccessful conversion, a runtime error will be triggered. The conditional form of the type cast operator (as?) is safer and should be used when possible.

Preferred

if let movie = item as? Movie {
    print("Movie: '\(movie.name)', dir. \(movie.director)")
}

Not Preferred

let movie = item as! Movie
print("Movie: '\(movie.name)', dir. \(movie.director)")

Force casts should be avoided
Open

        let tableView = notification.object as! NSTableView

forced-type-cast

Avoid using the forced form of the type cast operator (as!) because Swift is not able to determine at compile time if the type conversion will succeed. In the event of an unsuccessful conversion, a runtime error will be triggered. The conditional form of the type cast operator (as?) is safer and should be used when possible.

Preferred

if let movie = item as? Movie {
    print("Movie: '\(movie.name)', dir. \(movie.director)")
}

Not Preferred

let movie = item as! Movie
print("Movie: '\(movie.name)', dir. \(movie.director)")

Function should have at least one blank line before it
Open

    func reloadDataKeepingSelection() {

function-whitespace

Every function and method declaration should have one blank line before and after itself. An exception to this rule are functions that are declared at the start of a file (only need one blank line after their declaration) or at the end of a file (only need one blank line before their declaration). Comments immediately before a function declaration (no blank lines between them and the function) are considered to be part of the declaration.

Preferred

func function1() {
  var text = 1
  var text = 2
}

function1()

// a comment
func function2() {
  // something goes here
}

struct SomeStruct {

  func function3() {
    // something goes here
  }

  func function4() {
    // something else goes here
  };

}

func function5() {
  // something goes here
}

Not Preferred

func function1() {
  var text = 1
  var text = 2
}
function1()
// a comment
func function2() {
  // something goes here
}

struct SomeStruct {
  func function3() {
    // something goes here
  }

  func function4() {
    // something else goes here
  };
}
func function5() {
  // something goes here
}

Function should have at least one blank line before it
Open

    mutating func move(_ element: Element, to newIndex: Index) {

function-whitespace

Every function and method declaration should have one blank line before and after itself. An exception to this rule are functions that are declared at the start of a file (only need one blank line after their declaration) or at the end of a file (only need one blank line before their declaration). Comments immediately before a function declaration (no blank lines between them and the function) are considered to be part of the declaration.

Preferred

func function1() {
  var text = 1
  var text = 2
}

function1()

// a comment
func function2() {
  // something goes here
}

struct SomeStruct {

  func function3() {
    // something goes here
  }

  func function4() {
    // something else goes here
  };

}

func function5() {
  // something goes here
}

Not Preferred

func function1() {
  var text = 1
  var text = 2
}
function1()
// a comment
func function2() {
  // something goes here
}

struct SomeStruct {
  func function3() {
    // something goes here
  }

  func function4() {
    // something else goes here
  };
}
func function5() {
  // something goes here
}

Function should have at least one blank line before it
Open

    mutating func move(from oldIndex: Index, to newIndex: Index) {

function-whitespace

Every function and method declaration should have one blank line before and after itself. An exception to this rule are functions that are declared at the start of a file (only need one blank line after their declaration) or at the end of a file (only need one blank line before their declaration). Comments immediately before a function declaration (no blank lines between them and the function) are considered to be part of the declaration.

Preferred

func function1() {
  var text = 1
  var text = 2
}

function1()

// a comment
func function2() {
  // something goes here
}

struct SomeStruct {

  func function3() {
    // something goes here
  }

  func function4() {
    // something else goes here
  };

}

func function5() {
  // something goes here
}

Not Preferred

func function1() {
  var text = 1
  var text = 2
}
function1()
// a comment
func function2() {
  // something goes here
}

struct SomeStruct {
  func function3() {
    // something goes here
  }

  func function4() {
    // something else goes here
  };
}
func function5() {
  // something goes here
}

Multiline comment should end with whitespace
Open

                    : NSImage.statusUnavailableName)*/

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 */

If statement closing brace should be isolated on a separate line
Open

        if let oldIndex: Int = self.firstIndex(of: element) { self.move(from: oldIndex, to: newIndex) }

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
{
}

Function should have at least one blank line after it
Open

    }

function-whitespace

Every function and method declaration should have one blank line before and after itself. An exception to this rule are functions that are declared at the start of a file (only need one blank line after their declaration) or at the end of a file (only need one blank line before their declaration). Comments immediately before a function declaration (no blank lines between them and the function) are considered to be part of the declaration.

Preferred

func function1() {
  var text = 1
  var text = 2
}

function1()

// a comment
func function2() {
  // something goes here
}

struct SomeStruct {

  func function3() {
    // something goes here
  }

  func function4() {
    // something else goes here
  };

}

func function5() {
  // something goes here
}

Not Preferred

func function1() {
  var text = 1
  var text = 2
}
function1()
// a comment
func function2() {
  // something goes here
}

struct SomeStruct {
  func function3() {
    // something goes here
  }

  func function4() {
    // something else goes here
  };
}
func function5() {
  // something goes here
}

If statement closing brace should be isolated on a separate line
Open

        if oldIndex == newIndex { return }

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
{
}

Function should have at least one blank line after it
Open

    }

function-whitespace

Every function and method declaration should have one blank line before and after itself. An exception to this rule are functions that are declared at the start of a file (only need one blank line after their declaration) or at the end of a file (only need one blank line before their declaration). Comments immediately before a function declaration (no blank lines between them and the function) are considered to be part of the declaration.

Preferred

func function1() {
  var text = 1
  var text = 2
}

function1()

// a comment
func function2() {
  // something goes here
}

struct SomeStruct {

  func function3() {
    // something goes here
  }

  func function4() {
    // something else goes here
  };

}

func function5() {
  // something goes here
}

Not Preferred

func function1() {
  var text = 1
  var text = 2
}
function1()
// a comment
func function2() {
  // something goes here
}

struct SomeStruct {
  func function3() {
    // something goes here
  }

  func function4() {
    // something else goes here
  };
}
func function5() {
  // something goes here
}

Function should have at least one blank line after it
Open

    }

function-whitespace

Every function and method declaration should have one blank line before and after itself. An exception to this rule are functions that are declared at the start of a file (only need one blank line after their declaration) or at the end of a file (only need one blank line before their declaration). Comments immediately before a function declaration (no blank lines between them and the function) are considered to be part of the declaration.

Preferred

func function1() {
  var text = 1
  var text = 2
}

function1()

// a comment
func function2() {
  // something goes here
}

struct SomeStruct {

  func function3() {
    // something goes here
  }

  func function4() {
    // something else goes here
  };

}

func function5() {
  // something goes here
}

Not Preferred

func function1() {
  var text = 1
  var text = 2
}
function1()
// a comment
func function2() {
  // something goes here
}

struct SomeStruct {
  func function3() {
    // something goes here
  }

  func function4() {
    // something else goes here
  };
}
func function5() {
  // something goes here
}

Multiline comment should start with whitespace
Open

                /*cell.imageView?.image = NSImage(named: isEnabled

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 */

Function should have at least one blank line before it
Open

     func capitalizeFirstLetter() -> String {

function-whitespace

Every function and method declaration should have one blank line before and after itself. An exception to this rule are functions that are declared at the start of a file (only need one blank line after their declaration) or at the end of a file (only need one blank line before their declaration). Comments immediately before a function declaration (no blank lines between them and the function) are considered to be part of the declaration.

Preferred

func function1() {
  var text = 1
  var text = 2
}

function1()

// a comment
func function2() {
  // something goes here
}

struct SomeStruct {

  func function3() {
    // something goes here
  }

  func function4() {
    // something else goes here
  };

}

func function5() {
  // something goes here
}

Not Preferred

func function1() {
  var text = 1
  var text = 2
}
function1()
// a comment
func function2() {
  // something goes here
}

struct SomeStruct {
  func function3() {
    // something goes here
  }

  func function4() {
    // something else goes here
  };
}
func function5() {
  // something goes here
}

Function should have at least one blank line after it
Open

    }

function-whitespace

Every function and method declaration should have one blank line before and after itself. An exception to this rule are functions that are declared at the start of a file (only need one blank line after their declaration) or at the end of a file (only need one blank line before their declaration). Comments immediately before a function declaration (no blank lines between them and the function) are considered to be part of the declaration.

Preferred

func function1() {
  var text = 1
  var text = 2
}

function1()

// a comment
func function2() {
  // something goes here
}

struct SomeStruct {

  func function3() {
    // something goes here
  }

  func function4() {
    // something else goes here
  };

}

func function5() {
  // something goes here
}

Not Preferred

func function1() {
  var text = 1
  var text = 2
}
function1()
// a comment
func function2() {
  // something goes here
}

struct SomeStruct {
  func function3() {
    // something goes here
  }

  func function4() {
    // something else goes here
  };
}
func function5() {
  // something goes here
}

If statement closing brace should be isolated on a separate line
Open

        if abs(newIndex - oldIndex) == 1 { return self.swapAt(oldIndex, newIndex) }

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
{
}

Function should have at least one blank line after it
Open

     }

function-whitespace

Every function and method declaration should have one blank line before and after itself. An exception to this rule are functions that are declared at the start of a file (only need one blank line after their declaration) or at the end of a file (only need one blank line before their declaration). Comments immediately before a function declaration (no blank lines between them and the function) are considered to be part of the declaration.

Preferred

func function1() {
  var text = 1
  var text = 2
}

function1()

// a comment
func function2() {
  // something goes here
}

struct SomeStruct {

  func function3() {
    // something goes here
  }

  func function4() {
    // something else goes here
  };

}

func function5() {
  // something goes here
}

Not Preferred

func function1() {
  var text = 1
  var text = 2
}
function1()
// a comment
func function2() {
  // something goes here
}

struct SomeStruct {
  func function3() {
    // something goes here
  }

  func function4() {
    // something else goes here
  };
}
func function5() {
  // something goes here
}

There are no issues that match your filters.

Category
Status