# How to keep code formatting consistent in Replit

- Tool: Replit
- Difficulty: Beginner
- Time required: 15-20 minutes
- Compatibility: All Replit plans (Starter, Core, Pro). Works with JavaScript, TypeScript, Python, and most languages.
- Last updated: March 2026

## TL;DR

Keep code formatting consistent in Replit by adding Prettier and ESLint configuration files to your project root, installing them via Shell, creating an .editorconfig for universal editor settings, and wiring format checks into your .replit run command. This ensures every collaborator writes identically styled code without manual enforcement.

## Configure Code Formatting for Team-Wide Consistency in Replit

Inconsistent code formatting creates friction in collaborative projects and makes code reviews harder than they need to be. This tutorial shows you how to set up Prettier, ESLint, and .editorconfig in a Replit project so every team member follows the same style rules automatically. You will configure each tool, create the necessary config files, and connect everything to your run workflow.

## Before you start

- A Replit account on any plan (Starter, Core, or Pro)
- A JavaScript or TypeScript project in Replit
- Basic familiarity with the Replit workspace and Shell tab
- No prior experience with Prettier, ESLint, or EditorConfig required

## Step-by-step guide

### 1. Install Prettier and ESLint as dev dependencies

Open the Shell tab in your Replit workspace (find it in the Tools dock on the left sidebar). Run the npm install command below to add Prettier, ESLint, and the compatibility config that prevents rule conflicts between them. Installing these as devDependencies means they are project-scoped and available to every collaborator who opens the Repl, without polluting the global environment.

```
npm install --save-dev prettier eslint eslint-config-prettier
```

**Expected result:** All three packages install successfully with no errors. You will see them listed under devDependencies in package.json.

### 2. Create the .prettierrc configuration file

Click the three-dot menu at the top of the file tree, select 'Add file,' and name it .prettierrc. This JSON file defines your project-wide formatting rules. Every developer who works on this Repl will use the same settings automatically. The configuration below enforces single quotes, 2-space indentation, trailing commas, and an 80-character line width, which are the most common conventions in modern JavaScript projects.

```
{
  "semi": true,
  "singleQuote": true,
  "tabWidth": 2,
  "trailingComma": "es5",
  "printWidth": 80,
  "bracketSpacing": true,
  "arrowParens": "always",
  "endOfLine": "lf"
}
```

**Expected result:** A .prettierrc file appears in your project root. Prettier will use these rules for all formatting operations.

### 3. Create an .editorconfig file for universal settings

EditorConfig is a standard supported by most editors and IDEs. While Replit does not natively read .editorconfig, having one in your project root ensures that collaborators who clone the repo into VS Code, Cursor, or other editors maintain the same settings. Create a new file named .editorconfig in the project root and paste the configuration below.

```
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
```

**Expected result:** An .editorconfig file exists in the project root. Any editor that supports EditorConfig will automatically apply these settings.

### 4. Initialize ESLint with a flat configuration

Create a file named eslint.config.js in your project root. This uses the modern flat config format that ESLint now defaults to. The configuration below sets up recommended rules and integrates eslint-config-prettier to disable any ESLint rules that would conflict with Prettier. This means ESLint handles code quality (unused variables, missing returns) while Prettier handles formatting (indentation, quotes, semicolons).

```
import js from '@eslint/js';
import prettierConfig from 'eslint-config-prettier';

export default [
  js.configs.recommended,
  prettierConfig,
  {
    rules: {
      'no-unused-vars': 'warn',
      'no-console': 'warn',
      'prefer-const': 'error',
    },
  },
];
```

**Expected result:** ESLint is configured to check code quality without conflicting with Prettier formatting rules.

### 5. Add format and lint scripts to package.json

Open your package.json and add scripts for formatting, linting, and a combined check command. These scripts give you reusable commands you can run from Shell or wire into your .replit configuration. The format:check script is useful for CI-like verification without modifying files.

```
{
  "scripts": {
    "format": "prettier --write \"src/**/*.{js,jsx,ts,tsx,css,json}\"",
    "format:check": "prettier --check \"src/**/*.{js,jsx,ts,tsx,css,json}\"",
    "lint": "eslint src/",
    "lint:fix": "eslint src/ --fix",
    "check": "npm run format:check && npm run lint",
    "start": "node index.js"
  }
}
```

**Expected result:** Running 'npm run format' in Shell formats all source files. Running 'npm run lint' reports code quality issues.

### 6. Wire formatting into the .replit run command

