- 
                Notifications
    
You must be signed in to change notification settings  - Fork 0
 
Code Style
Guide to code formatting and style conventions for this project.
This project uses Prettier for code formatting and ESLint for code quality checks. All code must pass both format and lint checks before being deployed.
graph LR
    A[Write Code] --> B[Run Prettier]
    B --> C[Run ESLint]
    C --> D{All Checks Pass?}
    D -->|Yes| E[Commit & Push]
    D -->|No| F[Fix Issues]
    F --> B
    E --> G[CI/CD Pipeline]
    G --> H{Format & Lint Check}
    H -->|Pass| I[Deploy to Firebase]
    H -->|Fail| J[❌ Deployment Blocked]
    File: .prettierrc
{
  "semi": true,
  "trailingComma": "es5",
  "singleQuote": true,
  "printWidth": 80,
  "tabWidth": 2,
  "useTabs": false,
  "arrowParens": "always",
  "bracketSpacing": true,
  "endOfLine": "lf",
  "jsxSingleQuote": false,
  "bracketSameLine": false
}| Option | Value | Description | 
|---|---|---|
semi | 
true | 
Add semicolons at the end of statements | 
trailingComma | 
"es5" | 
Add trailing commas where valid in ES5 | 
singleQuote | 
true | 
Use single quotes instead of double quotes | 
printWidth | 
80 | 
Wrap lines at 80 characters | 
tabWidth | 
2 | 
Use 2 spaces for indentation | 
useTabs | 
false | 
Use spaces instead of tabs | 
arrowParens | 
"always" | 
Always include parentheses around arrow function parameters | 
bracketSpacing | 
true | 
Add spaces inside object literals | 
endOfLine | 
"lf" | 
Use LF line endings (Unix-style) | 
jsxSingleQuote | 
false | 
Use double quotes in JSX | 
bracketSameLine | 
false | 
Put closing bracket on new line in JSX | 
File: .prettierignore
# Dependencies
node_modules
package-lock.json
# Build outputs
dist
build
.vite
# Firebase
.firebase
.firebaserc
firebase-debug.log
firestore-debug.log
# Environment files
.env
.env.local
.env.production
# Logs
*.log
# Misc
*.min.js
*.min.css
# Auto-format all files
npm run format
# Check if files are formatted (no changes)
npm run format:check# Run ESLint
npm run lintAlways format and lint your code before committing:
# Format all files
npm run format
# Check for lint errors
npm run lint
# If all good, commit
git add .
git commit -m "feat: add new feature"To check if your code is properly formatted without making changes:
npm run format:checkThis is useful in CI/CD pipelines.
// ✅ Good: Single quotes, semicolons, proper spacing
import React from 'react';
import { useState } from 'react';
const MyComponent = ({ title, description }) => {
  const [count, setCount] = useState(0);
  const handleClick = () => {
    setCount(count + 1);
  };
  return (
    <div>
      <h1>{title}</h1>
      <p>{description}</p>
      <button onClick={handleClick}>Count: {count}</button>
    </div>
  );
};
export default MyComponent;// ✅ Good: Proper spacing and trailing commas
const user = {
  name: 'John Doe',
  age: 30,
  email: 'john@example.com',
};
const colors = ['red', 'green', 'blue'];
const nestedObject = {
  level1: {
    level2: {
      value: 'deep',
    },
  },
};// ✅ Good: Always use parentheses
const add = (a, b) => a + b;
const square = (x) => x * x;
const log = (message) => console.log(message);// ❌ Bad: Double quotes, no semicolons, inconsistent spacing
import React from "react"
import {useState} from "react"
const MyComponent = ({title,description}) => {
  const [count,setCount] = useState(0)
  const handleClick = () => {
    setCount(count+1)
  }
  return (
    <div>
      <h1>{ title }</h1>
      <p>{ description }</p>
      <button onClick={ handleClick }>Count: { count }</button>
    </div>
  )
}
export default MyComponentPrettier will automatically fix these issues when you run npm run format.
This project uses ESLint for code quality. Key rules:
- React Hooks Rules: Enforces rules of hooks
 - React Refresh: Ensures components can be refreshed
 - 
