@mrzr/eslint-plugin-component-ownership
A component owns its file and its look.
Two ESLint rules: one component per file, and no visual Tailwind classes outside the component that owns the look. Layout and sizing classes stay allowed.
npm install --save-dev @mrzr/eslint-plugin-component-ownershipimport ownership from "@mrzr/eslint-plugin-component-ownership";
import tseslint from "typescript-eslint";
export default [
{
files: ["**/*.tsx"],
languageOptions: {
parser: tseslint.parser,
parserOptions: { ecmaFeatures: { jsx: true } },
},
plugins: { ownership },
},
{
// Screens arrange components; the look belongs to the components in core.
files: ["src/features/**/*.tsx"],
rules: {
"ownership/one-component-per-file": "error",
"ownership/no-external-styling": "error",
},
},
];src/features/profile.tsx
2:25 error `rounded-full` styles an element from outside a component. Move it into the component's variants, or make the styled element a component ownership/no-external-styling
5:17 error `Profile` is a second component in this file. Move it into its own file (one component per file) ownership/one-component-per-file
✖ 5 problems (5 errors, 0 warnings)The rules are on for src/features and off for src/core, where the components that own the look live.
What it does
one-component-per-file
A module defines one component. A second one is reported where it is declared.
no-external-styling
Colour, type, border, radius, shadow, inner spacing and motion classes are reported outside their component.
Scoped by folder
Turn the rules on where screens arrange components, and off where the components live.
Documentation
Everything is documented.
More packages