-
Notifications
You must be signed in to change notification settings - Fork 627
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
Bug fixes and improvements for organizeDeclarations rule #707
Bug fixes and improvements for organizeDeclarations rule #707
Conversation
…function or property names
@calda thanks for the improvements! Something I'm struggling with at the moment is that the Would it be possible to modify it not to do this? It doesn't seem like it's in scope of what the rule is trying to achieve. If this is part of the AirBnB style guide that you are trying to enforce, I think it would make more sense to make it a configuration option for the existing |
Ahh I always forget that any mutation to the |
@nicklockwood It seems like there are also conflicts between the existing enabled-by-default For example, this test below fails because func testDoesntEmitConflictWarningsWithBlankLinesAroundMarkRule() {
let input = """
class Foo {
// MARK: Lifecycle
init(json: JSONObject) throws {
bar = try json.value(for: "bar")
baz = try json.value(for: "baz")
}
// MARK: Internal
let bar: String
let baz: Int?
}
"""
testFormatting(for: input, rules: [
FormatRules.blankLinesAroundMark,
FormatRules.blankLinesAtStartOfScope,
FormatRules.blankLinesAtEndOfScope,
])
} It seems like there are valid cases where we should be able to insert blank lines at the start or end of the scope (like this example with behavior from the existing Thoughts? |
@calda generally I manage these by either modifying the rules not to conflict (e.g. I could change I'm actually not sure what's best in this case. I'll give it some thought. |
If we update the linter to only compare the input and output source code (rather than simply listening for Would there be challenges / performance issues / concerns with an approach like that? |
@calda I'm not sure how you would track which rule caused which change if you were just comparing the source at the start/end? But I'd be open to such a solution if you have a way to implement it. Perhaps a hybrid approach would be possible, where changes are tracked at mutation time, but we retrospectively discard spurious changes by comparing the before/after source for each changed line? That should be possible since the formatted tokens retain the original line number. |
I ran the
organizeDeclarations
rule (#701) on our codebase last week and noticed a few issues. This PR includes several improvements and bug fixes:Improvements
Bug fixes
NavigationBarType.static
) would get misinterpreted as separate declarations and cause compilation failure#if ... #endif
) would not be parsed correctlyimport class Module.Type
) would not be parsed correctly