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 joined_default_parameter opt-in rule #1746

Merged
merged 3 commits into from Aug 7, 2017

Conversation

ornithocoder
Copy link
Contributor

@ornithocoder ornithocoder commented Aug 3, 2017

to discourage explicit usage of the default separator. Implements #1093.

[x] Adds opt-in rule
[x] Adds to tests (+ Linux)
[x] Adds to changelog
[x] Updates Rules.md

@SwiftLintBot
Copy link

SwiftLintBot commented Aug 3, 2017

8 Warnings
⚠️ Make sure that the docs are updated by running the Generate docs scheme.
⚠️ This PR introduced a violation in Nimble: /Sources/Nimble/FailureMessage.swift#L48:32: warning: Joined Default Parameter Violation: Discouraged explicit usage of the default separator. (joined_default_parameter)
⚠️ This PR introduced a violation in Sourcery: /Sourcery/Generating/Template/Swift/SwiftTemplate.swift#L61:53: warning: Joined Default Parameter Violation: Discouraged explicit usage of the default separator. (joined_default_parameter)
⚠️ This PR introduced a violation in Sourcery: /Sourcery/Generating/Template/Swift/SwiftTemplate.swift#L81:58: warning: Joined Default Parameter Violation: Discouraged explicit usage of the default separator. (joined_default_parameter)
⚠️ This PR introduced a violation in Sourcery: /Sourcery/Generating/Template/Swift/SwiftTemplate.swift#L257:29: warning: Joined Default Parameter Violation: Discouraged explicit usage of the default separator. (joined_default_parameter)
⚠️ This PR introduced a violation in Sourcery: /Sourcery/Parsing/FileParser.swift#L821:121: warning: Joined Default Parameter Violation: Discouraged explicit usage of the default separator. (joined_default_parameter)
⚠️ This PR introduced a violation in Sourcery: /SourceryTests/Helpers/Extensions.swift#L12:83: warning: Joined Default Parameter Violation: Discouraged explicit usage of the default separator. (joined_default_parameter)
⚠️ This PR introduced a violation in WordPress: /WordPress/Classes/Extensions/NSAttributedString+StyledHTML.swift#L65:54: warning: Joined Default Parameter Violation: Discouraged explicit usage of the default separator. (joined_default_parameter)
12 Messages
📖 Linting Aerial with this PR took 0.36s vs 0.34s on master (5% slower)
📖 Linting Alamofire with this PR took 2.38s vs 2.33s on master (2% slower)
📖 Linting Firefox with this PR took 9.9s vs 9.86s on master (0% slower)
📖 Linting Kickstarter with this PR took 14.85s vs 14.72s on master (0% slower)
📖 Linting Moya with this PR took 1.01s vs 1.0s on master (1% slower)
📖 Linting Nimble with this PR took 1.37s vs 1.35s on master (1% slower)
📖 Linting Quick with this PR took 0.44s vs 0.44s on master (0% slower)
📖 Linting Realm with this PR took 2.08s vs 2.05s on master (1% slower)
📖 Linting SourceKitten with this PR took 0.78s vs 0.83s on master (6% faster)
📖 Linting Sourcery with this PR took 3.48s vs 3.55s on master (1% faster)
📖 Linting Swift with this PR took 9.95s vs 9.72s on master (2% slower)
📖 Linting WordPress with this PR took 9.42s vs 9.32s on master (1% slower)

Generated by 🚫 Danger

to discourage explicit usage of the default separator. Implements realm#1093.
@codecov-io
Copy link

codecov-io commented Aug 3, 2017

Codecov Report

Merging #1746 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1746      +/-   ##
==========================================
+ Coverage   87.75%   87.78%   +0.02%     
==========================================
  Files         218      219       +1     
  Lines       10704    10730      +26     
==========================================
+ Hits         9393     9419      +26     
  Misses       1311     1311
Impacted Files Coverage Δ
Tests/SwiftLintFrameworkTests/RulesTests.swift 100% <100%> (ø) ⬆️
...e/SwiftLintFramework/Rules/JoinedDefaultRule.swift 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 54d6199...3252673. Read the comment docs.

@ornithocoder
Copy link
Contributor Author

ornithocoder commented Aug 4, 2017

Should this one be opt-in or enabled by default @marcelofabri / @jpsim?

@marcelofabri
Copy link
Collaborator

I think it should be opt-in. By bet is that joined can be a common name.

let bodyOffset = dictionary.bodyOffset,
let bodyLength = dictionary.bodyLength else { return nil }

let body = file.contents.bridge().substringWithByteRange(start: bodyOffset, length: bodyLength)
Copy link
Collaborator

Choose a reason for hiding this comment

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

what do you think about using the substructure instead?

 {
 	"key.namelength": 10,
 	"key.nameoffset": 1,
 	"key.length": 25,
 	"key.substructure": [{
 		"key.namelength": 9,
 		"key.nameoffset": 12,
 		"key.length": 13,
 		"key.name": "separator",
 		"key.bodyoffset": 23,
 		"key.bodylength": 2,
 		"key.kind": "source.lang.swift.expr.argument",
 		"key.offset": 12
 	}],
 	"key.name": "bar.joined",
 	"key.bodyoffset": 12,
 	"key.bodylength": 13,
 	"key.kind": "source.lang.swift.expr.call",
 	"key.offset": 1
 }

It should be more reliable than the current implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Consider it done :-)

let bodyOffset = dictionary.bodyOffset,
let bodyLength = dictionary.bodyLength else { return nil }
let argument = dictionary.substructure.first(where: { $0.name == "separator" }),
let argumentBodyOffset = argument.bodyOffset,
Copy link
Collaborator

Choose a reason for hiding this comment

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

you can also check if argument.name == "separator"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've just checked in another version which check the number of arguments and the argument name.

}

private func defaultSeparatorOffset(dictionary: [String: SourceKitRepresentable], file: File) -> Int? {
let arguments = dictionary.substructure.filter { $0.kind == SwiftExpressionKind.argument.rawValue }
Copy link
Collaborator

Choose a reason for hiding this comment

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

you can use dictionary.enclosedArguments instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done :-)


### Examples

<details>
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like the examples are outdated too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done :-)

@marcelofabri
Copy link
Collaborator

@ornithocoder what do you think about making it autocorrectable?

If you think it's easy, we can do on this PR. Otherwise we can leave it as a future improvement 👍

@ornithocoder
Copy link
Contributor Author

@marcelofabri I'd do in a different PR, if that's OK. Thanks! :-)

@marcelofabri marcelofabri merged commit 02f4212 into realm:master Aug 7, 2017
@marcelofabri
Copy link
Collaborator

Sure, no problem. Thanks! 💯

@ornithocoder ornithocoder deleted the joined_default_parameter branch August 7, 2017 12:52
ornithocoder added a commit to ornithocoder/personal-fork-swiftlint that referenced this pull request Aug 8, 2017
ornithocoder added a commit to ornithocoder/personal-fork-swiftlint that referenced this pull request Aug 8, 2017
ornithocoder added a commit to ornithocoder/personal-fork-swiftlint that referenced this pull request Aug 8, 2017
marcelofabri pushed a commit that referenced this pull request Aug 17, 2017
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.

None yet

4 participants