-
Notifications
You must be signed in to change notification settings - Fork 55
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
Enforce import order #254
Enforce import order #254
Conversation
All Go files should have exactly three import groups: - stdlib - 3rd-party / non-project imports - project imports (from inside canonical/pebble)
gocheck should be imported with `.`, as suggested in the comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Definitely nice to enforce this via tooling rather than (clearly error-prone) human eyeballs. And nice to make daemon_test.go
consistent and get rid of that TODO too.
Just an idea for the future: I like the idea of having a single script (like |
Add linting to the pre-merge checks to enforce Go import groups: - stdlib - 3rd-party / non-Pebble imports - Pebble imports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks Jordan. Merging this as it's just an enforcement of agreed code style.
Apparently there is an implicit rule that Pebble imports should be arranged into three groups:
github.com/canonical/pebble
)This rule was not being enforced anywhere except code review, and there were many Go files not following this convention.
I've fixed up all Go files so that they now follow this convention. I used the
gci
tool to enforce the import order. Unfortunatelygoimports
is not strict enough - it will only make sure that imports from the same group are not together. It will allow a group to be split up, so e.g. the following still passes:The easiest way to use
gci
is viagolangci-lint
(whichgci
is bundled inside). Runto do the linting. If you add the
--fix
flag,gci
will fix all the imports for you.While I'm here, I resolved a stale TODO in
daemon_test.go
by changing the import ofgocheck
to use.
, following the convention observed in (most) other test files.Finally, I've added a
Lint
GitHub workflow to enforce this import order on future PRs.