Open the .replit file (enable 'Show hidden files' if you cannot see it) and update the run command to format and lint before starting the application. This ensures every time you or a collaborator presses the Run button, the code is automatically formatted and checked. For team projects, this is the single most effective way to enforce consistent style without relying on individual discipline.

```
run = "npx prettier --write src/ && npx eslint src/ && node index.js"
```

**Expected result:** Pressing the Run button now formats code, runs ESLint checks, and then starts the application. Console output shows the formatter and linter results before app startup.

## Complete code example

File: `.replit`

```toml
# .replit configuration with formatting and linting on run

entrypoint = "index.js"
modules = ["nodejs-20:v8-20230920-bd784b9"]

# Format and lint before running the app
run = "npx prettier --write src/ && npx eslint src/ && node index.js"

[nix]
channel = "stable-24_05"

[deployment]
run = ["sh", "-c", "node index.js"]
build = ["sh", "-c", "npm install && npx prettier --write src/"]
deploymentTarget = "cloudrun"

[[ports]]
localPort = 3000
externalPort = 80

hidden = [".config", "package-lock.json", "node_modules"]
```

## Common mistakes

- **Installing Prettier globally instead of as a project devDependency** — undefined Fix: Use 'npm install --save-dev prettier' so the formatter version is locked to the project and automatically available to every collaborator.
- **Having ESLint formatting rules that conflict with Prettier** — undefined Fix: Install eslint-config-prettier and add it as the last item in your ESLint config array. This disables all ESLint rules that Prettier already handles.
- **Forgetting to create .prettierignore, causing Prettier to format node_modules** — undefined Fix: Create a .prettierignore file listing node_modules, dist, build, and any generated files you do not want Prettier to touch.
- **Configuring different indentation in .editorconfig and .prettierrc** — undefined Fix: Make sure tabWidth in .prettierrc matches indent_size in .editorconfig. Both should use the same value (typically 2 for JavaScript projects).

## Best practices

- Always commit .prettierrc, .editorconfig, and eslint.config.js to the project so every collaborator inherits the same rules
- Use eslint-config-prettier to prevent ESLint and Prettier from fighting over formatting rules
- Add a .prettierignore file that excludes node_modules, dist, build, and lock files for faster formatting
- Pin formatter and linter versions in package.json to avoid surprise style changes after updates
- Use the format:check script (--check flag) in deployment builds to catch unformatted code without modifying files
- Keep .editorconfig in sync with .prettierrc to avoid conflicts when collaborators use external editors
- For Python projects, use Black with a pyproject.toml instead of Prettier
- Run formatting before linting in your run command so linters see already-formatted code

## Frequently asked questions

### Does Replit have built-in code formatting settings?

No. As of March 2026, Replit does not have a built-in formatting configuration panel. You need to install external formatters like Prettier or Black and configure them via files in your project root.

### Will formatting slow down my Run button?

For projects under 100 source files, Prettier adds less than 2 seconds. For larger projects, add a .prettierignore file and limit formatting to your src directory.

### Can Replit Agent set up formatting for my project?

Yes. Prompt Agent v4 with: 'Set up Prettier with single quotes and 2-space indentation, ESLint with eslint-config-prettier, and an .editorconfig. Wire formatting into the run command.' Agent will install packages and create all config files.

### How do I enforce formatting in a team project?

Wire the format command into the .replit run command so every collaborator formats code automatically on every run. Additionally, use the format:check script in your deployment build to reject unformatted code before it reaches production.

### Should I use ESLint or Prettier for formatting?

Use both. Prettier handles formatting (indentation, quotes, semicolons) and ESLint handles code quality (unused variables, unreachable code). Install eslint-config-prettier to prevent rule conflicts.

### What about formatting Python code in Replit?

Install Black via Shell with 'pip install black'. Black enforces a single opinionated style with zero configuration. Add 'black . && python main.py' to your .replit run command.

### Does .editorconfig work in Replit?

Replit's built-in editor does not read .editorconfig natively. However, including the file in your project ensures that collaborators who clone the repo into VS Code, Cursor, or other editors maintain consistent settings.

### What if my formatting setup becomes too complex for browser-based configuration?

For projects that outgrow simple config files and need advanced CI pipelines with pre-commit hooks and automated formatting checks, the RapidDev team can help you design a scalable development workflow.

---

Source: https://www.rapidevelopers.com/replit-tutorial/how-to-configure-code-formatting-settings-in-replit-for-a-consistent-codebase
© RapidDev — https://www.rapidevelopers.com/replit-tutorial/how-to-configure-code-formatting-settings-in-replit-for-a-consistent-codebase
