Code Formatting
Popcorn Vision uses automated code formatting tools to maintain consistent code style across the project.Prettier Configuration
The project uses Prettier for automatic code formatting with the following configuration:.prettierrc
Prettier uses its default settings with the prettier-plugin-tailwindcss plugin to automatically sort Tailwind CSS classes.
Prettier Default Settings
Since no custom rules are specified, Prettier applies its defaults:- Print Width: 80 characters
- Tab Width: 2 spaces
- Tabs: Spaces (not tabs)
- Semicolons: Always
- Quotes: Double quotes
- Trailing Commas: ES5 (objects, arrays)
- Bracket Spacing: true
- Arrow Function Parentheses: Always
Running Prettier
While not included as an npm script, you can format your code manually:Tip: Configure your code editor to format on save using Prettier. This ensures your code is always properly formatted.
ESLint Configuration
Popcorn Vision uses ESLint with Next.js’s recommended configuration:.eslintrc.json
- React best practices
- React Hooks rules
- Next.js specific optimizations
- Core Web Vitals warnings
- Accessibility rules
Running ESLint
Check your code for issues:File Naming Conventions
Consistent file naming makes the codebase easier to navigate:React Components
-
Component files: PascalCase with
.jsxor.jsextension- ✅
MovieCard.jsx - ✅
SearchBar.jsx - ❌
movie-card.jsx - ❌
search_bar.jsx
- ✅
-
Component directories: PascalCase matching the component name
Next.js App Router Files
-
Pages: Use Next.js conventions (
page.js,layout.js, etc.)page.js- Page componentlayout.js- Layout wrapperloading.js- Loading UIerror.js- Error UInot-found.js- 404 UI
-
Route groups: Use parentheses for organization
(auth)/login/page.js(films)/movie/[id]/page.js
Utilities and Helpers
- Utility files: camelCase with
.jsextension- ✅
formatDate.js - ✅
apiHelpers.js - ❌
FormatDate.js - ❌
api-helpers.js
- ✅
Configuration Files
- Use lowercase with hyphens or dots:
- ✅
next.config.mjs - ✅
tailwind.config.js - ✅
.eslintrc.json
- ✅
Component Organization
Follow these patterns when creating components:Component Structure
Component Best Practices
- One component per file - Each component should be in its own file
- Default export - Use default exports for page components
- Named exports - Use named exports for utility components
- PropTypes or TypeScript - Document expected props (consider adding TypeScript)
- Destructure props - Destructure props in function parameters
Import Ordering
Organize imports in the following order:Use absolute imports with the
@/ alias (configured in jsconfig.json) instead of relative paths when possible.Tailwind CSS Guidelines
Class Organization
The prettier-plugin-tailwindcss automatically sorts classes in the recommended order:Custom Utilities
When using custom Tailwind utilities defined intailwind.config.js:
DaisyUI Components
Use DaisyUI component classes when applicable:JavaScript/React Best Practices
Use Modern JavaScript
- Arrow functions for functional components
- Destructuring for props and state
- Template literals for string concatenation
- Optional chaining (
?.) for safe property access - Nullish coalescing (
??) for default values
Component Patterns
- Functional components - Use function components with hooks
- Custom hooks - Extract reusable logic into custom hooks
- Composition - Prefer composition over prop drilling
- Memoization - Use
useMemoanduseCallbackfor expensive operations
Naming Conventions
Comments and Documentation
When to Comment
- Complex logic - Explain why, not what
- API integrations - Document expected responses
- Workarounds - Explain temporary solutions
- TODOs - Mark items for future improvement
JSDoc for Complex Functions
Consider adding JSDoc comments for complex utility functions:EditorConfig
Consider adding an.editorconfig file for consistent editor settings:
.editorconfig
Next Steps
- Review the Development Guide for setup instructions
- Read the Contributing Guidelines for the PR process
- Set up your editor with Prettier and ESLint plugins