aequitas/macos-menubar-wireguard

View on GitHub
WireGuardStatusbar/INIParser.swift

Summary

Maintainability
C
1 day
Test Coverage

Function parse has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring.
Open

  internal func parse(line: String) throws -> ContentType? {
    var cache = ""
    var state = State.Variable
    let stack = Stack<State>()

Severity: Minor
Found in WireGuardStatusbar/INIParser.swift - About 7 hrs 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 parse has 76 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  internal func parse(line: String) throws -> ContentType? {
    var cache = ""
    var state = State.Variable
    let stack = Stack<State>()

Severity: Major
Found in WireGuardStatusbar/INIParser.swift - About 3 hrs to fix

    Avoid deeply nested control flow statements.
    Open

                if var sec = _sections[currentTitle] {
                  sec[variable] = value
                  _sections[currentTitle] = sec
                } else {
                  var sec: [String: String] = [:]
    Severity: Major
    Found in WireGuardStatusbar/INIParser.swift - About 45 mins to fix

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

      // TODO: figure out how to get this using package manager (Cocoapods/SwiftPM,Carthage)
      // or get rid of config file parsing altogether?
      
      //
      //  INIParser.swift
      Severity: Major
      Found in WireGuardStatusbar/INIParser.swift and 1 other location - About 1 hr to fix
      WireGuardStatusbar/INIParser.swift on lines 1..181

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 71.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Enum case names should be lowerCamelCase
      Open

          case Title, Variable, Value, SingleQuotation, DoubleQuotation
      Severity: Minor
      Found in WireGuardStatusbar/INIParser.swift by tailor

      lower-camel-case

      method and var names should follow lowerCamelCase naming convention: first letter of the entire word is lowercase, but subsequent first letters are uppercase.

      Method and selector names

      Preferred

      func someMethod() {
          // method definition goes here
      }

      Not Preferred

      func some-method() {
          // method definition goes here
      }

      Variable names

      Preferred

      var someVariable = someValue

      Not Preferred

      var Some_Var1able = someValue

      Enum case names should be lowerCamelCase
      Open

          case Assignment(String, String)
      Severity: Minor
      Found in WireGuardStatusbar/INIParser.swift by tailor

      lower-camel-case

      method and var names should follow lowerCamelCase naming convention: first letter of the entire word is lowercase, but subsequent first letters are uppercase.

      Method and selector names

      Preferred

      func someMethod() {
          // method definition goes here
      }

      Not Preferred

      func some-method() {
          // method definition goes here
      }

      Variable names

      Preferred

      var someVariable = someValue

      Not Preferred

      var Some_Var1able = someValue

      Variable names should be lowerCamelCase
      Open

        internal var _anonymousSection: [String: String] = [:]
      Severity: Minor
      Found in WireGuardStatusbar/INIParser.swift by tailor

      lower-camel-case

      method and var names should follow lowerCamelCase naming convention: first letter of the entire word is lowercase, but subsequent first letters are uppercase.

      Method and selector names

      Preferred

      func someMethod() {
          // method definition goes here
      }

      Not Preferred

      func some-method() {
          // method definition goes here
      }

      Variable names

      Preferred

      var someVariable = someValue

      Not Preferred

      var Some_Var1able = someValue

      Variable names should be lowerCamelCase
      Open

        internal var _sections: [String: [String: String]] = [:]
      Severity: Minor
      Found in WireGuardStatusbar/INIParser.swift by tailor

      lower-camel-case

      method and var names should follow lowerCamelCase naming convention: first letter of the entire word is lowercase, but subsequent first letters are uppercase.

      Method and selector names

      Preferred

      func someMethod() {
          // method definition goes here
      }

      Not Preferred

      func some-method() {
          // method definition goes here
      }

      Variable names

      Preferred

      var someVariable = someValue

      Not Preferred

      var Some_Var1able = someValue

      Single-line comment should start with whitespace
      Open

      //===----------------------------------------------------------------------===//
      Severity: Minor
      Found in WireGuardStatusbar/INIParser.swift by tailor

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

      Enum case names should be lowerCamelCase
      Open

          case InvalidSyntax, InvalidFile
      Severity: Minor
      Found in WireGuardStatusbar/INIParser.swift by tailor

      lower-camel-case

      method and var names should follow lowerCamelCase naming convention: first letter of the entire word is lowercase, but subsequent first letters are uppercase.

      Method and selector names

      Preferred

      func someMethod() {
          // method definition goes here
      }

      Not Preferred

      func some-method() {
          // method definition goes here
      }

      Variable names

      Preferred

      var someVariable = someValue

      Not Preferred

      var Some_Var1able = someValue

      Enum case names should be lowerCamelCase
      Open

          case Title, Variable, Value, SingleQuotation, DoubleQuotation
      Severity: Minor
      Found in WireGuardStatusbar/INIParser.swift by tailor

      lower-camel-case

      method and var names should follow lowerCamelCase naming convention: first letter of the entire word is lowercase, but subsequent first letters are uppercase.

      Method and selector names

      Preferred

      func someMethod() {
          // method definition goes here
      }

      Not Preferred

      func some-method() {
          // method definition goes here
      }

      Variable names

      Preferred

      var someVariable = someValue

      Not Preferred

      var Some_Var1able = someValue

      Enum case names should be lowerCamelCase
      Open

          case Title, Variable, Value, SingleQuotation, DoubleQuotation
      Severity: Minor
      Found in WireGuardStatusbar/INIParser.swift by tailor

      lower-camel-case

      method and var names should follow lowerCamelCase naming convention: first letter of the entire word is lowercase, but subsequent first letters are uppercase.

      Method and selector names

      Preferred

      func someMethod() {
          // method definition goes here
      }

      Not Preferred

      func some-method() {
          // method definition goes here
      }

      Variable names

      Preferred

      var someVariable = someValue

      Not Preferred

      var Some_Var1able = someValue

      Enum case names should be lowerCamelCase
      Open

          case Title, Variable, Value, SingleQuotation, DoubleQuotation
      Severity: Minor
      Found in WireGuardStatusbar/INIParser.swift by tailor

      lower-camel-case

      method and var names should follow lowerCamelCase naming convention: first letter of the entire word is lowercase, but subsequent first letters are uppercase.

      Method and selector names

      Preferred

      func someMethod() {
          // method definition goes here
      }

      Not Preferred

      func some-method() {
          // method definition goes here
      }

      Variable names

      Preferred

      var someVariable = someValue

      Not Preferred

      var Some_Var1able = someValue

      Enum case names should be lowerCamelCase
      Open

          case Title, Variable, Value, SingleQuotation, DoubleQuotation
      Severity: Minor
      Found in WireGuardStatusbar/INIParser.swift by tailor

      lower-camel-case

      method and var names should follow lowerCamelCase naming convention: first letter of the entire word is lowercase, but subsequent first letters are uppercase.

      Method and selector names

      Preferred

      func someMethod() {
          // method definition goes here
      }

      Not Preferred

      func some-method() {
          // method definition goes here
      }

      Variable names

      Preferred

      var someVariable = someValue

      Not Preferred

      var Some_Var1able = someValue

      Enum case names should be lowerCamelCase
      Open

          case Section(String)
      Severity: Minor
      Found in WireGuardStatusbar/INIParser.swift by tailor

      lower-camel-case

      method and var names should follow lowerCamelCase naming convention: first letter of the entire word is lowercase, but subsequent first letters are uppercase.

      Method and selector names

      Preferred

      func someMethod() {
          // method definition goes here
      }

      Not Preferred

      func some-method() {
          // method definition goes here
      }

      Variable names

      Preferred

      var someVariable = someValue

      Not Preferred

      var Some_Var1able = someValue

      Enum case names should be lowerCamelCase
      Open

          case InvalidSyntax, InvalidFile
      Severity: Minor
      Found in WireGuardStatusbar/INIParser.swift by tailor

      lower-camel-case

      method and var names should follow lowerCamelCase naming convention: first letter of the entire word is lowercase, but subsequent first letters are uppercase.

      Method and selector names

      Preferred

      func someMethod() {
          // method definition goes here
      }

      Not Preferred

      func some-method() {
          // method definition goes here
      }

      Variable names

      Preferred

      var someVariable = someValue

      Not Preferred

      var Some_Var1able = someValue

      Single-line comment should start with whitespace
      Open

      //===----------------------------------------------------------------------===//
      Severity: Minor
      Found in WireGuardStatusbar/INIParser.swift by tailor

      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 array.isEmpty { return nil }
      Severity: Minor
      Found in WireGuardStatusbar/INIParser.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
      {
      }

      Parentheses should not be preceded by whitespace
      Open

        public func top () -> T? {
      Severity: Minor
      Found in WireGuardStatusbar/INIParser.swift by tailor

      Parentheses should not be preceded by whitespace
      Open

        public func pop () -> T? {
      Severity: Minor
      Found in WireGuardStatusbar/INIParser.swift by tailor

      There are no issues that match your filters.

      Category
      Status