Skip to content
IRC-CodingIRC-Coding
Static Code AnalysisESLintSonarQubePylintSpotBugsCI/CDCode Quality

Static Code Analysis Tools: ESLint, SonarQube, Pylint

Automated code quality checks with ESLint, SonarQube, Pylint, SpotBugs. CI/CD integration and best practices.

S

schutzgeist

3 min read
Static Code Analysis Tools: ESLint, SonarQube, Pylint

Static Code Analysis Tools

Static Code Analysis Tools examine source code without executing it, automatically detecting bugs, security vulnerabilities, and code smells.

In a Nutshell

Static Code Analysis (SCA) analyzes code without running it. Tools like ESLint (JS), Pylint (Python), and SonarQube (multi-language) automatically find bugs, security issues, and code smells. They integrate into CI/CD pipelines as quality gates.

Technical Overview

Static Code Analysis is the automated examination of source code without execution. Tools check syntax, semantics, coding standards, security vulnerabilities, and code quality metrics. Analysis happens through pattern matching, data flow analysis, and abstract interpretation. SCA tools typically integrate into CI/CD pipelines and can serve as quality gates, preventing poor code from being merged.

Why Static Code Analysis?

  • Automation: Finds errors faster than manual code reviews
  • Consistency: Enforces uniform coding standards across teams
  • Security: Catches vulnerabilities before production
  • Learning: New developers learn through immediate tool feedback
  • Metrics: Measurable code quality over time

Tools Overview

ToolLanguageTypeHighlights
ESLintJavaScript/TSLinterHighly configurable with plugin system
PrettierJavaScript/TSFormatterOpinionated code formatting
PylintPythonLinterPEP-8 compliant, comprehensive
BlackPythonFormatterUncompromising, PEP-8 aligned
SonarQubeMultiPlatformCode quality dashboard
SpotBugsJavaLinterFinds Java-specific bugs
CheckstyleJavaLinterEnforces coding standards
RuboCopRubyLinterRuby style guide enforcement

ESLint (JavaScript/TypeScript)

Installation

npm install --save-dev eslint
npx eslint --init

Configuration

// .eslintrc.js
module.exports = {
  env: {
    browser: true,
    es2021: true,
    node: true,
  },
  extends: [
    'eslint:recommended',
    'plugin:@typescript-eslint/recommended',
    'plugin:prettier/recommended',
  ],
  parser: '@typescript-eslint/parser',
  plugins: ['@typescript-eslint'],
  rules: {
    'no-unused-vars': 'error',
    'no-console': 'warn',
    '@typescript-eslint/no-explicit-any': 'warn',
  },
};

Example Violations

// ESLint error: no-unused-vars
const unused = 42;

// ESLint error: no-console
console.log('Debug output');

// ESLint error: prefer-const
var x = 5;

Pylint (Python)

Installation

pip install pylint

Configuration

# .pylintrc
[MASTER]
disable=C0111,C0103

[FORMAT]
max-line-length=100

[BASIC]
good-names=i,j,k,ex,Run,_

Running Pylint

pylint mymodule.py

SonarQube (Multi-Language)

Installation (Docker)

docker run -d --name sonarqube -p 9000:9000 sonarqube

Configuration

# SonarQube Scanner
sonar-scanner \
  -Dsonar.projectKey=my-project \
  -Dsonar.sources=src \
  -Dsonar.host.url=http://localhost:9000

Quality Gate Standards

  • Coverage: > 80%
  • Duplications: < 3%
  • Security Rating: A
  • Reliability Rating: A

CI/CD Integration

GitHub Actions

name: Code Quality

on: [push, pull_request]

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: '18'
      - run: npm ci
      - run: npm run lint
      - run: npm run test:coverage

GitLab CI

code_quality:
  image: sonarsource/sonar-scanner-cli
  script:
    - sonar-scanner
  only:
    - merge_requests
    - main

Best Practices

  • Early Integration: Start using SCA early in your development process
  • Custom Rules: Tailor rules to your project instead of relying on defaults
  • Auto-Fix: Leverage automatic fixes for simple issues
  • Quality Gates: Block builds when critical issues are detected
  • Regular Updates: Keep tools and rulesets current

Exam-Relevant Key Points

  • Static Code Analysis examines code without execution
  • Common tools: ESLint (JS), Pylint (Python), SonarQube (multi-language)
  • Linters check code; formatters fix style automatically
  • CI/CD integration enforces quality gates
  • Automates code quality checks

FAQ

1. What is Static Code Analysis?

Automated analysis of source code without execution to find bugs and code smells.

2. What’s the difference between a linter and formatter?

A linter checks for errors and code smells; a formatter automatically fixes code style.

3. What is ESLint?

A linter for JavaScript/TypeScript with an extensive plugin system and customization.

4. What is Pylint?

A Python linter that checks PEP-8 compliance and overall code quality.

5. What is SonarQube?

A multi-language platform for code quality analysis with dashboards and quality gates.

6. How do you integrate SCA into CI/CD?

Add the linter or scanner to your pipeline and block builds when issues arise.

7. What is a quality gate?

Thresholds that must be met before code can be merged.

8. What is Prettier?

An opinionated formatter for JavaScript/TypeScript that automatically formats code.

9. What is Black?

An uncompromising Python formatter that is PEP-8 compliant.

10. How does SCA compare to testing?

SCA checks code structure; testing verifies behavior. They complement each other.

11. How does SCA compare to code review?

SCA is automated; code review is manual and evaluates architecture and design.

12. When should you use SCA?

Early in the project, before commits and throughout your CI/CD pipeline.

13. Should you customize rules?

Yes, tailor rules to your project and team; don’t stick with defaults.

14. What is SpotBugs?

A Java linter that finds typical Java bugs and security vulnerabilities.

15. How does SCA perform?

Quickly, from seconds to minutes. Analysis can be parallelized.

Next in the Software Quality Learning Path

The next article in the Software Quality Learning Path covers Software Quality and Maintainability — how to achieve maintainable code through good architecture, documentation, and testing.

Sources

  1. https://eslint.org/
  2. https://pylint.pycqa.org/
  3. https://www.sonarqube.org/

If you’d like to dive deeper into Static Code Analysis, tools, and software quality, we recommend these books:

Software Engineering

Books about software quality, clean code, code reviews and software development processes

Clean Code: A Handbook of Agile Software Craftsmanship von Robert C. Martin

Clean Code: A Handbook of Agile Software Craftsmanship von Robert C. Martin

Bei Amazon ansehen

Affiliate-Link: Bei einem Kauf erhalten wir möglicherweise eine Provision.

The Pragmatic Programmer: Your Journey to Mastery von David Thomas, Andrew Hunt

The Pragmatic Programmer: Your Journey to Mastery von David Thomas, Andrew Hunt

Bei Amazon ansehen

Affiliate-Link: Bei einem Kauf erhalten wir möglicherweise eine Provision.

Back to Blog
Share:

Related Posts