API

Recommended

★★★★☆ Stable

The recommended rules, how selector keys are resolved, and the styling prop setting.

@plumeria/eslint-plugin is the ESLint plugin for Plumeria.

Installation

Terminal
pnpm i -D @plumeria/eslint-plugin

Usage

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/.

RuleLevelReports
custom-props-require-importerrora style passed through a prop other than the styling prop in a file that does not import @plumeria/core
expand-border-shorthandswarna border shorthand that bundles a width, a style and a color; fixable
no-combinatorerror>, +, ~ and the descendant combinator outside a functional pseudo-class
no-destructureerrordestructuring the Plumeria API
no-inline-objecterroran inline object on the styling prop or in css.use()
no-inner-callerroran API call inside a function
no-invalid-selectorerrora selector or nesting order the compiler cannot place
no-mixed-styling-propserrorthe styling prop on an element that also has className or style
no-mutable-bindingwarna let or var in a style definition
no-order-dependent-overlapwarntwo declarations in one style that only source order can rank
no-style-prop-relayerrora style prop a component only passes on
no-unknown-css-propertieserrora property CSS does not have
no-unused-keyswarna key nothing in the same component file reads
no-unresolved-compositionwarna css.use() result combined with other class names
sort-propertieswarnproperties out of the recommended order; fixable
format-propertieswarna style written on one line, or with empty lines between its properties; fixable
validate-valueswarna value the property does not accept
validate-pseudoswarna misspelled or malformed pseudo-class or pseudo-element
validate-at-ruleswarnan 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.

Edit on GitHub