Slide 1

Slide 1 text

ANALYZE YOUR CHANGESET IN A BRANCH BEFORE GIT PUSH WITH SONARLINT + GIT HOOKS https://speakerdeck.com/janosgyerik/sonarlint-before-git-push

Slide 2

Slide 2 text

Let’s talk about SonarTech… (aka sonar-github) SonarTech

Slide 3

Slide 3 text

SonarTech

Slide 4

Slide 4 text

SonarTech

Slide 5

Slide 5 text

SonarTech

Slide 6

Slide 6 text

SonarTech

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

You think you coded a great branch… You think “there should be no more issues”… … sorry bud, you thought wrong!

Slide 9

Slide 9 text

Delay to generate comments git push fixes -> more delays -> -> more issues -> git push fixes ->

Slide 10

Slide 10 text

Don’t get me wrong This is absolutely necessary But would you push a branch if you *knew* it has 10+ issues? (-> no)

Slide 11

Slide 11 text

Let’s talk about

Slide 12

Slide 12 text

SonarLint helps, but you have to look… …it’s harder than it sounds

Slide 13

Slide 13 text

Example * Open SonarLint view * Build gets broken * (SonarLint view gone…)

Slide 14

Slide 14 text

build broken

Slide 15

Slide 15 text

Example * Open SonarLint view * Run unit tests * (SonarLint view gone…)

Slide 16

Slide 16 text

run unit tests

Slide 17

Slide 17 text

SonarLint can help, but you have to look! Sooner or later you cannot help and lose sight of the SonarLint view, and SonarLint just cannot force you to look, not all the time, that’s just the way it is

Slide 18

Slide 18 text

+ = cli hooks

Slide 19

Slide 19 text

$ sonarlint --src path/to/file1 --tests path/to/file2

Slide 20

Slide 20 text

$ ls -1 .git/hooks/ applypatch-msg.sample commit-msg.sample post-update.sample pre-applypatch.sample pre-commit.sample pre-push.sample pre-rebase.sample prepare-commit-msg.sample update.sample

Slide 21

Slide 21 text

Let’s see it in action

Slide 22

Slide 22 text

$ git push origin HEAD info: source files to analyze: info: src/main/java/example/HelloWorld.java info: src/main/java/example/Two.java info: analyzing... ------------- SonarLint Report ------------- 3 issues (2 files analyzed) 2 major 1 info ------------------------------------------- INFO: SonarLint HTML Report generated: /Users/janos/dev/git/github/java-maven-simple/.sonarlint/ sonarlint-report.html fatal: hook abort: some analyses have failed error: failed to push some refs to '[email protected]:janosgyerik/java-maven-simple.git' (push rejected if issues exist)

Slide 23

Slide 23 text

$ git push origin HEAD info: source files to analyze: info: src/main/java/example/HelloWorld.java info: src/main/java/example/Two.java info: analyzing... ------------- SonarLint Report ------------- No issues to display (2 files analyzed) ------------------------------------------- INFO: SonarLint HTML Report generated: /Users/janos/dev/git/github/java-maven-simple/.sonarlint/sonarlint- report.html Counting objects: 42, done. Delta compression using up to 8 threads. Compressing objects: 100% (24/24), done. Writing objects: 100% (42/42), 2.84 KiB | 0 bytes/s, done. Total 42 (delta 11), reused 0 (delta 0) remote: Resolving deltas: 100% (11/11), completed with 2 local objects. To [email protected]:janosgyerik/java-maven-simple.git * [new branch] HEAD -> demo (no issues -> push OK)

Slide 24

Slide 24 text

git clone https://github.com/janosgyerik/sonarlint-git-hooks cd sonarlint-git-hooks ./get-and-setup-sonarlint.sh hooks=$PWD cd /path/to/your/project $hooks/install.sh cd /path/to/another/project $hooks/install.sh

Slide 25

Slide 25 text

https://github.com/janosgyerik/sonarlint-git-hooks/issues Problems? Ideas? Feature requests?