Improve Frontend Code Quality with Tools — SonarQube

Using SonarQube alongside ESLint to improve frontend code quality: differences, setup, and CI integration.

Jan 28, 2021 · 1 min read · 227 Words · -Views -Comments · Programming
🇨🇳 阅读中文版
Read with AI

Choose an AI assistant

ChatGPT Open in a new tab with the article link and prompt
Claude Copy the prompt, then open Claude

Open Claude
Trouble reading the article?

If the prompt is missing, copy the full prompt below into your AI assistant. If the AI cannot read the article, paste the visible passage you want to discuss and add your question.

Our backend teams adopted SonarQube; I followed suit on the frontend. Along the way I corrected some misconceptions — notes below.

SonarQube vs. ESLint

ESLint is familiar to frontend devs; it enforces style and some best practices. With unit tests, I once thought Sonar wasn’t necessary. In practice they differ:

  1. ESLint focuses on style and some patterns; you fix findings manually or via autofix.
  2. Sonar goes beyond style to detect code smells and potential bugs, tracks trends over time, and gives quality gates.

They’re complementary — especially useful for large teams with varied experience.

Setup

Here’s a minimal setup:

  1. SonarQube Web创建新项目
  2. 项目下增加sonar-project.properties,按需配置,
  3. GitLab CI增加如下PipeLine
sonar:
  stage: sonar_scanner
  image: "nexus.abc.cn/sonarsource/sonar-scanner-cli:4"
  allow_failure: true
  services:
    - docker:stable-dind
  script:
    - sonar-scanner -Dsonar.projectKey=$SONAR_QUBE_PROJECT_KEY
  only:
    - /^sprint/

This triggers a Sonar scan on branches prefixed with sprint. Adjust rules and conditions over time.

Final Thoughts

Humans make mistakes — tools like Sonar complement reviews and tests by continuously surfacing potential issues.

References

Authors
Developer, digital product enthusiast, tinkerer, sharer, open source lover