Last updated
Tab Width Settings
Language / Context Recommended spaces per tab
------------------ --------------------------
JavaScript / TypeScript 2
Python 4
Java / C# / C++ 4
Go tabs (no conversion needed)
Ruby 2
HTML / CSS 2
SQL 4
EditorConfig Integration
After converting, add an .editorconfig file to enforce consistent indentation for all contributors:
# .editorconfig
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.py]
indent_size = 4
[Makefile]
indent_style = tab
Git Commit Strategy
When converting indentation across a large codebase, make the change in a single dedicated commit:
# Convert all JS files from tabs to 2-space indentation
# Then commit with a clear message
git add -A
git commit -m "style: convert indentation from tabs to 2 spaces
Formatting-only change. No logic modified.
Run with: prettier --write '**/*.js'"
This keeps the commit history clean and makes it easy to review subsequent commits that contain actual logic changes.
Examples
Example 1: Spaces to Tabs (4-space indent)
Input (4 spaces per indent level):
def calculate_total(items):
total = 0
for item in items:
if item['active']:
total += item['price']
return total
Output (tabs):
def calculate_total(items):
total = 0
for item in items:
if item['active']:
total += item['price']
return total
Example 2: Spaces to Tabs (2-space indent)
Input (2 spaces per indent level):
function greet(name) {
if (name) {
return `Hello, ${name}!`;
} else {
return 'Hello, World!';
}
}
Output (tabs):
function greet(name) {
if (name) {
return `Hello, ${name}!`;
} else {
return 'Hello, World!';
}
}
Example 3: Tabs to Spaces (2 spaces)
Input (tabs):
const config = {
host: 'localhost',
port: 3000,
database: {
name: 'mydb',
pool: {
min: 2,
max: 10
}
}
};
Output (2 spaces per tab):
const config = {
host: 'localhost',
port: 3000,
database: {
name: 'mydb',
pool: {
min: 2,
max: 10
}
}
};