How criteo/eslint-plugin-criteo works
Project type and purpose
• This is an open-source ESLint plugin (named eslint-plugin-criteo).
• Its purpose is to provide a curated set of linting rules, configs, and a helper (buildConfig) for Angular (and soon React) projects, enforcing Criteo’s coding conventions.
File structure
• Top level:
• package.json / package-lock.json (metadata, dependencies)
• .gitignore, .npmrc, LICENSE, CHANGELOG.md (standard project files)
• lib/ (the heart of the plugin)
• In lib/:
• index.js – plugin entry point, exports rules, configs, and the buildConfig helper
• configs/ – JavaScript modules defining named configurations (recommended, recommendedAngularApp, etc.)
• rules/ – individual rule implementations (cypress-no-force.js, filename.js, etc.)
• utils.js – shared utilities used by rule implementations
README for additional insights
• Lists the configurations exposed (recommendedAngularApp, recommendedAngularTemplate, recommended, etc.)
• Describes how the buildConfig() helper flattens and merges nested configurations
• Details each custom rule’s intent and configuration options
• Shows usage patterns for importing the plugin in an ESLint config
Main components
a. ESLint Core Engine
• Represents the ESLint CLI or API that loads plugins and runs lint passes.
b. Plugin Entry Point (lib/index.js)
• Exports:
• Rules Registry – maps rule names to rule definitions from lib/rules/
• Configs Registry – maps config names to rule-sets from lib/configs/
• buildConfig Helper – function to merge and override configs
c. **Rule Implementation Modules (lib/rules/*.js)**
• Each module exports a Rule object that ESLint invokes for AST checks.
• Use shared functions from lib/utils.js.
d. **Config Definition Modules (lib/configs/*.js)**
• Arrays of ESLint settings, enabling internal and external rules.
• Some configs import external plugin configs (e.g., @typescript-eslint, angular-eslint).
e. Utility Module (lib/utils.js)
• Provides helper functions for rule authors (e.g., file-name parsing).
f. External Plugins & Shared Rules
• External dependencies listed in package.json (e.g., @typescript-eslint, eslint-plugin-cypress).
• Config modules include or extend external rule sets.
g. Consumer Project
• An Angular (or React) codebase that installs this plugin and references its exported configs in its ESLint pipeline.
Relationships and interactions
• ESLint Core → loads → Plugin Entry Point
• Plugin Entry → exposes → Rules Registry & Configs Registry ↔ uses ↔ Rule Modules, Config Modules, Utils
• Config Modules → reference → External Plugin Configs / Rules
• Consumer Project → invokes → ESLint Core → which applies → Selected Plugin Config → running → Rules
Architectural patterns and design principles
• Modularization: each rule and config lives in its own file to isolate concerns.
• Registry Pattern: index.js formats exports as two registries (rules and configs) for ESLint to consume.
• Extensibility: buildConfig() helper allows merging and overriding default settings.
• Dependency Injection: config modules declare external plugins centrally, so updates are localized.
Diagramming recommendations
• Core Plugin (entry, utils)
• Rules
• Configs
• External Plugins
• Consumer Project / ESLint Core
• From ESLint Core → Plugin Entry
• From Plugin Entry → Rules & Configs
• From Configs → External Plugins
• From Consumer Project → ESLint Core
• The plugin’s internal structure (modules and registries)
• How it ties into ESLint’s plugin architecture
• Where custom logic and policy definitions reside
• How external rule sets are incorporated
• The consumer’s role in invoking the plugin through ESLint