Skip to content
Notifications
Clear all

Step-by-step: Getting Windsurf to respect our ESLint and Prettier rules.

1 Posts
1 Users
0 Reactions
3 Views
(@integrations_ivan)
Estimable Member
Joined: 4 months ago
Posts: 125
Topic starter   [#1007]

Our team recently completed a significant integration project where we standardized on a specific set of ESLint rules and Prettier formatting to ensure code consistency across our microservices and the middleware layer. Adopting Windsurf as our primary editor introduced an unexpected challenge: its AI-driven code completion and inline edit features (`Cmd/Ctrl + I`) were frequently generating code that violated our established project rules, creating diff noise and failing pre-commit hooks.

The core issue stems from the need to explicitly configure Windsurf's underlying language server to respect local project configuration files. Through systematic testing, I've mapped out the necessary steps to align Windsurf's behavior with our linting and formatting stack.

**Primary Configuration Steps:**

1. **Project Root Configuration:** Ensure your `eslint.config.js` (or `.eslintrc.*`) and `prettier.config.js` are present and correctly configured. Windsurf, like many editors, looks for these at the project root.
2. **Windsurf Settings JSON:** Access the command palette (`Cmd/Ctrl + Shift + P`) and open `Preferences: Open User Settings (JSON)`. You must add explicit directives for the LSP.

**Crucial Settings JSON Entries:**

```json
{
"eslint.experimental.useFlatConfig": true, // Only if you are using eslint.config.js (ESLint 9+)
"eslint.workingDirectories": ["./"],
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"prettier.requireConfig": true
}
```

3. **Extension Management:** Install and enable the official "ESLint" and "Prettier - Code formatter" extensions via Windsurf's Extensions panel. Windsurf's native capabilities often lean on these.
4. **Workspace Trust:** For corporate environments with monorepos or linked modules, ensure the workspace is trusted. Untrusted workspaces heavily restrict extension functionality, including ESLint.

**Additional Considerations for Data Consistency:**
* **Node.js & Package Manager:** Ensure Windsurf's integrated terminal or environment is using the correct Node.js version (via `.nvmrc` or `.node-version`) where your ESLint and Prettier are installed. A version mismatch can cause rule resolution failures.
* **Path Resolution in Monorepos:** For monorepo structures (e.g., Turborepo, Nx), you may need a more precise `eslint.workingDirectories` setting, such as `["apps/*", "packages/*"]`, to direct the LSP to the correct subdirectories.
* **Validation:** Open a problematic file, open the Command Palette, and run `ESLint: Restart ESLint Server`. Check the ESLint output channel for any configuration load errors.

After applying this configuration map, Windsurf's generated code and suggestions should now adhere to your project's style guide. The key is treating Windsurf's editor core as a configurable integration point in your development toolchain, much like configuring an API gateway to enforce consistent request/response formats.

-- Ivan


Single source of truth is a myth.


   
Quote