Fix Design System Violations with ESLint
Job to be done: Identify and fix design system violations in code using a linter
🇳🇬 Ways to use this in Nigeria
Ideas to get you started, adapt to your situation.
- Student
Fix design system violations in your React Native app code for a school project using ESLint and a plugin.
- 9-5 employee
Automatically catch design system errors like raw color usage in your company's React codebase with ESLint.
What you’ll get
You will set up ESLint with a specific plugin to automatically find and flag violations of your design system’s rules within your code. This helps catch issues like using raw color values instead of design tokens, or missing styling hooks, preventing common errors and improving code consistency.
Tools you need
- ESLint (free): A popular tool for identifying and reporting on patterns in JavaScript and TypeScript code, helping to make code more consistent and free of errors.
- eslint-plugin-react-features (free): A plugin for ESLint that adds rules specifically designed to enforce best practices related to React components and design systems.
Steps
-
Install the ESLint plugin: Open your project’s terminal and install the necessary plugin as a development dependency.
npm i -D eslint-plugin-react-featuresYou should see the package added to your
devDependenciesin yourpackage.jsonfile and the installation process complete without errors. -
Configure ESLint: Update your ESLint configuration file (e.g.,
eslint.config.mjsor.eslintrc.js) to include the new plugin and enable specific rules. The author useseslint.config.mjs.import reactFeatures from "eslint-plugin-react-features"; export default [ { files: ["**/*.tsx"], plugins: { "react-features": reactFeatures, }, rules: { "react-features/no-raw-color-literal": "error", "react-features/no-arbitrary-token-class": "error", "react-features/require-data-slot": "warn", "react-features/no-inline-style": "warn", }, }, ];Your ESLint configuration file should now include the plugin and the specified rules. The author recommends starting
require-data-slotandno-inline-styleat"warn"to ease adoption. -
Run ESLint: Execute ESLint from your terminal to scan your project’s
.tsxfiles for violations based on the new rules.npx eslint .You should see a report in your terminal listing any violations found, categorized by severity (error or warning), and indicating the files and lines where they occur.
Original source
This workflow is based on an article by Ofri Peretz, shared on the DEV Community platform. The author details their experience using ESLint and a custom plugin to enforce design system rules across their codebase, highlighting how imported components can introduce violations.
Notes & variations
- Free tier viability: Both ESLint and
eslint-plugin-react-featuresare free and open-source, making them fully accessible without cost. - Common mistake: If you are migrating an existing project, running all rules as
"error"from the start can be overwhelming. The author suggests starting with"warn"for rules likerequire-data-slotandno-inline-styleto gradually introduce them. - Tip for better results: For rules like
no-raw-color-literal, ensure your design system’s tokens are correctly configured and accessible as CSS custom properties or Tailwind theme classes. This makes it easier for the linter to identify correct replacements.