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

TypeBodyLengthRule should not count comment and whitespace lines #377

Merged
merged 6 commits into from
Jan 22, 2016
Merged

TypeBodyLengthRule should not count comment and whitespace lines #377

merged 6 commits into from
Jan 22, 2016

Conversation

marcelofabri
Copy link
Collaborator

Fixes #369.

@norio-nomura
Copy link
Collaborator

👍 other than change log entry

@marcelofabri
Copy link
Collaborator Author

Fixed

@@ -181,4 +181,31 @@ extension File {
}
return violatingRanges
}

internal func numberOfCommentOnlyLines(startLine: Int, endLine: Int) -> Int {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I thought these functions also excluded whitespace only lines? It doesn't seem like they do. I'm not sure what I'm missing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

They do, but probably their names could be changed to reflect that.

syntaxKindsByLine() adds the whitespace only lines with an empty SyntaxKind array. Then numberOfCommentOnlyLines keeps these lines because of

kinds.filter { !commentKinds.contains($0) }.isEmpty

as kinds will be empty, .filter won't have any effect, keeping the line on the resulting array of the outer .filter.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right, that line could use a short comment explaining that, and these functions should be renamed accordingly.

@marcelofabri
Copy link
Collaborator Author

Renamed the functions in 1ad7e76

@jpsim
Copy link
Collaborator

jpsim commented Jan 18, 2016

👍

@marcelofabri
Copy link
Collaborator Author

I've rebased this with master. Is there anything else that needs to be done to get this merged?

@norio-nomura
Copy link
Collaborator

I think it would be better if it follows the 04267a4's example.

@norio-nomura
Copy link
Collaborator

You can check compilation time by make display_compilation_time as following:

% make display_compilation_time
…
5089.2ms    …/ASTRuleTests.swift:139:10   @objc func testTypeBodyLengths()

@marcelofabri
Copy link
Collaborator Author

OK, I'l try to refactor that later today

@@ -6,6 +6,10 @@

##### Enhancements

* TypeBodyLengthRule now does not count comment lines.
Copy link
Collaborator

Choose a reason for hiding this comment

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

"comment or whitespace lines"? Same with the one for FunctionBodyLengthRule below.

@marcelofabri
Copy link
Collaborator Author

@norio-nomura
Copy link
Collaborator

👍

@jpsim
Copy link
Collaborator

jpsim commented Jan 22, 2016

👍 nicely done!

jpsim added a commit that referenced this pull request Jan 22, 2016
TypeBodyLengthRule should not count comment and whitespace lines
@jpsim jpsim merged commit e12b924 into realm:master Jan 22, 2016
@norio-nomura
Copy link
Collaborator

🎉

@jpsim
Copy link
Collaborator

jpsim commented Jan 23, 2016

Hmm, I just noticed that the tests now take much longer to run than before, and it's because testTypeBodyLengths alone takes ~30 seconds 😬. See https://travis-ci.org/realm/SwiftLint/builds/104029577#L628-L706

@marcelofabri could you please look a bit more into this to see if the tests are doing tons of unnecessary work, or if it's the rule that's quite slow?

@jpsim jpsim mentioned this pull request Jan 23, 2016
3 tasks
@norio-nomura
Copy link
Collaborator

@jpsim I did notice about the test issue and investigated.
That caused by the test matches to worst case of using SourceKitten.NSString.CacheContainer.
On the investigating process, I found some optimization points that can be reduce the test duration.
Maybe I can file the PR to SwiftLint for that today.

@norio-nomura
Copy link
Collaborator

Sorry, it seems #399 did not reduce the duration of test as https://travis-ci.org/realm/SwiftLint/builds/104243015#L583. 😞

@marcelofabri
Copy link
Collaborator Author

I've investigated a little and found that it seems that most of time is spent in NSString. lineAndCharacterForByteOffset and File.syntaxMap.

I'm afraid that's as far as I got. If you guys have any ideas on how to make that faster, I'd be happy to implement.

@norio-nomura
Copy link
Collaborator

Current testTypeBodyLengths is validating all rules.
We can reduce time by validating only TypeBodyLengthRule.

@marcelofabri
Copy link
Collaborator Author

That apparently worked:

Test Case '-[SwiftLintFrameworkTests.ASTRuleTests testTypeBodyLengths]' passed (0.886 seconds).

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.

3 participants