Skip to content

Smart Smoker V2 - Linting & Formatting Implementation Guide

🎯 What Was Implemented

This implementation provides comprehensive linting and formatting for the Smart Smoker V2 monorepo while respecting its existing structure and best practices.

✅ Completed Setup

  1. Root-Level Configuration
  2. .eslintrc.js - Workspace-wide ESLint rules
  3. .prettierrc - Unified formatting configuration
  4. .prettierignore - Proper ignore patterns
  5. .vscode/ - Workspace settings and recommended extensions

  6. Enhanced Package Configurations

  7. Added linting to packages/TemperatureChart
  8. Updated all React apps with proper ESLint + Prettier
  9. Maintained existing NestJS app configurations
  10. Added consistent script names across all packages

  11. Comprehensive Scripts

  12. Root-level formatting and linting commands
  13. App-specific safe linting with error handling
  14. Pre-commit hooks support
  15. CI/CD friendly commands

🚀 Usage Guide

# 1. Format entire workspace (always works)
npm run format

# 2. Check formatting without changes
npm run format:check  

# 3. Run all app linting (safe with error handling)
npm run lint:apps

# 4. Fix linting issues across all apps
npm run lint:apps:fix

# 5. Quality check before commits
npm run check

App-Specific Development

# Backend (NestJS) - Full TypeScript linting
cd apps/backend
npm run lint        # ESLint with auto-fix
npm run format      # Prettier formatting

# Device Service (NestJS) - Full TypeScript linting  
cd apps/device-service
npm run lint        # ESLint with auto-fix
npm run format      # Prettier formatting

# Frontend (React) - React + TypeScript linting
cd apps/frontend
npm run lint        # ESLint with React rules
npm run format      # Prettier formatting

# Smoker App (Electron + React) - React + TypeScript linting
cd apps/smoker
npm run lint        # ESLint with React rules  
npm run format      # Prettier formatting

# TemperatureChart Package - React + TypeScript linting
cd packages/TemperatureChart
npm run lint        # ESLint with React rules
npm run format      # Prettier formatting

CI/CD Integration Commands

# For GitHub Actions - fail on issues
npm run check                    # Format check + app linting
npm run format:check            # Just formatting check
npm run lint:apps               # All apps with safe error handling

# Pre-commit - auto-fix and check
npm run fix                     # Auto-fix formatting + linting

📋 Code Quality Rules Implemented

TypeScript Rules (Backend/Device Service)

  • ✅ Explicit function return types (NestJS only)
  • ✅ Explicit module boundary types (NestJS only)
  • ✅ No unused variables/imports
  • ✅ Prefer const over let
  • ✅ Object shorthand syntax
  • ✅ Template literals over string concatenation

React Rules (Frontend/Smoker/Packages)

  • ✅ Functional components only (per best practices)
  • ✅ Arrow function component definitions
  • ✅ React Hooks rules enforcement
  • ✅ JSX accessibility best practices
  • ✅ No React.Fragment imports (React 17+)
  • ✅ Testing Library best practices

Formatting Rules (All Files)

  • ✅ Single quotes for strings
  • ✅ Trailing commas (ES5 style)
  • ✅ 100 character line length
  • ✅ 2-space indentation
  • ✅ Semicolons required
  • ✅ Unix line endings (LF)

🔧 Configuration Details

ESLint Configuration (.eslintrc.js)

  • Backend/Device Service: TypeScript + NestJS rules
  • Frontend/Smoker: React + TypeScript + Accessibility rules
  • Packages: React + TypeScript (relaxed rules)
  • JavaScript Files: Basic ES2022 rules

Prettier Configuration (.prettierrc)

  • Consistent across all file types
  • Special rules for Markdown (80 chars) and JSON (120 chars)
  • Ignores build artifacts, dependencies, and generated files

VS Code Integration

  • Format on save enabled
  • Auto-fix ESLint issues on save
  • Recommended extensions for the team
  • Proper working directories for monorepo

âš¡ Current Code Quality Status

After implementation, the linting found these issues in your codebase:

Backend (23 warnings)

  • Mostly unused imports and variables in service specs
  • Some controller parameters not being used
  • Clean code with good structure ✅

Frontend (148 issues)

  • Testing Library rule violations (using act unnecessarily)
  • Multiple assertions in waitFor callbacks
  • Some unused imports
  • Direct DOM access in tests

Smoker App (93 issues)

  • Similar Testing Library issues
  • React Hooks dependency warnings
  • Some unused variables
  • WiFi component test improvements needed

Device Service (12 issues)

  • Some TypeScript strict mode violations
  • Require statements instead of imports
  • Unused variables in tests

🎯 Next Steps & Recommendations

1. Immediate Actions

# Fix all formatting issues
npm run format

# Review and fix critical linting issues
npm run lint:apps:fix

2. Team Adoption

  • Install recommended VS Code extensions
  • Use npm run check before commits
  • Run app-specific linting during development
  • Address linting warnings incrementally

3. CI/CD Integration

Add to your GitHub Actions workflow:

- name: Check Code Quality
  run: |
    npm run bootstrap
    npm run check

4. Incremental Improvement

  • Week 1: Fix unused imports/variables (easy wins)
  • Week 2: Improve Testing Library usage in React apps
  • Week 3: Address TypeScript strict mode issues
  • Week 4: Refactor complex test cases

🚨 Important Notes

  1. Workspace-Level Linting Limitation: Due to TypeScript project reference conflicts in the monorepo, workspace-level TypeScript linting has been disabled. Use app-specific linting for best results.

  2. Backward Compatibility: All existing npm scripts continue to work. New scripts are additive.

  3. Build Process: Linting issues are warnings and don't break builds. Use CI/CD enforcement for strict quality gates.

  4. Performance: App-specific linting is faster and more accurate than workspace-level for this monorepo structure.

📚 Additional Resources

  • ESLint Rules: https://eslint.org/docs/rules/
  • Prettier Configuration: https://prettier.io/docs/en/configuration.html
  • React Testing Library: https://testing-library.com/docs/react-testing-library/intro/
  • TypeScript ESLint: https://typescript-eslint.io/rules/

This implementation provides a solid foundation for maintaining code quality across your Smart Smoker V2 project while being practical for daily development workflows.