Contributing
Thank you for your interest in contributing to eslint-plugin-code-style. This guide covers how to set up the project, understand the codebase, and submit changes.
Getting Started
Clone the repository and install dependencies:
git clone https://github.com/Mohamed-Elhawary/eslint-plugin-code-style.gitcd eslint-plugin-code-stylenpm installBuild the plugin:
npm run buildThe build step uses esbuild to bundle all source files into dist/index.js. You must run the build after making changes before testing.
Project Structure
The plugin is organized into 17 category files under src/rules/. Each file exports one or more rule objects:
eslint-plugin-code-style/├── src/│ ├── rules/│ │ ├── arrays.js│ │ ├── arrow-functions.js│ │ ├── call-expressions.js│ │ ├── classes.js│ │ ├── comments.js│ │ ├── components.js│ │ ├── control-flow.js│ │ ├── functions.js│ │ ├── hooks.js│ │ ├── imports-exports.js│ │ ├── jsx.js│ │ ├── objects.js│ │ ├── react.js│ │ ├── spacing.js│ │ ├── strings.js│ │ ├── typescript.js│ │ └── variables.js│ ├── utils/│ │ └── tailwind.js│ └── index.js├── _tests_/│ ├── v9/│ │ ├── react/│ │ ├── react-ts/│ │ ├── react-tw/│ │ └── react-ts-tw/│ └── v10/│ ├── react/│ ├── react-ts/│ ├── react-tw/│ └── react-ts-tw/├── dist/│ └── index.js├── docs/│ └── website/├── package.json└── esbuild.config.jsKey files
src/index.js— Main entry point. Registers all rules and defines the 4 preset configs.src/rules/*.js— 17 category files containing all 81 rules.src/utils/tailwind.js— Shared utilities for Tailwind-related rules.esbuild.config.js— Build configuration. Bundles to ESM format targeting Node 20.
Rule Implementation Pattern
Every rule follows the standard ESLint rule structure. Here is a simplified example:
1// src/rules/arrays.js2 3const arrayCallbackDestructure = {4 meta: {5 type: "layout",6 docs: {7 description: "Enforce destructured properties on separate lines",8 },9 fixable: "whitespace",10 schema: [],11 },12 create(context) {13 return {14 // AST visitor methods15 CallExpression(node) {16 // Rule logic here17 context.report({18 node,19 message: "Each destructured property should be on its own line",20 fix(fixer) {21 // Auto-fix logic22 },23 });24 },25 };26 },27};Guidelines for new rules
- Place the rule in the appropriate category file under
src/rules/. - Include a
fixableproperty inmetawhenever the fix is safe and deterministic. - Write clear, actionable error messages.
- Add the rule to
src/index.jsin both the plugin rules map and the relevant preset configs. - If the rule is TypeScript-only, only add it to
react-tsandreact-ts-twconfigs.
Testing
The project uses 4 test projects that reference the built plugin via "file:../..". Each project covers a different stack:
| Test Project | Stack | Rules |
|---|---|---|
_tests_/v9/react/ | JavaScript + React | 72 |
_tests_/v9/react-ts/ | TypeScript + React | 81 |
_tests_/v9/react-tw/ | JavaScript + React + Tailwind | 72 |
_tests_/v9/react-ts-tw/ | TypeScript + React + Tailwind | 81 |
To test your changes:
- Run
npm run buildfrom the project root. - Navigate to the appropriate test project and run ESLint:
cd _tests_/v9/react-tsnpx eslint . --fixTest your rule against all 4 projects to ensure it works correctly across stacks.
Build
The plugin uses esbuild to bundle all source files into a single dist/index.js file (~269 KB minified). The build configuration:
- Format: ESM
- Platform: Node
- Target: Node 20
- Injects
__VERSION__at build time frompackage.json
npm run buildCommit Conventions
Follow the conventional commit format for commit messages:
feat:— New rule or featurefix:— Bug fix in an existing ruledocs:— Documentation changesrefactor:— Code refactoring without behavior changeschore:— Build, tooling, or dependency updates
Links
Next Steps
- Rules Reference — See existing rules for implementation examples
- Philosophy — Understand the design principles guiding new rules
- Getting Started — Try the plugin in your own project