ericphanson / ExplicitImports.jl

Developer tooling for Julia namespace management: detecting implicit imports, improper explicit imports, and improper qualified accesses
https://ericphanson.github.io/ExplicitImports.jl/
MIT License
77 stars 5 forks source link

Consider adding a pre-commit hook #85

Open abelsiqueira opened 4 days ago

abelsiqueira commented 4 days ago

We are considering how to best use ExplicitImports in Bestie (abelsiqueira/BestieTemplate.jl#349 and abelsiqueira/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 commented 3 days ago

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

ericphanson commented 3 days ago

Sure, I’m open to PRs adding this here

abelsiqueira commented 2 days ago

Thanks! I'll submit something soon