-
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Extend HooksRule on extension * Add ComponentAsStructRule * Fix typo * Apply swiftformat * Fix violation description * Fix rule name
- Loading branch information
Showing
7 changed files
with
90 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// ComponentIsStructRule.swift | ||
// TokamakLint | ||
// | ||
// Created by Matvii Hodovaniuk on 5/30/19. | ||
// | ||
|
||
import SwiftSyntax | ||
|
||
struct ComponentIsStructRule: Rule { | ||
static let description = RuleDescription( | ||
type: ComponentIsStructRule.self, | ||
name: "Component as struct", | ||
description: "Components can only be declared as structs" | ||
) | ||
|
||
public static func validate(visitor: TokenVisitor) -> [StyleViolation] { | ||
var violations: [StyleViolation] = [] | ||
|
||
// search usage of componentProtocols | ||
componentProtocols.forEach { prot in | ||
let components = visitor.root.children(with: prot) | ||
components.forEach { component in | ||
|
||
// check that components is struct | ||
guard let componentCodeBlockItem = component.firstParent(of: .codeBlockItem) else { return } | ||
guard componentCodeBlockItem.children.first?.text == SyntaxKind.structDecl.rawValue else { | ||
violations.append(StyleViolation( | ||
ruleDescription: ComponentIsStructRule.description, | ||
location: Location( | ||
file: visitor.path, | ||
line: componentCodeBlockItem.range.startRow, | ||
character: componentCodeBlockItem.range.startColumn | ||
) | ||
)) | ||
return | ||
} | ||
} | ||
} | ||
|
||
return violations | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class BeatlesComponents: CompositeComponent { | ||
let willThereBeAnAnswer = true | ||
let itBe = "Whisper words of wisdom" | ||
} | ||
|
||
class LedZeppelinLeaf: PureLeafComponent { | ||
let doIhaveToGo = false | ||
enum WhatMakeMe: String { | ||
case mad = "the letter you wrote me" | ||
case sad = "the news that letters told me" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
struct List: PureLeafComponent { | ||
struct Props: Equatable { | ||
let model: [AppRoute] | ||
let onSelect: Handler<CellPath> | ||
} | ||
|
||
static func render(props: Props) -> AnyNode { | ||
return ListView<Cells>.node(.init( | ||
Style([ | ||
Edges.equal(to: .parent), | ||
]), | ||
model: [props.model], | ||
onSelect: props.onSelect | ||
)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters