Coder Social home page Coder Social logo

sonarlint-git-hooks's Introduction

SonarLint Git hooks

Git hook scripts to trigger SonarLint on VCS actions.

Requirements

To run SonarLint analysis, you need the sonarlint command line tool.

http://www.sonarlint.org/commandline/

Alternatively, you can run a convenience script included in this repository:

./get-and-setup-sonarlint.sh

This will do:

  1. Download the latest release of SonarLint CLI and extract inside this clone
  2. Create a symbolic link to sonarlint in your ~/bin
  3. Verify that sonarlint is ready to run

This assumes that your ~/bin folder is on PATH. If that's not the case, you need to add the following line to your ~/.bashrc or ~/.bash_profile or ~/.profile, as appropriate for your environment:

PATH=$HOME/bin:$PATH

Installing

To install the hook scripts, you can use the install.sh script:

cd your/git/project
/path/to/sonarlint-git-hooks/install.sh

The script will create symbolic links to the hook scripts in the hooks/ directory. It will not overwrite existing files. To disable a hook script, you can either rename it or delete it.

If symbolic links don't work well in your system, you can copy the hook scripts manually.

Hooks

See the hook scripts inside the hooks directory.

  • pre-push: run analysis before git push, on files that were added or modified compared to origin/master, after some basic filtering applied:
    • If the file path contains src/, analyze it as source code
    • If the file path contains src/ and also test or Test, analyze it as test code
    • Otherwise skip the file and print a warning
  • pre-commit: run analysis before git commit, on files that were added or modified, after the same filtering applied as in pre-push.

You can easily run the hook scripts "standalone", without actually running a Git command. For example, to analyze files in the current branch that were added or modified compared to origin/master, you can run the pre-push hook script directly:

.git/hooks/pre-push

To temporarily disable a hook, run with SKIPSONARLINT=1 set, for example:

SKIPSONARLINT=1 git push

Tip: here's an example Git alias to git push without analysis:

pushf = "!f() { SKIPSONARLINT=1 git push \"$@\"; }; f"

To permanently disable the hook, you can simply rename the script file.

Limitations

If there are too many files to analyze, the argument list might exceed the length limit of the operating system.

sonarlint-git-hooks's People

Contributors

janosgyerik avatar

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.