Unused Variables: Variables starting with 
_or uppercase are ignored 
File: eslint.config.js
import js from '@eslint/js';
import globals from 'globals';
import react from 'eslint-plugin-react';
import reactHooks from 'eslint-plugin-react-hooks';
import reactRefresh from 'eslint-plugin-react-refresh';
export default [
  { ignores: ['dist'] },
  {
    files: ['**/*.{js,jsx}'],
    languageOptions: {
      ecmaVersion: 2020,
      globals: globals.browser,
      parserOptions: {
        ecmaVersion: 'latest',
        ecmaFeatures: { jsx: true },
        sourceType: 'module',
      },
    },
    settings: { react: { version: '18.3' } },
    plugins: {
      react,
      'react-hooks': reactHooks,
      'react-refresh': reactRefresh,
    },
    rules: {
      ...js.configs.recommended.rules,
      ...react.configs.recommended.rules,
      ...react.configs['jsx-runtime'].rules,
      ...reactHooks.configs.recommended.rules,
      'react/jsx-no-target-blank': 'off',
      'react-refresh/only-export-components': [
        'warn',
        { allowConstantExport: true },
      ],
      'no-unused-vars': [
        'error',
        {
          argsIgnorePattern: '^_',
          varsIgnorePattern: '^_|^[A-Z]',
        },
      ],
    },
  },
];When you push to the main branch, GitHub Actions will:
- 
Check Formatting - 
npm run format:check - 
Run Linter - 
npm run lint - 
Build Project - 
npm run build - Deploy - Only if all checks pass
 
flowchart TD
    A[Push to main] --> B{Format Check}
    B -->|Pass| C{Lint Check}
    B -->|Fail| D[❌ Block Deployment]
    C -->|Pass| E[Build Project]
    C -->|Fail| D
    E -->|Success| F[Deploy to Firebase]
    E -->|Fail| D
    If your deployment fails due to format or lint errors:
# 1. Pull latest changes
git pull
# 2. Fix formatting
npm run format
# 3. Fix lint errors
npm run lint
# 4. Commit and push
git add .
git commit -m "fix: format and lint errors"
git pushInstall the Prettier extension for automatic formatting on save:
- Install Prettier - Code formatter extension
 - Add to 
.vscode/settings.json: 
{
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnSave": true,
  "[javascript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[javascriptreact]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  }
}- Go to Settings → Languages & Frameworks → JavaScript → Prettier
 - Enable On save
 - Set Prettier package path
 
Install JsPrettier package via Package Control.
Always run npm run format before committing code.
Set up your editor to format on save for seamless formatting.
After formatting, review the changes to understand what was modified.
Avoid disabling Prettier or ESLint rules unless absolutely necessary.
Ensure your editor is set to use LF (Unix) line endings, not CRLF (Windows).
Problem: npm run format:check fails in GitHub Actions
Solution:
# Run locally to see what needs formatting
npm run format:check
# Fix all formatting issues
npm run format
# Commit the changes
git add .
git commit -m "fix: format code"
git pushProblem: Prettier and ESLint give conflicting suggestions
Solution: Prettier handles formatting, ESLint handles code quality. This project is configured to avoid conflicts. If you encounter issues:
- Run Prettier first: 
npm run format - Then run ESLint: 
npm run lint 
Problem: Some files aren't being formatted
Solution: Check .prettierignore to ensure files aren't excluded.
Problem: CRLF vs LF line ending conflicts
Solution:
# Configure Git to use LF
git config --global core.autocrlf input
# Re-format all files
npm run format| Aspect | Tool | Command | 
|---|---|---|
| Formatting | Prettier | npm run format | 
| Format Check | Prettier | npm run format:check | 
| Linting | ESLint | npm run lint | 
| Auto-fix Lint | ESLint | npm run lint -- --fix | 
- GitHub Actions - CI/CD setup with format/lint checks
 - Development Workflow - Daily development practices
 - Setup Guide - Initial project setup
 
Next: GitHub Actions →
Firebase React Template | Made with ❤️ | GitHub | Report Issues
Getting Started
Configuration
Advanced Topics
Deployment
- React 19
 - Vite
 - Firebase 12
 - Redux Toolkit
 - React Router