Skip to content

Commit

Permalink
Split Rule into Rule and ParameterizedRule protocols (fixes #21)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsim committed May 20, 2015
1 parent 10285bd commit e2df054
Show file tree
Hide file tree
Showing 15 changed files with 13 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* The `Rule` and `ASTRule` protocol members are now non-static.
[aarondaub](https://github.com/aarondaub)

* Split `Rule` into `Rule` and `ParameterizedRule` protocols.
[aarondaub](https://github.com/aarondaub)
[#21](https://github.com/realm/SwiftLint/issues/21)

##### Enhancements

* The following rules now conform to `ASTRule`:
Expand Down
9 changes: 5 additions & 4 deletions Source/SwiftLintFramework/Rule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
import SourceKittenFramework

protocol Rule {
typealias ParameterType

var identifier: String { get }
var parameters: [RuleParameter<ParameterType>] { get }

func validateFile(file: File) -> [StyleViolation]
}

protocol ParameterizedRule: Rule {
typealias ParameterType
var parameters: [RuleParameter<ParameterType>] { get }
}
1 change: 0 additions & 1 deletion Source/SwiftLintFramework/Rules/ColonRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import SourceKittenFramework

struct ColonRule: Rule {
let identifier = "colon"
let parameters = [RuleParameter<Void>]()

func validateFile(file: File) -> [StyleViolation] {
let pattern1 = file.matchPattern("\\w+\\s+:\\s*\\S+",
Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintFramework/Rules/FileLengthRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import SourceKittenFramework

struct FileLengthRule: Rule {
struct FileLengthRule: ParameterizedRule {
let identifier = "file_length"
let parameters = [
RuleParameter(severity: .VeryLow, value: 400),
Expand Down
1 change: 0 additions & 1 deletion Source/SwiftLintFramework/Rules/ForceCastRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import SourceKittenFramework

struct ForceCastRule: Rule {
let identifier = "force_cast"
let parameters = [RuleParameter<Void>]()

func validateFile(file: File) -> [StyleViolation] {
return file.matchPattern("as!", withSyntaxKinds: [.Keyword]).map { range in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import SourceKittenFramework
import SwiftXPC

struct FunctionBodyLengthRule: ASTRule {
struct FunctionBodyLengthRule: ASTRule, ParameterizedRule {
let identifier = "function_body_length"
let parameters = [
RuleParameter(severity: .VeryLow, value: 40),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import SourceKittenFramework

struct LeadingWhitespaceRule: Rule {
let identifier = "leading_whitespace"
let parameters = [RuleParameter<Void>]()

func validateFile(file: File) -> [StyleViolation] {
let countOfLeadingWhitespace = file.contents.countOfLeadingCharactersInSet(
Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintFramework/Rules/LineLengthRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import SourceKittenFramework

struct LineLengthRule: Rule {
struct LineLengthRule: ParameterizedRule {
let identifier = "line_length"
let parameters = [
RuleParameter(severity: .VeryLow, value: 100),
Expand Down
1 change: 0 additions & 1 deletion Source/SwiftLintFramework/Rules/NestingRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import SwiftXPC

struct NestingRule: ASTRule {
let identifier = "nesting"
let parameters = [RuleParameter<Void>]()

func validateFile(file: File) -> [StyleViolation] {
return self.validateFile(file, dictionary: Structure(file: file).dictionary)
Expand Down
1 change: 0 additions & 1 deletion Source/SwiftLintFramework/Rules/TodoRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import SourceKittenFramework

struct TodoRule: Rule {
let identifier = "todo"
let parameters = [RuleParameter<Void>]()

func validateFile(file: File) -> [StyleViolation] {
return file.matchPattern("// (TODO|FIXME):", withSyntaxKinds: [.Comment]).map { range in
Expand Down
1 change: 0 additions & 1 deletion Source/SwiftLintFramework/Rules/TrailingNewlineRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import SourceKittenFramework

struct TrailingNewlineRule: Rule {
let identifier = "trailing_newline"
let parameters = [RuleParameter<Void>]()

func validateFile(file: File) -> [StyleViolation] {
let countOfTrailingNewlines = file.contents.countOfTailingCharactersInSet(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import SourceKittenFramework

struct TrailingWhitespaceRule: Rule {
let identifier = "trailing_whitespace"
let parameters = [RuleParameter<Void>]()

func validateFile(file: File) -> [StyleViolation] {
return file.contents.lines().map { line in
Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintFramework/Rules/TypeBodyLengthRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import SourceKittenFramework
import SwiftXPC

struct TypeBodyLengthRule: ASTRule {
struct TypeBodyLengthRule: ASTRule, ParameterizedRule {
let identifier = "type_body_length"
let parameters = [
RuleParameter(severity: .VeryLow, value: 200),
Expand Down
1 change: 0 additions & 1 deletion Source/SwiftLintFramework/Rules/TypeNameRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import SwiftXPC

struct TypeNameRule: ASTRule {
let identifier = "type_name"
let parameters = [RuleParameter<Void>]()

func validateFile(file: File) -> [StyleViolation] {
return self.validateFile(file, dictionary: Structure(file: file).dictionary)
Expand Down
1 change: 0 additions & 1 deletion Source/SwiftLintFramework/Rules/VariableNameRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import SwiftXPC

struct VariableNameRule: ASTRule {
let identifier = "variable_name"
let parameters = [RuleParameter<Void>]()

func validateFile(file: File) -> [StyleViolation] {
return self.validateFile(file, dictionary: Structure(file: file).dictionary)
Expand Down

0 comments on commit e2df054

Please sign in to comment.