textmachine/frontend/stylelint.config.js

49 lines
2.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Гейт «одно место для цвета и размера», половина в CSS (STACK_DECISIONS §3).
// TSX-половина — в eslint.config.js.
//
// Двухслойно: запрет литеральных цветов ловит их в ЛЮБОМ свойстве, включая сокращённые
// записи вроде `border: 1px solid #fff`, а allowed-list добавляет свойства, где литерал
// не цвет (`font-size`, `z-index`). reportDisables делает ошибкой и попытку отключить
// правило комментарием.
const gate = { reportDisables: true };
const token = '/^var\\(--/';
const colorValues = [token, 'inherit', 'currentColor', 'transparent'];
export default {
extends: ['stylelint-config-standard'],
rules: {
'color-no-hex': [true, gate],
'color-named': ['never', gate],
'function-disallowed-list': [
['rgb', 'rgba', 'hsl', 'hsla', 'hwb', 'lab', 'lch', 'oklab', 'oklch'],
gate,
],
'declaration-property-value-allowed-list': [
{
color: colorValues,
'background-color': colorValues,
'border-color': colorValues,
background: [...colorValues, 'none'],
fill: [...colorValues, 'none'],
stroke: [...colorValues, 'none'],
'font-size': [token, 'inherit'],
'z-index': [token],
},
{ ...gate, message: 'Значение только из токена: var(--...) из src/tokens/tokens.css' },
],
// CSS Modules читаются из TS как styles.panelHeader, поэтому классы camelCase.
'selector-class-pattern': ['^[a-z][a-zA-Z0-9]*$', { message: 'Имя класса — camelCase' }],
},
overrides: [
{
// Единственное место, где литеральный цвет легален: сами токены.
files: ['src/tokens/tokens.css'],
rules: {
'color-no-hex': null,
'color-named': null,
'function-disallowed-list': null,
'declaration-property-value-allowed-list': null,
},
},
],
};