Code Monkey home page Code Monkey logo

pre-commit-hooks's Introduction

pre-commit-hooks

This repository contains pre-commit hooks by Extenda Retail.

See also: http://pre-commit.com for general usage instructions.

To install the pre-commit module, Python 3 is required to be installed (tested OK with version 3.9.5). Make sure Python directory is placed in PATH. Python's Scripts directory also should be in PATH.

Run command to install pre-commit:

$ pip install pre-commit

Navigate to the project you want to apply pre-commit hooks and run:

$ pre-commit install

Usage with pre-commit

Add this to your .pre-commit-config.yaml in project's root.

default_stages: [commit]
-  repo: git://github.com/extenda/pre-commit-hooks
   rev: v0.9.0 # Use the ref you want to point at
   hooks:
   - id: google-java-formatter
   - id: commitlint
     stages: [commit-msg]

Available hooks

  • eclipse-formatter (deprecated) - Runs Eclipse Java formatter with default formatting rules on all staged java source files. The following arguments are available:
    • --source - set the Java compiler source version (default 1.8)
    • --target - set the Java compiler target version (default 1.8)
  • google-java-formatter - Runs Google's Java formatter on all staged java source files. Please note: Java 11 or newer is required in v0.5+ Use v0.4 if you need Java 8 support.
  • pre-commitlint - Runs commitlint to validate commit messages.
  • vale (deprecated) - Runs Extenda docker-vale wrapping Vale lint and Extenda's own lint style to validate natural language in files.

Google Java format in your IDE

There's a Google Java Format plugin for both Eclipse and IntelliJ.

The current version used is 1.17.0.0.

Eclipse

Download the formatter plugin and drop it into Eclipse's dropins folder.

The plugin adds a google-java-format formatter implementation that can be configured in Window > Preferences > Java > Code Style > Formatter > Formatter Implementation for the whole workspace.

If you have multiple projects in one workspace, it is possible to apply the formatter only to selected projects.

  1. Navigate to Window > Preferences > Java > Code Style > Formatter > Formatter Implementation
  2. Click on Configure Project Specific Settings
  3. Select the project you want to apply the formatter
  4. In a newly appear window check the checkbox on Enable project specific settings
  5. Select google-java-format in a drop-down menu Formatter implementation
  6. Save

You must also change Window > Preferences > Java > Code style > Organize Imports and remove all the pre-defined groups. This can be done per the whole workspace or per selected project. Google Java Format expects imports to be sorted in alphabetical order and not grouped like the Eclipse default settings.

IntelliJ

A Google Java Format IntelliJ plugin is available from the plugin repository. The plugin will not be enabled by default. To enable it in the current project, go to File > Settings... > google-java-format Settings and check Enable. To enable it by default in new projects, use File > Other Settings > Default Settings....

When enabled, it will replace the normal Reformat Code action, which can be triggered from the Code menu or with the Ctrl-Alt-L (by default) keyboard shortcut.

License

This project is licensed under the MIT license.

pre-commit-hooks's People

Contributors

sasjo avatar msilfver avatar l0kal avatar thced avatar plagov avatar

Stargazers

Denis Cuciuc avatar

Watchers

 avatar James Cloos avatar Jöran Marquardt avatar Shayne Clausson avatar Susanna Stenson avatar  avatar

pre-commit-hooks's Issues

pre-commit hook always shows failed

.pre-commit-config.yaml

default_language_version:
  python: python3.9

repos:
-  repo: https://github.com/extenda/pre-commit-hooks.git
   rev: v0.4
   hooks:
     - id: google-java-formatter

Running the pre-commit manually it always shows up "failed" even though the file is successfully formatted:

Command: pre-commit run --files your/path/to/any/java/file.java

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.