Commit Message Conventions & Linting · Formatters
This page collects ways to standardize and automate two things with rules: commit messages and code style.
Conventional Commit: Rules for Commit Messages
Commit messages are a key clue for quickly understanding what changed in the code. They also help a lot when you need to trace the cause of a problem later. Conventional Commit is a set of rules created to do this systematically.
The format looks like this:
<type>(<scope>): <subject>type: the kind of commitscope: the area affectedsubject: a short description (starting with an imperative verb)
For example, if you added email verification to the login screen:
feat(UserProfile): Add email verificationCommon types
| type | Meaning |
|---|---|
feat | Add a new feature |
fix | Fix a bug |
docs | Change documentation |
style | Code formatting (no logic change) |
refactor | Improve code structure without changing behavior |
test | Add/modify test code |
chore | Minor tasks such as build or configuration |
Why bother following rules this strictly?
When commits pile up in a consistent format, you can later pick out only the feat commits and automatically generate release notes. Nobody has to compile the change history by hand.
Automating Style with Linting and Formatters
Developers hate repetitive work. Having people memorize code style rules and fix them by hand every time is inefficient. That is why Linting and Formatters came along.
- Linting: automatically checks whether code style, syntax and potential errors break the rules
- Formatter: a tool that automatically fixes code to match the linting rules
Linting unifies the whole team's coding style to improve readability, and lets reviewers focus on logic instead of style. If you keep the config files in the project root and share them through Git, you don't need to explain the rules verbally when a new teammate joins.
JavaScript: ESLint + Prettier
Before:
const name="John",age=25;function greet(name,age){console.log('Hello, '+name)}After:
const name = 'John',
age = 25;
function greet(name, age) {
console.log('Hello, ' + name);
}.eslintrc sets the lint rules and .prettierrc sets the formatting rules. However, the two can conflict, so you need a plugin such as eslint-config-prettier to turn off the conflicting rules.
Python: Flake8 + Black + isort
Python is a dynamically typed language used in many different fields (servers, data, ML and more), so there are several linting tools.
- Flake8: PEP 8-based style checks + complexity/logic error checks (
.flake8config) - Black: a formatter that automatically arranges code according to PEP 8 (
pyproject.tomlconfig) - isort: automatically sorts import statements in the order standard library / third-party / project-internal (
.isort.cfgconfig)
pip3 install flake8 black isort
flake8 src/
black src/
isort src/Summary
| Concept | One-line summary |
|---|---|
| Conventional Commit | Standardizes commit messages in the <type>(<scope>): <subject> format, enabling automatic documentation |
| Linting / Formatter | Automatically checks code style (Linting) and automatically corrects it (Formatter) |
Source: Codyssey-B1/B2-2
