Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Principle:SeleniumHQ Selenium Code Formatting Pipeline

From Leeroopedia
Knowledge Sources
Domains Code_Quality, Continuous_Integration, Developer_Experience
Last Updated 2026-02-11 00:00 GMT

Overview

Automated multi-language code formatting and linting pipeline that ensures consistent code style across the polyglot Selenium monorepo.

Description

The Selenium monorepo contains code in Java, Python, Ruby, JavaScript, Rust, .NET, Bazel (Starlark), Shell, and YAML. The scripts/format.sh script provides a unified formatting pipeline that detects changed files relative to trunk using git diff, classifies them by path and extension, and applies the appropriate formatter. It always runs buildifier (for *.bzl, BUILD.bazel, MODULE.bazel files) and update_copyright (license headers). Language-specific formatters are run conditionally based on which files changed:

  • Java: google-java-format
  • JavaScript: prettier
  • Ruby: rubocop with autocorrect (-a)
  • Python: ruff format (and ruff check with --lint flag)
  • Rust: rustfmt via @rules_rust
  • .NET: dotnet format (style + whitespace)
  • Shell/Actions: actionlint + shellcheck (lint mode only)

The script exits with code 1 if formatters modify files beyond the baseline, signaling that formatting was needed. Python follows PEP 8 with a 120-character line length.

Usage

Run ./scripts/format.sh before committing to ensure code passes CI formatting checks. Use --pre-commit for staged changes only, --all to format everything, or --lint to also run linters. The alternative ./go all:lint command provides equivalent functionality.

Theoretical Basis

# Formatting Pipeline Flow
1. Parse flags: --all, --pre-commit, --pre-push, --lint
2. Detect changed files:
   - Default: git diff trunk... (committed + staged + unstaged + untracked)
   - --pre-commit: git diff --cached (staged only)
   - --pre-push: git diff base..HEAD (committed vs trunk)
   - --all: skip detection, format everything
3. Capture baseline: git status --porcelain
4. Always run:
   - buildifier (Bazel/Starlark files)
   - update_copyright (license headers)
5. Conditionally run per language (if matching files changed):
   - Java (^java/): google-java-format --replace
   - JavaScript (^javascript/selenium-webdriver/): prettier --write
   - Ruby (^rb/|^rake_tasks/|^Rakefile): rubocop -a
   - Rust (^rust/): rustfmt via @rules_rust
   - Python (^py/): ruff format (+ ruff check if --lint)
   - .NET (^dotnet/): dotnet format style + whitespace
   - Shell/Actions: actionlint + shellcheck (--lint only)
6. Compare: git status --porcelain vs baseline
7. Exit 1 if formatters modified files; exit 0 otherwise

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment