You are currently viewing Convert Tabs to Spaces Before Pasting Into Strict Linters

Convert Tabs to Spaces Before Pasting Into Strict Linters

TL;DR / Summary: Tabs copied from one editor can fail CI the moment a repo enforces spaces-only indentation. Convert tabs to the project’s space width before you paste into a review comment, a web IDE, or a ticket snippet—then lint sees what you intended, not a mix of invisible characters.

Why a “clean” paste still fails lint

Your local editor may render a tab as four columns while the remote linter expands tabs as eight, or rejects tabs entirely. The visual alignment you trusted in the browser preview collapses when ESLint, RuboCop, or gofmt runs on a spaces-only tree. Reviewers then argue about style instead of the logic you meant to share.

Mixed indentation is worse: a file that already uses spaces gains a pasted block with tabs. Many formatters treat that as an error, not a soft warning, and the build goes red on a one-line hotfix.

Detect tabs before you blame the rule

Turn on visible whitespace in your editor, or pipe the clipboard through a check that flags U+0009. If you only look at the rendered gutter, tabs and spaces look identical. A quick convert-and-diff cycle on a throwaway buffer shows whether the problem is width or character identity.

Online text utilities that expand tabs to a chosen width help when you are mid-ticket and cannot open the full IDE. Paste, set width to match .editorconfig or the repo’s documented indent, copy the spaced result back. Tools on Masters Tool fit that clipboard-first workflow when you are away from your usual setup.

Match width to the project, not to muscle memory

Python projects often want four spaces; Go wants tabs that gofmt owns; many JavaScript trees want two spaces. Expanding every tab to four spaces into a two-space repo still fails prettier. Read the nearest config file before converting. Wrong width is still wrong even when every tab is gone.

Makefiles are the classic exception: recipe lines must start with a real tab. Converting those to spaces breaks Make itself. Scope your conversion to source and config languages that document spaces, and leave Makefile recipes alone.

Snippet comments in GitHub and Jira

Fenced code blocks in tickets often preserve tabs until someone copies them into a patch. If your team pastes “suggested fix” blocks into PRs, convert first so the suggestion applies cleanly with “Commit suggestion.” Otherwise the author spends a commit fighting whitespace noise.

EditorConfig and CI should agree

When indent_style = space lives in EditorConfig but the CI formatter still accepts tabs, onboarding becomes tribal knowledge. Align both sides. Developers who convert tabs before paste are compensating for that gap; fixing the gap removes the ritual for everyone.

If you maintain a monorepo with mixed languages, document per-package indent rules in the contributing guide with one concrete example each. Ambiguous “use project defaults” language is how tabs sneak into the wrong package.

A safe convert workflow for hotfixes

Copy the suspect block into a scratch buffer. Expand tabs to the repo width. Run the same formatter the CI uses on that buffer if available. Paste into the PR or patch. Avoid converting an entire legacy file in the same commit as a behavioral fix—reviewers cannot see the real change under a thousand indent flips.

For emergency patches on a phone browser, do the expand step in a text tool first, then paste into the web editor. Mobile keyboards rarely expose a clear tab-versus-space signal.

When soft tabs hide the problem

Some editors insert spaces when you press Tab (“soft tabs”) but still leave literal tabs in older files. You can believe you “always use spaces” while the file on disk disagrees. A project-wide search for the tab character before a release branch cut catches surprises that soft-tab muscle memory misses.

Binary or generated files should stay out of that search. Limit scans to source globs your formatter already owns.

Teaching the habit without shaming

New contributors often paste from tutorials that used tabs for brevity. Link the indent rule and a one-click convert path in the first review comment instead of only citing the failed job URL. The goal is a green build and a clearer diff, not a purity contest.

Keep a short internal note: language, required style, convert tip, formatter command. That note saves more time than another debate in Slack about whether tabs are morally superior.

Clipboard hygiene for multi-file pastes

When you assemble a reproduction from three files, convert each block separately at its own width. A YAML sidecar that wants two spaces next to a Python module that wants four will break if you run one global expand. Label each paste with the path so reviewers know which rule applied.

If you regularly move snippets between stacks, a dedicated convert pass on Masters Tool before the ticket update is faster than re-indenting by hand in the browser.

PR bots that rewrite only half the file

Some repositories run a formatter on changed lines only. A pasted tab inside a spaces file can survive if the bot formats solely the hunk boundaries and leaves the middle untouched. Full-file format jobs catch the mix; partial jobs do not. When you know CI uses a sparse formatter, convert before paste rather than hoping the bot will finish the job.

Pre-commit hooks on your laptop that expand tabs locally prevent the round trip entirely. Install the same hook the repo documents so your clipboard habit and the hook agree on width. If the hook and EditorConfig disagree, fix that conflict once instead of teaching every contributor a private convert ritual.

Patch files downloaded from review tools sometimes reintroduce tabs when the web UI normalizes whitespace for display. Re-open the downloaded patch in a hex-aware or visible-whitespace view before applying it with git apply.

Indent that survives the pipeline

Tabs are not evil; mismatched indentation is. Convert to the width and style your linter already enforces before the paste lands in a PR, a gist, or a support ticket. The characters you cannot see are the ones that burn the most CI minutes—fix them on purpose, once, before the bot does it the hard way.