This document outlines the code quality standards and best practices for the EU Parliament Monitor project.
- Overview
- Linting
- Code Formatting
- JSDoc Documentation
- Complexity Guidelines
- Security Standards
- Pre-commit Hooks
The EU Parliament Monitor project maintains high code quality standards through automated tooling and best practices. All code must pass linting, formatting, and documentation checks before being merged.
We use ESLint with multiple plugins to enforce code quality:
@eslint/js- ESLint recommended ruleseslint-plugin-security- Security vulnerability detectioneslint-plugin-sonarjs- Code smell and complexity detectioneslint-plugin-jsdoc- JSDoc documentation validation
# Check for issues
npm run lint
# Auto-fix issues where possible
npm run lint:fix
# Generate JSON report
npm run lint:reporteqeqeq: Always use===and!==instead of==and!=prefer-const: Useconstfor variables that are never reassignedno-eval: Never useeval()ornew Function()require-await: Async functions must useawait
security/detect-unsafe-regex: Prevent ReDoS vulnerabilities (ERROR)security/detect-eval-with-expression: Prevent eval-like code (ERROR)security/detect-object-injection: Warn about potential object injection (WARNING - false positives acceptable for safe code)
sonarjs/cognitive-complexity: Max complexity of 15 per functionsonarjs/no-duplicate-string: Max 3 occurrences of same string literalsonarjs/no-identical-functions: Prevent duplicate function implementationssonarjs/prefer-immediate-return: Return directly instead of storing in variable
We use Prettier for consistent code formatting:
- Print Width: 100 characters
- Tab Width: 2 spaces
- Quotes: Single quotes for strings
- Semicolons: Always required
- Trailing Commas: ES5 style
- Line Ending: LF (Unix style)
# Format all files
npm run format
# Check formatting without making changes
npm run format:checkAll exported functions must have complete JSDoc documentation.
@param- Every parameter with type, name, and description@returns- Return value with type and description@throws- Any exceptions that may be thrown
/**
* Generate complete HTML for a news article
* @param {object} options - Article options
* @param {string} options.title - Article title
* @returns {string} Complete HTML document
*/
export function generateArticleHTML(options) {
// implementation
}Maximum: 15 per function
- Extract methods: Break large functions into smaller ones
- Use early returns: Exit early instead of nesting
- Strategy pattern: Use objects/maps instead of large switch statements
- Guard clauses: Validate inputs at the start
eval()andnew Function(): Never use dynamic code evaluation- Unsafe regex: Avoid catastrophic backtracking patterns
- Hardcoded secrets: Never commit credentials or API keys
We use Husky and lint-staged to enforce quality gates before commits.
On every commit, the following are automatically run on staged files:
- ESLint with auto-fix
- Prettier formatting
- htmlhint for HTML files
All pull requests must pass these checks:
- ESLint: Zero errors (warnings acceptable)
- Prettier: All code must be formatted
- HTML validation: Pass htmlhint checks
- npm audit: No high/critical vulnerabilities
Last Updated: 2026-02-16 Version: 1.0.0