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

Add pre-commit hook to enable LuaFormatter for pre-commit. #236

Merged
merged 1 commit into from Jan 21, 2022

Conversation

mblayman
Copy link
Contributor

Hello! I've been working with the maintainer of pre-commit to add official Lua support for the pre-commit tool. With pre-commit, a developer or team can choose to run hooks that will execute before a change is committed to git.

Support for Lua in pre-commit was literally added an hour ago as of this PR submission in pre-commit/pre-commit#2158, so this change is hot off the presses.

I believe that LuaFormatter would be a fantastic tool to work with pre-commit since running a code formatter is a very common thing to do before committing.

This PR adds a hooks definition file that will allow any project to use lua-format with pre-commit. I ran a local test on one of my projects to confirm the behavior. I've included the output with no changes (i.e. already formatted code) and a test where the formatter updates the output.

Thanks for the consideration.

No formatting changes:

atlas git:(main) ✗ pre-commit try-repo ../LuaFormatter luaformatter
===============================================================================
Using config:
===============================================================================
repos:
-   repo: ../LuaFormatter
    rev: ad94bea01ca027ca46541af727e15d002aa5ce74
    hooks:
    -   id: luaformatter
===============================================================================
[INFO] Initializing environment for ../LuaFormatter.
[INFO] Installing environment for ../LuaFormatter.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
LuaFormatter.............................................................Passed

Auto-formatted:

atlas git:(main) ✗ pre-commit try-repo ../LuaFormatter luaformatter
===============================================================================
Using config:
===============================================================================
repos:
-   repo: ../LuaFormatter
    rev: ad94bea01ca027ca46541af727e15d002aa5ce74
    hooks:
    -   id: luaformatter
===============================================================================
[INFO] Initializing environment for ../LuaFormatter.
[INFO] Installing environment for ../LuaFormatter.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
LuaFormatter.............................................................Failed
- hook id: luaformatter
- files were modified by this hook

The auto-formatted change acts as a failure so that a dev can review the diff of what the lua-format command did before they commit the changes.

The output during the first run is much noisier than subsequent runs. Typically, after the environment is configured by the first run, users will only see a line like:

LuaFormatter.............................................................Passed

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.

None yet

2 participants