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

Consider adding a pre-commit hook #85

Closed
abelsiqueira opened this issue Oct 1, 2024 · 3 comments · Fixed by #86
Closed

Consider adding a pre-commit hook #85

abelsiqueira opened this issue Oct 1, 2024 · 3 comments · Fixed by #86

Comments

@abelsiqueira
Copy link
Contributor

We are considering how to best use ExplicitImports in Bestie (JuliaBesties/BestieTemplate.jl#349 and JuliaBesties/BestieTemplate.jl#217).
Our current idea is to have a pre-commit hook, like we have for JuliaFormatter and other non-Julia tools.
These hooks also form our Lint workflow, which ensures that even if someone is not using pre-commit, the hooks still run at each PR.
For that to work, we'll need a definition of the pre-commit-hook for ExplicitImports. Although it's possible to create a completely separate repo for that, it's common to have it as part of the main repo (e.g., https://github.com/domluna/JuliaFormatter.jl/blob/master/.pre-commit-hooks.yaml).

Are you open to adding a .pre-commit-hooks.yml file here (and possibly an auxiliary script file)?


From what I tried so far, it would probably be something like the two files below, although I'm open to suggestions

# .pre-commit-hooks.yaml
- id: explicit-imports
  name: "Explicit Imports"
  entry: "pre_commit_explicit_imports.sh"
  args: [Debugging]
  pass_filenames: false
  always_run: false
  types: [file]
  files: \.jl$
  language: "script"
  description: "Checks explicit imports"
#!/bin/bash
# pre_commit_explicit_imports.sh

module=$1

# Check that $module is not empty
if [ -z "$module" ]; then
  echo "Module was not passed. 'args: [Module]' should be passed"
fi

julia -e "
using Pkg
pkg\"activate\"
using ExplicitImports: ExplicitImports
pkg\"activate .\"
using $module
ExplicitImports.check_no_implicit_imports($module)
"
@abelsiqueira
Copy link
Contributor Author

I've implemented the hook as an example here: JuliaBesties/BestieTemplate.jl#472
The logic and script are in the user's side, but the code would be pretty much the same.

@ericphanson
Copy link
Owner

Sure, I’m open to PRs adding this here

@abelsiqueira
Copy link
Contributor Author

Thanks! I'll submit something soon

abelsiqueira added a commit to abelsiqueira/ExplicitImports.jl that referenced this issue Oct 3, 2024
Create scripts/explicit-imports.jl to allow running checks based on
parsed arguments.
Create a pre-commit hook that runs the script.
Document how to use the pre-commit hook and the script in the README.

Closes ericphanson#85
abelsiqueira added a commit to abelsiqueira/ExplicitImports.jl that referenced this issue Oct 3, 2024
Create scripts/explicit-imports.jl to allow running checks based on
parsed arguments.
Create a pre-commit hook that runs the script.
Document how to use the pre-commit hook and the script in the README.

Closes ericphanson#85
abelsiqueira added a commit to abelsiqueira/ExplicitImports.jl that referenced this issue Oct 4, 2024
Update the CLI at src/main.jl to allow running the checks.
The checks can be defined based on parsed arguments.
Create scripts/explicit-imports.jl to pass ARGS to the CLI when running
pre-commit.
Create a pre-commit hook that runs the script.
Move the documentation of CLI from docs/api.md to the README.
Expands the CLI documentation with information on how to run the
pre-commit hooks.

Closes ericphanson#85
abelsiqueira added a commit to abelsiqueira/ExplicitImports.jl that referenced this issue Oct 4, 2024
Update the CLI at src/main.jl to allow running the checks.
The checks can be defined based on parsed arguments.
Create scripts/explicit-imports.jl to pass ARGS to the CLI when running
pre-commit.
Create a pre-commit hook that runs the script.
Move the documentation of CLI from docs/api.md to the README.
Expands the CLI documentation with information on how to run the
pre-commit hooks.

Closes ericphanson#85
abelsiqueira added a commit to abelsiqueira/ExplicitImports.jl that referenced this issue Oct 4, 2024
Update the CLI at src/main.jl to allow running the checks.
The checks can be defined based on parsed arguments.
Create scripts/explicit-imports.jl to pass ARGS to the CLI when running
pre-commit.
Create a pre-commit hook that runs the script.
Move the documentation of CLI from docs/api.md to the README.
Expands the CLI documentation with information on how to run the
pre-commit hooks.

Closes ericphanson#85
abelsiqueira added a commit to abelsiqueira/ExplicitImports.jl that referenced this issue Oct 4, 2024
Update the CLI at src/main.jl to allow running the checks.
The checks can be defined based on parsed arguments.
Create scripts/explicit-imports.jl to pass ARGS to the CLI when running
pre-commit.
Create a pre-commit hook that runs the script.
Move the documentation of CLI from docs/api.md to the README.
Expands the CLI documentation with information on how to run the
pre-commit hooks.

Closes ericphanson#85
ericphanson added a commit that referenced this issue Oct 6, 2024
…ersions, and add `.pre-commit-config.yaml` (#86)

* Create script and pre-commit hook

Update the CLI at src/main.jl to allow running the checks.
The checks can be defined based on parsed arguments.
Create scripts/explicit-imports.jl to pass ARGS to the CLI when running
pre-commit.
Create a pre-commit hook that runs the script.
Move the documentation of CLI from docs/api.md to the README.
Expands the CLI documentation with information on how to run the
pre-commit hooks.

Closes #85

* fix typo (`individial` -> `individual`)

* rename files `main.jl` -> `cli.jl`

* reorganize docs a little bit

* reduce confusion by tweaking word elsewhere

* don't show stacktrace in CLI

* Revert "rename files `main.jl` -> `cli.jl`"

This reverts commit d1ef007.

* rename `cli` to `main`

* only call `activate_and_load` once

* all caps globals

* exit manually

* bump version

---------

Co-authored-by: Eric Hanson <5846501+ericphanson@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants