Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add human readable reporter that’s also funny because emoji. #916

Closed
wants to merge 1 commit into from

Conversation

justMaku
Copy link
Contributor

@justMaku justMaku commented Dec 1, 2016

This pull request adds a new reporter type that's much easier to read for human eye. I believe it could be useful for people that use swiftlint for example in a pre-commit hook or on CI.

Example:

/Users/maku/Projects/Temp/Otter.swift
⛔️ Line 159: Function should have complexity 10 or less: currently complexity equals 21
⛔️ Line 185: Function should have complexity 10 or less: currently complexity equals 96
⚠️ Line 12: Lines should not have trailing whitespace.
⚠️ Line 18: Lines should not have trailing whitespace.
⚠️ Line 115: Lines should not have trailing whitespace.

/Users/maku/Projects/Temp/Other.swift
⚠️ Line 23: Lines should not have trailing whitespace.
⚠️ Line 69: Lines should not have trailing whitespace.
⚠️ Line 92: Lines should not have trailing whitespace.

Copy link
Collaborator

@jpsim jpsim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test to ReporterTests.swift.

@@ -11,6 +11,8 @@
[Marcelo Fabri](https://github.com/marcelofabri)
[#910](https://github.com/realm/SwiftLint/issues/910)
[#911](https://github.com/realm/SwiftLint/issues/911)
* Add `EmojiReporter`: a human readble reporter.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we generally use a single empty line between changelog entries

}

public extension SequenceType {
func categorise<U: Hashable>(@noescape by transform: Generator.Element -> U) -> [U:[Generator.Element]] {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we use American English spellings throughout the project: categorize


public extension SequenceType {
func categorise<U: Hashable>(@noescape by transform: Generator.Element -> U) -> [U:[Generator.Element]] {
var dictionary: [U:[Generator.Element]] = [:]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're in the process of adding a new rule requiring a space after the colon in dictionaries: var dictionary = [U: [Generator.Element]]()


public static func generateReport(violations: [StyleViolation]) -> String {
return violations.categorise {
(violation) in
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

closure parameters on the same line as opening brace please: { violation in

(violation) in
violation.location.file ?? "Other"
}.map {
(filename, violations) in
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

closure parameters on the same line as opening brace please: { filename, violations in

@justMaku justMaku force-pushed the feature/emoji_reporter branch 2 times, most recently from 6ac4ae2 to b7ef2d0 Compare December 1, 2016 21:07
@justMaku
Copy link
Contributor Author

justMaku commented Dec 1, 2016

Thanks for the feedback @jpsim!

I've updated the PR with the changes you've requested and also added a mention about the emoji reporter to the both README files.

@@ -26,6 +26,9 @@
[#910](https://github.com/realm/SwiftLint/issues/910)
[#911](https://github.com/realm/SwiftLint/issues/911)

* Add `EmojiReporter`: a human readble reporter.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, okay 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity: what's the reason behind this rule?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we follow the same changelog format as CocoaPods, I don't know where the motivation for this came from.

@@ -24,3 +24,27 @@ extension Array where Element: NSTextCheckingResult {
return map { $0.range }
}
}

extension Array where Element: Equatable {
var unique: [Element] {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

internal var?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it internal by default?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but we prefer explicit ACLs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I add them everywhere in the file then?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nah, it's fine, this file in particular doesn't seem to follow that convention.

}
}

public extension SequenceType {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

internal extension? This doesn't seem to be relevant in SwiftLint's public API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I copy-pasted it from my other project, doesn't make any sense for this to be public.


public extension SequenceType {
// swiftlint:disable line_length
func categorize<U: Hashable>(@noescape by transform: Generator.Element -> U) -> [U: [Generator.Element]] {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe group instead of categorize?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm… I was wondering about the same thing, but you're right, group sound much nicer.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, SourceKitten already has implementations for these, in case you want to compare:

https://github.com/jpsim/SourceKitten/blob/0.15.2/Source/SourceKittenFramework/ClangTranslationUnit.swift#L16-L33

Copy link
Collaborator

@jpsim jpsim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one more tiny thing, then I think this can land.

}

extension SequenceType {
// swiftlint:disable line_length
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you just want to disable for the next line (as opposed to the entire rest of the file, as is happening currently), change this to // swiftlint:disable:next line_length

@justMaku justMaku force-pushed the feature/emoji_reporter branch 2 times, most recently from 4fbafc1 to 53a1115 Compare December 2, 2016 11:14
@justMaku
Copy link
Contributor Author

justMaku commented Dec 2, 2016

@jpsim okay, fixed that tiny thing and also rebased, thanks for all the help!

@justMaku
Copy link
Contributor Author

justMaku commented Dec 6, 2016

Hey @jpsim, any chance you could take another look on this? :)

@marcelofabri
Copy link
Collaborator

@justMaku Are you sure you've rebased this properly? This is failing on CI because there's no SequenceType in Swift 3.0 (it was renamed).

@justMaku
Copy link
Contributor Author

justMaku commented Dec 7, 2016

Uhm, this is embarrassing 😅. Somehow I was working on a stale master branch still supporting Swift 2.0

Fixed now.

@codecov-io
Copy link

Current coverage is 83.17% (diff: 75.75%)

Merging #916 into master will decrease coverage by 0.05%

@@             master       #916   diff @@
==========================================
  Files           114        115     +1   
  Lines          5136       5201    +65   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits           4275       4326    +51   
- Misses          861        875    +14   
  Partials          0          0          

Powered by Codecov. Last update 291ecd6...a5db9f7

@jpsim jpsim mentioned this pull request Dec 8, 2016
@jpsim
Copy link
Collaborator

jpsim commented Dec 8, 2016

Thanks for the PR @justMaku! I addressed the merge conflict and refactored things a bit, so I'll now be merging this as part of #945.

@jpsim jpsim closed this Dec 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants