|
1 | 1 | opt_in_rules:
|
| 2 | +- attributes |
| 3 | +- closure_end_indentation |
| 4 | +- closure_spacing |
2 | 5 | - empty_count
|
3 |
| -# - missing_docs |
4 |
| - |
5 |
| -disabled_rules: |
6 |
| -- vertical_whitespace # Turn off until configurable to 2 newlines |
7 |
| -- cyclomatic_complexity |
| 6 | +- explicit_init |
| 7 | +- fatal_error_message |
| 8 | +- file_header |
| 9 | +- first_where |
| 10 | +- implicit_return |
| 11 | +- implicitly_unwrapped_optional |
| 12 | +- nimble_operator |
| 13 | +- no_extension_access_modifier |
| 14 | +- number_separator |
| 15 | +- operator_usage_whitespace |
| 16 | +- overridden_super_call |
| 17 | +- private_outlet |
| 18 | +- prohibited_super_call |
| 19 | +- redundant_nil_coalescing |
| 20 | +- switch_case_on_newline |
8 | 21 |
|
9 | 22 | included:
|
10 | 23 | - Sources
|
11 | 24 | - Tests
|
12 | 25 |
|
13 | 26 | excluded:
|
14 | 27 | - Carthage
|
15 |
| -- Sources/Constants |
| 28 | +- Sources/Code/TextFile.swift |
16 | 29 |
|
17 | 30 | line_length: 180
|
| 31 | + |
| 32 | +file_header: |
| 33 | + required_pattern: | |
| 34 | + \/\/ |
| 35 | + \/\/ .*?\.swift |
| 36 | + \/\/ [\S ]+ |
| 37 | + \/\/ |
| 38 | + \/\/ Created by [\S ]+ on \d{1,2}\.\d{1,2}\.\d{2}\. |
| 39 | + \/\/ Copyright © \d{4} [\S ]+\. All rights reserved\. |
| 40 | + \/\/ |
| 41 | +
|
| 42 | +custom_rules: |
| 43 | + closing_brace_whitespace: |
| 44 | + included: ".*.swift" |
| 45 | + regex: '(?:\n| {2,})\}\)? *\n *[^ \n\})\]]' |
| 46 | + name: "Closing Brace Whitespace" |
| 47 | + message: "Empty line required after closing curly braces if code with same indentation follows." |
| 48 | + severity: warning |
| 49 | + closure_params_parantheses: |
| 50 | + included: ".*.swift" |
| 51 | + regex: '\{\s*\([^):]+\)\s*in' |
| 52 | + name: "Unnecessary Closure Params Parantheses" |
| 53 | + message: "Don't use parantheses around non-typed parameters in a closure." |
| 54 | + severity: warning |
| 55 | + ending_closure: |
| 56 | + included: ".*.swift" |
| 57 | + regex: '(?:\(|, | *\S+ *: *)\{[^\}]+\}\) *\n' |
| 58 | + name: "Ending Closure" |
| 59 | + message: "Don't use '(' and ')' on the last closure of a method – remove them instead." |
| 60 | + severity: warning |
| 61 | + if_as_guard: |
| 62 | + included: ".*.swift" |
| 63 | + regex: '\n *if [^\{]+\{\s*return[^\n]*\n *\}(?! *else)' |
| 64 | + name: "If as Guard" |
| 65 | + message: "Don't use an if statement to just return – use guard for such cases instead." |
| 66 | + severity: warning |
| 67 | + late_force_unwrapping: |
| 68 | + included: ".*.swift" |
| 69 | + regex: '\(\S+\?\.\S+\)!' |
| 70 | + name: "Late Force Unwrapping" |
| 71 | + message: "Don't use ? first to force unwrap later – directly unwrap within the parantheses." |
| 72 | + severity: warning |
| 73 | + long_switch_case: |
| 74 | + included: ".*.swift" |
| 75 | + regex: 'case (?:let )?\.[^\n]+\n((?!\s*switch)[^\n\}]+\n){5,}?\s*(case|\})' |
| 76 | + name: "Long Switch Cases" |
| 77 | + message: "Use a maximum of 3 lines within each case." |
| 78 | + severity: warning |
| 79 | + missing_docs: |
| 80 | + included: ".*.swift" |
| 81 | + regex: '\n *(?!\/\/\/)(\/\/)?[^\n\/]*\n *(?:public|open)' |
| 82 | + name: "Missing Docs" |
| 83 | + message: "Types, properties and methods with public or open access level should be documented." |
| 84 | + severity: warning |
| 85 | + multiple_closure_params: |
| 86 | + included: ".*.swift" |
| 87 | + regex: '\} *\) *\{' |
| 88 | + name: "Multiple Closure Params" |
| 89 | + message: "Don't use multiple in-line closures – save one or more of them to variables instead." |
| 90 | + severity: warning |
| 91 | + return_whitespace: |
| 92 | + included: ".*.swift" |
| 93 | + regex: '( {4}\S[^\n]+\n){2,} {4}return|( {8}\S[^\n]+\n){2,} {8}return|( {12}\S[^\n]+\n){2,} {12}return|( {16}\S[^\n]+\n){2,} {16}return|( {20}\S[^\n]+\n){2,} {20}return|( {24}\S[^\n]+\n){2,} {24}return' |
| 94 | + name: "Return Whitespace" |
| 95 | + message: "Put an empty line before the return line if two or more other lines in closure." |
| 96 | + severity: warning |
| 97 | + single_line_guard: |
| 98 | + included: ".*.swift" |
| 99 | + regex: 'guard[^\{]{2,100}else\s*\{\s*\n\s*return.{2,60}\}' |
| 100 | + name: "Single Line Guard" |
| 101 | + message: "Use a single line guard for simple checks." |
| 102 | + severity: warning |
| 103 | + space_before_comment: |
| 104 | + included: ".*.swift" |
| 105 | + regex: '\n[ ]{0}[^\/ \n][^\n]*\n[ ]{0}\/\/|\n[ ]{4}[^\/ \n][^\n]*\n[ ]{4}\/\/|\n[ ]{8}[^\/ \n][^\n]*\n[ ]{8}\/\/|\n[ ]{16}[^\/ \n][^\n]*\n[ ]{16}\/\/|\n[ ]{20}[^\/ \n][^\n]*\n[ ]{20}\/\/|\n[ ]{24}[^\/ \n][^\n]*\n[ ]{24}\/\/' |
| 106 | + name: "Space Before Comment" |
| 107 | + message: "Always put a space line before a comment line and always comment code beforehand." |
| 108 | + severity: warning |
| 109 | + too_much_indentation: |
| 110 | + included: ".*.swift" |
| 111 | + regex: '\n {0}[^\s\/][^\n]*[^,|&]\n+ {5,}\S|\n {4}[^\s\/][^\n]*[^,|&]\n+ {9,}\S|\n {8}[^\s\/][^\n]*[^,|&]\n+ {13,}\S|\n {12}[^\s\/][^\n]*[^,|&]\n+ {17,}\S|\n {16}[^\s\/][^\n]*[^,|&]\n+ {21,}\S|\n {20}[^\s\/][^\n]*[^,|&]\n+ {25,}\S' |
| 112 | + name: "Too Much Indentation" |
| 113 | + message: "Don't indent code by more than 4 whitespaces." |
| 114 | + severity: warning |
| 115 | + too_much_unindentation: |
| 116 | + included: ".*.swift" |
| 117 | + regex: ' {28}\S(.|[^\n]*[^\)][^\ ][^\}])\n+ {0,23}[^\s\/]| {24}\S(.|[^\n]*[^\)][^\ ][^\}])\n+ {0,19}[^\s\/]| {20}\S(.|[^\n]*[^\)][^\ ][^\}])\n+ {0,15}[^\s\/]| {16}\S(.|[^\n]*[^\)][^\ ][^\}])\n+ {0,11}[^\s\/]| {12}\S(.|[^\n]*[^\)][^\ ][^\}])\n+ {0,7}[^\s\/]| {8}\S(.|[^\n]*[^\)][^\ ][^\}])\n+ {0,3}[^\s\/]' |
| 118 | + name: "Too Much Unindentation" |
| 119 | + message: "Don't unindent code by more than 4 whitespaces." |
| 120 | + severity: warning |
| 121 | + unnecessary_case_break: |
| 122 | + included: ".*.swift" |
| 123 | + regex: '(case |default)(?:[^\n\}]+\n){2,}\s*break|\n *\n *break(?:\n *\n|\n *\})' |
| 124 | + name: "Unnecessary Case Break" |
| 125 | + message: "Don't use break in switch cases – Swift breaks by default." |
| 126 | + severity: warning |
| 127 | + unnecessary_nil_assignment: |
| 128 | + included: ".*.swift" |
| 129 | + regex: 'var \S+\s*:\s*[^\s]+\?\s*=\s*nil' |
| 130 | + name: "Unnecessary Nil Assignment" |
| 131 | + message: "Don't assign nil as a value when defining an optional type – it's nil by default." |
| 132 | + severity: warning |
| 133 | + vertical_whitespace_between_cases: |
| 134 | + included: ".*.swift" |
| 135 | + regex: '[^\n{][ \t]*\n[ \t]*(?:case[^\n]+|default):[ \t]*\n' |
| 136 | + name: "Vertical Whitespace Between Cases" |
| 137 | + message: "Include a vertical whitespace (empty line) between cases in switch statements." |
| 138 | + severity: warning |
| 139 | + vertical_whitespaces_around_mark: |
| 140 | + included: ".*.swift" |
| 141 | + regex: '\/\/\s*MARK:[^\n]*(\n\n)|(\n\n\n)[ \t]*\/\/\s*MARK:|[^\s{]\n[^\n\/]*\/\/\s*MARK:' |
| 142 | + name: "Vertical Whitespaces Around MARK:" |
| 143 | + message: "Include a single vertical whitespace (empty line) before and none after MARK: comments." |
| 144 | + severity: warning |
| 145 | + vertical_whitespace_opening_braces: |
| 146 | + included: ".*.swift" |
| 147 | + regex: '[{(\[][ \t]*\n[ \t]*\n' |
| 148 | + name: "Vertical Whitespace after Opening Braces" |
| 149 | + message: "Don't include vertical whitespace (empty line) after opening braces." |
| 150 | + severity: warning |
| 151 | + vertical_whitespace_closing_braces: |
| 152 | + included: ".*.swift" |
| 153 | + regex: '\n[ \t]*\n[ \t]*[)}\]]' |
| 154 | + name: "Vertical Whitespace before Closing Braces" |
| 155 | + message: "Don't include vertical whitespace (empty line) before closing braces." |
| 156 | + severity: warning |
| 157 | + whitespace_comment_start: |
| 158 | + included: ".*.swift" |
| 159 | + regex: '[^:]\/\/[^\s\/]' |
| 160 | + name: "Whitespace Comment Start" |
| 161 | + message: "A comment should always start with a whitespace." |
| 162 | + severity: warning |
0 commit comments