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

Convention for import statement ordering #491

Closed
fredrik-bakke opened this issue Mar 7, 2023 · 3 comments · Fixed by #495
Closed

Convention for import statement ordering #491

fredrik-bakke opened this issue Mar 7, 2023 · 3 comments · Fixed by #495
Assignees
Labels

Comments

@fredrik-bakke
Copy link
Collaborator

fredrik-bakke commented Mar 7, 2023

Jonathan and I have been working together to try to define a ruleset for how import statements should be ordered, as he is developing a script to automate the sorting of these (#488 #487 #484).

The import order that we are currently proposing is the following.

  1. public import statements
  2. non-public Agda primitive imports
  3. non-public import statements from the same namespace
  4. non-public import statements from other namespaces
  5. other open statements (this seems to be unconventional, but alas there are instances of this in the library)

Within these categories, the statements should be sorted alphabetically.

The reasoning is that this will hopefully correlate well with the relevance of each individual import, while still being somewhat intuitive to the user/contributor.

@fredrik-bakke
Copy link
Collaborator Author

fredrik-bakke commented Mar 7, 2023

Alright, after speaking with Egbert, the new proposal is as follows:

  1. public import statements
  2. non-public import statements
  3. other open statements (although these should not occur)

Within each category, the statements are sorted alphabetically, and each namespace is separated with an empty line.

@EgbertRijke
Copy link
Collaborator

I was just about to write the same:)

These seem very sensible conventions to me.

@jonaprieto jonaprieto self-assigned this Mar 7, 2023
@jonaprieto jonaprieto mentioned this issue Mar 9, 2023
1 task
EgbertRijke pushed a commit that referenced this issue Mar 9, 2023
This PR adds pre-commit hooks to fix/enforce some conventions like
automatically formatting the Agda import block insider `<details>`
block.

- Closes #491
- Add infrastructure for #448


The hooks are written in Python for ease (also for the CI in the future)
and are run using [pre-commit](https://pre-commit.com/).

The idea is once you have
staged all your changes, you can run (which by default also runs `make
check`):

```bash
make pre-commit
```

It will automatically fix any formatting issues.

In principle, we could also add checks for other conventions in the
future, like the ones
described in CONVENTIONS.md

Oh. I also changed CITATION.md as Github encourages to use the .cff
extension.

- [x] Update the CI to run pre-commit
@fredrik-bakke
Copy link
Collaborator Author

As an addendum, import statements are sorted by namespaces first, not just alphabetically as a whole. (#497)

In practice, this means foundation imports come before foundation-core imports, even though the string foundation-core. comes before foundation. alphabetically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants