Skip to main content
RapidDev - Software Development Agency
lovable-issues

Customizing Code Style and Preferences in Lovable Projects

Lovable generates code with its own default formatting and conventions, which may not match your preferences. Customize code style by adding an AGENTS.md file to your project root with specific coding conventions, configuring ESLint and Prettier in your project files, and enabling TypeScript strict mode. The AGENTS.md file is read by Lovable's AI on every session, ensuring consistent output across all future prompts.

Book a free consultation
4.9Clutch rating
600+Happy partners
17+Countries served
190+Team members
Beginner8 min read~10 minAll Lovable projects (Vite + React + TypeScript)March 2026RapidDev Engineering Team
TL;DR

Lovable generates code with its own default formatting and conventions, which may not match your preferences. Customize code style by adding an AGENTS.md file to your project root with specific coding conventions, configuring ESLint and Prettier in your project files, and enabling TypeScript strict mode. The AGENTS.md file is read by Lovable's AI on every session, ensuring consistent output across all future prompts.

Why Lovable's generated code style may not match your preferences

Lovable's AI generates TypeScript and React code using its own internal defaults. While the code works, it may not follow your team's conventions. For example, it might use single quotes when you prefer double quotes, or skip semicolons when your style guide requires them. It might also use inline styles instead of Tailwind utility classes, or name components differently than your existing patterns. This inconsistency grows as your project gets larger. If half your files use one convention and half use another, the codebase becomes harder to maintain, especially if you export it to GitHub and continue development in VS Code or Cursor. Lovable reads an AGENTS.md file in your project root at the start of every session. This file acts as persistent instructions for the AI, telling it which coding conventions to follow. Combined with standard config files like .eslintrc and tsconfig.json, you can enforce a consistent style across all generated code.

  • No AGENTS.md file exists to guide Lovable's code generation preferences
  • ESLint configuration file is missing or uses default rules that do not match your style
  • TypeScript is in loose mode, allowing implicit any types and other lenient patterns
  • Lovable's AI defaults do not match the conventions in your existing codebase
  • Multiple contributors (human and AI) generating code without shared formatting rules

Error messages you might see

Parsing error: Unexpected token

ESLint cannot parse the code because the parser configuration does not match the file type. This often happens when ESLint is not configured for TypeScript. Ensure your ESLint config uses @typescript-eslint/parser.

'React' is defined but never used

With modern React (17+), you do not need to import React in every file. If ESLint flags this, add the react/jsx-runtime plugin to your ESLint config so it knows React is available globally.

Type 'string' is not assignable to type 'number'

TypeScript strict mode catches type mismatches that loose mode ignores. This is a good thing because it prevents runtime bugs. Fix the type or add proper type annotations.

Before you start

  • A Lovable project you want to enforce coding conventions on
  • A general idea of your preferred code style (quotes, semicolons, naming conventions)
  • Dev Mode or GitHub access to create files in the project root

How to fix it

1

Create an AGENTS.md file with your coding conventions

AGENTS.md is read by Lovable's AI at the start of every session, ensuring all generated code follows your rules

In your Lovable project, prompt the AI to create an AGENTS.md file at the project root. This file should list your coding preferences clearly. Include rules about naming conventions, file structure, import ordering, component patterns, and any frameworks or libraries to prefer or avoid. Be specific and use examples. The AI reads this file automatically on every session regardless of session length.

Before
typescript
// No AGENTS.md file exists in the project
After
typescript
# AGENTS.md Coding Conventions
## Code Style
- Use double quotes for strings
- Always include semicolons at the end of statements
- Use arrow functions for components: const MyComponent = () => { }
- Prefer named exports over default exports
- Use type instead of interface for TypeScript types
## Naming
- Components: PascalCase (UserProfile, DashboardHeader)
- Files: PascalCase matching the component name (UserProfile.tsx)
- Hooks: camelCase starting with 'use' (useAuth, useFetchData)
- Constants: UPPER_SNAKE_CASE (API_BASE_URL, MAX_RETRIES)
## Imports
- Group imports: React first, then third-party, then local
- Use @/ path alias for all local imports
- Never use relative paths like ../../
## Components
- Keep components under 150 lines; extract sub-components if larger
- Always use shadcn/ui components instead of raw HTML elements
- Use Tailwind utility classes; never write inline styles

Expected result: An AGENTS.md file in the project root. Lovable will follow these conventions in all future code generation.

2

Configure ESLint for consistent linting

ESLint catches style violations and potential bugs in generated code automatically

Ask Lovable to create or update the ESLint configuration file. Lovable projects use TypeScript, so the config should include the TypeScript ESLint parser and plugin. Add rules that match the conventions in your AGENTS.md. This way, even if the AI occasionally deviates from your preferences, ESLint will flag the inconsistency in the code editor.

Before
typescript
// No ESLint configuration or using defaults
After
typescript
// .eslintrc.cjs
module.exports = {
root: true,
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint", "react-hooks"],
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react-hooks/recommended"
],
rules: {
// Enforce double quotes
"quotes": ["warn", "double"],
// Require semicolons
"semi": ["warn", "always"],
// Warn on unused variables (prefix with _ to ignore)
"@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }],
// Warn on any type usage
"@typescript-eslint/no-explicit-any": "warn"
}
};

Expected result: ESLint highlights style violations directly in the Lovable code editor (Dev Mode) and in your GitHub-connected IDE.

3

Enable TypeScript strict mode

Strict mode catches type errors at compile time that would otherwise cause runtime bugs

Open your tsconfig.json and set the strict flag to true. This enables a collection of stricter type-checking options including noImplicitAny, strictNullChecks, and strictFunctionTypes. Lovable's generated code generally works with strict mode, but you may see new type errors in existing files. Ask Lovable to fix each one, as they represent genuine type safety improvements.

Before
typescript
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"strict": false
}
}
After
typescript
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"forceConsistentCasingInFileNames": true
}
}

Expected result: TypeScript now catches implicit 'any' types and null safety issues. Existing code may show new errors that Lovable can fix.

4

Add Prettier for automatic code formatting

Prettier handles formatting (indentation, line length, trailing commas) so you do not have to think about it

Ask Lovable to add a .prettierrc file to your project root. Prettier formats code automatically, which is especially useful when Lovable generates code with inconsistent spacing or line breaks. Configure it to match the rules in your AGENTS.md. If you have both ESLint and Prettier, make sure their rules do not conflict. If this involves coordinating config across multiple files, RapidDev's engineers have set up this exact toolchain across 600+ projects and can ensure everything works together.

Before
typescript
// No Prettier configuration
After
typescript
// .prettierrc
{
"semi": true,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5",
"printWidth": 100,
"bracketSpacing": true,
"arrowParens": "always"
}

Expected result: Code formatting is now consistent across the entire project. When editing in Dev Mode or after GitHub export, Prettier auto-formats on save.

Complete code example

AGENTS.md
1# Project Coding Conventions
2
3This file is read by Lovable's AI agent on every session. Follow these rules for all generated code.
4
5## TypeScript & React
6- Use TypeScript strict mode (all types must be explicit, no 'any')
7- Use arrow function components: const MyComponent = () => { }
8- Prefer named exports: export const MyComponent
9- Use type keyword for types, not interface
10- Always destructure props in the function signature
11
12## Formatting
13- Double quotes for strings
14- Semicolons at end of every statement
15- 2-space indentation
16- Max 100 characters per line
17- Trailing commas in objects and arrays
18
19## File Structure
20- Components in src/components/ (PascalCase filenames)
21- Pages in src/pages/ (PascalCase filenames)
22- Hooks in src/hooks/ (camelCase, prefixed with 'use')
23- Types in src/types/ (PascalCase filenames)
24- Use @/ path alias for all imports, never relative paths
25
26## Styling
27- Use Tailwind utility classes exclusively
28- Never use inline styles or CSS modules
29- Use shadcn/ui components for all UI elements
30- Follow the existing theme in Design view > Themes
31
32## State Management
33- useState for component-local state
34- React Context for auth and theme
35- Zustand for complex shared state
36- Never use prop drilling beyond 2 levels
37
38## IMPORTANT: Preservation Rules
39- Never delete existing components without explicit instruction
40- Never change the routing structure without explicit instruction
41- Never modify environment variables or secrets

Best practices to prevent this

  • Keep AGENTS.md under 500 lines — Lovable reads the entire file, so long files waste context and credits
  • Be specific with examples in AGENTS.md rather than vague instructions like 'write clean code'
  • Include preservation rules in AGENTS.md to prevent the AI from accidentally removing components or changing structure
  • Use ESLint rules that warn rather than error during development — this avoids blocking the build while you iterate
  • Enable TypeScript strict mode early in the project before the codebase grows large and generates many new errors
  • Sync your AGENTS.md conventions with your ESLint and Prettier configs so all tools enforce the same rules
  • Review generated code in Dev Mode after each prompt to verify the AI followed your conventions
  • If exporting to GitHub, add a .editorconfig file so external editors also follow your formatting preferences

Still stuck?

Copy one of these prompts to get a personalized, step-by-step explanation.

ChatGPT Prompt

I have a Lovable project and I want to enforce consistent coding conventions. Here is my current AGENTS.md file (or I do not have one yet): [paste your AGENTS.md here or describe your preferred style] Please: 1. Write a complete AGENTS.md file with coding conventions for TypeScript, React, Tailwind, and shadcn/ui 2. Create a matching .eslintrc.cjs configuration 3. Create a .prettierrc configuration that does not conflict with the ESLint rules 4. Update tsconfig.json to enable strict mode 5. Make sure all configs are compatible with Lovable's Vite + React stack

Lovable Prompt

Create an AGENTS.md file in my project root with coding conventions. Include rules for: TypeScript strict mode, double quotes, semicolons, arrow function components, PascalCase filenames, @/ import paths, Tailwind-only styling, and shadcn/ui components. Also create a .eslintrc.cjs with @typescript-eslint/parser and rules matching these conventions. Add a .prettierrc with semi: true, singleQuote: false, tabWidth: 2. Make sure the configs do not conflict with each other.

Frequently asked questions

How do I make Lovable generate code with my preferred style?

Create an AGENTS.md file in your project root with your coding conventions. Lovable reads this file automatically at the start of every session. Include rules for formatting (quotes, semicolons), naming (PascalCase for components), imports (@/ path alias), and any libraries to prefer.

Does AGENTS.md actually change how Lovable generates code?

Yes. Lovable reads root-level AGENTS.md files regardless of session length. The rules in this file influence all future code generation. The effect is strongest with clear, specific rules and concrete examples rather than vague guidelines.

Can I use ESLint and Prettier in a Lovable project?

Yes. Add .eslintrc.cjs and .prettierrc files to your project root. ESLint warnings appear in Dev Mode and in your IDE after GitHub export. Prettier formats code automatically. Make sure the rules do not conflict by using eslint-config-prettier if needed.

Should I enable TypeScript strict mode in Lovable?

Yes, especially early in the project before the codebase grows large. Strict mode catches type errors that cause runtime bugs. Lovable can fix any new type errors that appear after enabling strict mode, so there is minimal risk.

How do I prevent Lovable from deleting my custom formatting configs?

Add a preservation rule to your AGENTS.md: 'Never modify .eslintrc.cjs, .prettierrc, or tsconfig.json without explicit instruction.' This tells the AI to leave your config files untouched during normal code generation.

What if I can't fix this myself?

If setting up ESLint, Prettier, TypeScript strict mode, and AGENTS.md together feels overwhelming, RapidDev's engineers can configure the entire toolchain for your Lovable project. They have standardized code quality setups across 600+ projects.

RapidDev

Talk to an Expert

Our team has built 600+ apps. Get personalized help with your issue.

Book a free consultation

Need help with your Lovable project?

Our experts have built 600+ apps and can solve your issue fast. Book a free consultation — no strings attached.

Book a free consultation

We put the rapid in RapidDev

Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We'll discuss your project and provide a custom quote at no cost.