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

SwiftLint integration #249

Merged
merged 6 commits into from
Nov 11, 2018
Merged

SwiftLint integration #249

merged 6 commits into from
Nov 11, 2018

Conversation

djbe
Copy link
Contributor

@djbe djbe commented Sep 24, 2018

Note: I recommend you view these changes either by checking the "Hide whitespace changes" in GitHub, or in a local git client and hiding whitespace changes.

This adds the swiftlint configuration files to the project, and the necessary steps to CI.

  • The changes in Sources/ are pretty minimal, most done by swiftlint autocorrect, and the rest are tiny renames/moving code around.
  • By contrast, the changes in Tests/ are quite extensive. Nothing really functional, more in the sense of reorganisation. The problem is that the old tests were all one (insanely) massive function per file, I've had to split these up into smaller functions. A remaining issue is that we may want to further split up the tests into smaller files.

The advantage of the last item, is much nicer Xcode integration for some tests, as some tests are a single test function now, showing up in the "Test Navigator". If the rest of the team agrees with this approach, I can apply it to the rest of the test cases. It's also a partial application of https://github.com/orgs/stencilproject/teams/coreteam/discussions/5.

Package.swift Outdated
],
dependencies: [
.package(url: "https://github.com/kylef/PathKit.git", from: "0.9.0"),
.package(url: "https://github.com/kylef/Spectre.git", from: "0.9.0"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Personally I actually like these trailing comma's. Leads to:

  • cleaner git diffs
  • less conflicts
  • easier copy and pasting of lines
  • easier reordering of lines

Thoughts?

Copy link
Contributor Author

@djbe djbe Sep 24, 2018

Choose a reason for hiding this comment

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

IMO we should avoid a bunch of copy/paste? More often than not, it leads to mistakes.

let expectedError = expectedSyntaxError(token: token, template: template, description: reason)

let error = try expect(
self.environment.render(template: self.template, context: ["names": ["Bob", "Alice"], "name": "Bob"]),
Copy link
Collaborator

Choose a reason for hiding this comment

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

extract context in a local variable and also move template and context parameters on separate lines?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd prefer to keep this function in a single line though, same as expectation later.

Copy link
Contributor Author

@djbe djbe Sep 30, 2018

Choose a reason for hiding this comment

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

extract context in a local variable

Could you clarify this bit?

Copy link
Collaborator

Choose a reason for hiding this comment

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

let context = ["names": ["Bob", "Alice"], "name": "Bob"])
self.environment.render(template: template, context: context, file: file, line: line, function: function)

Copy link
Contributor Author

@djbe djbe Sep 30, 2018

Choose a reason for hiding this comment

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

Ah ok.

in a single line though

Problem is, and this in quite a few places, that we have absolutely gigantically long function calls/init/...

Thanks to swiftlint, we can enforce a hard limit on this, to improve readability. We can try keeping some things on one line, but here and there, we will have to split things up into multiple lines.

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes, I agree, though having a function call that takes more than 5 lines probably is a sign that we should refactor it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, but there's not much of a choice here, we're passing along parameters to another function 🤷‍♂️

}

func testSyntaxError() throws {
template = Template(templateString: """
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see profit from using multi-line strings in this and next function 🤷‍♂️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's to avoid having to escape " (quotes).

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think escaping is fine... Don't we allow using single quotes though?

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, we could use '.

But you'll see in some other tests I've placed the template in multiline strings just to keep the formatting consistent between multiple tests. It's a nice visual queue of "hey, that's a template", or "hey, that's an expected result".

rules

rules
@djbe
Copy link
Contributor Author

djbe commented Nov 11, 2018

Most of this PR is good to go, some of the feedback can't really be fixed without a more extensive refactor of the unit tests.

I'm going to merge this for now, and further feedback/refactors can be done in other PRs. This one is an absolute hell to rebase after each PR 😱

@djbe djbe merged commit 5220c37 into master Nov 11, 2018
@djbe djbe deleted the feature/swiftlint branch November 11, 2018 16:43
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