node/react -> github -> travis -> sonar

When programming I like to keep my code as clean and automated as possible.

I like sonar (does analysis on your code and provide you output how many duplicate, code smells, unused variables,..)

I like node.js / react.js for its quick prototyping and agile and others advantages. So lastly I was looking if I can have setup where I could automate my infrastructure  code -> push to  VCS (github) -> CI (travis) -> code analysis (Sonar).

Here are steps what you need to do:

  • -> on project settings turn on “travis-ci” integration
    • -> project -> settings -> Integration & services -> Add Service -> Travis CI
  • -> make sure after code push code build is triggered
  • – get started
    • create token here (I used this token in travis – see above)
    • define your organisation here
  • project:

dist: trusty
sudo: required
organization: "czechsource"
- master
- develop
- oraclejdk8
- sonar-scanner
- '$HOME/.sonar/cache'
sonar.projectName=React.js blog

Make sure you define organization and token and use it in travis.

Github repo

travis info

sonarcloud info

Update: I am using git flow and find out that branches “develop” were not sent to sonar. Make sure you add them in .travis.yml as well as in files (marked them in bold)

Update2: there is another option using sonarqube-scanner-node project . (I am assuming your project is made by create-react-app by facebook)

  • yarn add sonarqube-scanner-node --dev
  • yarn test -- --coverage
  • package.json -> add in script section:  "sonarqube": "sonarqube-scanner-node"
  • from command line: yarn sonarqube -Dsonar.organization=chowanioksource -Dsonar.sources=src -Dsonar.projectKey=chowanioksource:reactBlog  -Dsonar.login=< token>


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s