API
Recommended
★★★★☆ StableThe recommended rules, how selector keys are resolved, and the styling prop setting.
@plumeria/eslint-plugin is the ESLint plugin for Plumeria.
Installation
pnpm i -D @plumeria/eslint-pluginUsage
import plumeria from '@plumeria/eslint-plugin';
export default [plumeria.configs.recommended];no-invalid-selector, validate-pseudos, and validate-at-rules also check selectors that are not written as string literals. A computed key is followed back to where it is declared, the same way under ESLint and plumeria-lint, with no type information involved:
import * as css from '@plumeria/core';
import { breakpoints } from './tokens';
const hover = ':hover' as const;
export const styles = css.create({
link: {
[hover]: { color: 'teal' },
[breakpoints.md]: { fontSize: 18 },
},
});A key resolves when it is a const holding a string, a member of a const object or a css.createStatic object, or an import of one of these. as const, satisfies, and type annotations make no difference. A key the rules cannot resolve, such as a let or a function parameter, is skipped.
sort-properties reads a computed key the same way, and sorts one that holds an at-rule with the other at-rules, after the pseudo-classes. no-combinator checks a css.createStatic value only when it starts with : or [, the ones that become a selector when used as a key, so a shadow or a font stack is not reported.
Rules
recommended turns on every rule below. Each one is prefixed with @plumeria/.
| Rule | Level | Reports |
|---|---|---|
custom-props-require-import | error | a style passed through a prop other than the styling prop in a file that does not import @plumeria/core |
expand-border-shorthands | warn | a border shorthand that bundles a width, a style and a color; fixable |
no-combinator | error | >, +, ~ and the descendant combinator outside a functional pseudo-class |
no-destructure | error | destructuring the Plumeria API |
no-inline-object | error | an inline object on the styling prop or in css.use() |
no-inner-call | error | an API call inside a function |
no-invalid-selector | error | a selector or nesting order the compiler cannot place |
no-mixed-styling-props | error | the styling prop on an element that also has className or style |
no-mutable-binding | warn | a let or var in a style definition |
no-order-dependent-overlap | warn | two declarations in one style that only source order can rank |
no-style-prop-relay | error | a style prop a component only passes on |
no-unknown-css-properties | error | a property CSS does not have |
no-unused-keys | warn | a key nothing in the same component file reads |
no-unresolved-composition | warn | a css.use() result combined with other class names |
sort-properties | warn | properties out of the recommended order; fixable |
format-properties | warn | a style written on one line, or with empty lines between its properties; fixable |
validate-values | warn | a value the property does not accept |
validate-pseudos | warn | a misspelled or malformed pseudo-class or pseudo-element |
validate-at-rules | warn | an at-rule other than @media, @container, @supports and @starting-style |
Three more rules ship with the plugin and stay off until you ask for them. They do not report a defect; they remove the room for one. See Optional rules.
Configuring the styling prop
custom-props-require-import, no-inline-object, no-mixed-styling-props, no-style-prop-relay and no-unresolved-composition need to know which JSX prop carries styles. It is sx unless you changed it, so most projects configure nothing.
If you did rename it — via styleProp on withPlumeria or on the unplugin options — tell the plugin the same name. The lint the bundler plugins run in the build is given that name already. plumeria-lint takes it with --style-prop, or reads it from the settings below when ESLint is installed. ESLint cannot read it from your bundler config, so set it once in settings and every rule picks it up:
import plumeria from '@plumeria/eslint-plugin';
export default [
plumeria.configs.recommended,
{
settings: {
plumeria: { styleProp: 'classStyle' },
},
},
];A single rule can override that if you need it to:
{
rules: {
'@plumeria/no-mixed-styling-props': ['error', { styleProp: 'classStyle' }],
},
}The name must match whatever the loader or unplugin was given. If they disagree, the lint rules report against a prop the compiler never transforms.