This document outlines the coding standards and formatting guidelines for the Node.js website project.
- Commit Guidelines
- Pre-commit Hooks
- CSS Guidelines
- JavaScript/TypeScript Guidelines
- File Naming Conventions
- Linting and Formatting
- Code Organization
- Documentation Standards
- Performance Guidelines
This project follows the Conventional Commits specification.
- Commit messages must include a "type" as described in Conventional Commits
- Commit messages must be written in lowercase, except proper nouns
- Commit messages must not end with a period
.
Commits should be signed. You can read more about Commit Signing in the GitHub documentation.
✅ Good commit messages:
feat: add new component for download statistics
fix: resolve navigation menu accessibility issue
docs: update contributing guidelines
❌ Bad commit messages:
update stuff
Fixed bug.
added new feature
This project uses Husky for Git pre-commit hooks to ensure code quality standards are met before commits.
We use PostCSS and Tailwind CSS for styling. All component styles should be written in CSS Modules.
- Use camelCase for defining CSS classes
- Use Tailwind's
@applydirective to apply utility classes - Define one Tailwind utility class per line for better readability
- Avoid plain CSS styles and tokens - use Tailwind utilities instead
- Only write CSS within CSS Modules, avoid inline styles in JavaScript
- Refer to Tailwind's documentation for more details
.myComponent {
@apply flex
flex-col
items-center
justify-center
rounded-lg
bg-white
p-4
shadow-md;
}
.componentTitle {
@apply mb-4
text-2xl
font-bold
text-gray-900;
}- Avoid importing
Reactdirectly - only import specific modules you need - Use
import typefor type-only imports - Prefer named imports over default imports where possible
- Use
FCtype from React for component definitions - Use
FC<PropsWithChildren<MyComponentProps>>when using children prop - Prefix prop types with the component name
- Always use default exports for React components
- Avoid direct DOM/Web API access in components - use hooks or utilities instead
- CSS imports should always be the last import in the file
import type { FC } from 'react';
import styles from './index.module.css';
type MyComponentProps = {
title: string;
isVisible?: boolean;
};
const MyComponent: FC<MyComponentProps> = ({ title, isVisible = true }) => {
if (!isVisible) {
return null;
}
return (
<div className={styles.myComponent}>
<h2 className={styles.componentTitle}>{title}</h2>
</div>
);
};
export default MyComponent;- Component folders:
PascalCase - Component files:
index.tsx(orPascalCase.tsxif a subdirectory is not needed) - Style files:
index.module.css - Test files:
__tests__/index.test.mjs - Story files:
index.stories.tsx
- Use
kebab-casefor most file names (i.e. documentation) - Use
camelCasefor utility functions and configuration files - Use
PascalCaseonly for React components
Run these commands to ensure your code meets our standards:
pnpm format # Formats and fixes lints for entire codebase
pnpm lint # Run linter for all files
pnpm lint:fix # Attempt to fix linting errors
pnpm prettier # Run prettier for JavaScript files
pnpm prettier:fix # Fix style errorsWe recommend using Visual Studio Code with these extensions:
- Stylelint - CSS linting
- Tailwind CSS IntelliSense - Tailwind autocomplete
- ESLint - JavaScript/TypeScript linting
- Prettier - Code formatting
The repository includes a .vscode directory with recommended settings that will be automatically applied if you use VS Code.
- Keep related files together in component folders
- Use index files for clean imports
- Group similar functionality in dedicated directories
- Follow the established patterns in the codebase
Organize imports in this order:
- Node.js built-in modules
- External library imports (Including
@node-core/*) - Relative imports (
./*,../*,#specifier/) - Type-only imports at the end of each given section
import { readFile } from 'node:fs/promises';
import { SomeComponent } from '@node-core/ui-components/Common/SomeComponent';
import type { FC } from 'react';
import { myHook } from '../hooks/myHook';
import type { MyComponentProps } from './types';- Use JSDoc comments for complex functions and utilities
- Document component props with TypeScript interfaces
- Include examples in Storybook for UI components
- Keep README files updated for significant changes
- Minimize bundle size by importing only what you need
- Use dynamic imports for large components when appropriate
- Optimize images and assets
- Follow React best practices for rendering performance