103 lines
4 KiB
TypeScript
103 lines
4 KiB
TypeScript
import Stylelint from "stylelint";
|
|
// @ts-expect-error -- La dépendance ne dispose pas de types.
|
|
import { propertyGroups } from "stylelint-config-clean-order";
|
|
|
|
// Cérémonie nécessaire au vue de l'absence de types de stylelint-config-clean-order.
|
|
type GroupesPropriétés = ReadonlyArray<ReadonlyArray<string>>;
|
|
|
|
type OrdrePropriétés = Readonly<{
|
|
emptyLineBefore: string;
|
|
noEmptyLineBetween: boolean;
|
|
properties: ReadonlyArray<string>;
|
|
}>;
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Impossible de connaître à l'avance la forme d'une Règle.
|
|
type Règles = Record<string, Stylelint.ConfigRuleSettings<any, object>>;
|
|
const ordrePropriétés: ReadonlyArray<OrdrePropriétés> = (propertyGroups as GroupesPropriétés).map(
|
|
(propriétés: ReadonlyArray<string>): OrdrePropriétés => ({
|
|
emptyLineBefore: "never",
|
|
noEmptyLineBetween: true,
|
|
properties: propriétés,
|
|
}),
|
|
);
|
|
|
|
/** Règles liées à l'usage de propriétés de couleur. */
|
|
const règlesCouleur: Règles = {
|
|
/**
|
|
* Force l'utilisation de notations avec canal alpha pour les couleurs.
|
|
*
|
|
* @link [color-function-alias-notation](https://stylelint.io/user-guide/rules/color-function-alias-notation)
|
|
*/
|
|
"color-function-alias-notation": "with-alpha",
|
|
/**
|
|
* Force l'utilisation de notations modernes pour les couleurs.
|
|
*
|
|
* @link [color-function-notation](https://stylelint.io/user-guide/rules/color-@function-notation)
|
|
*/
|
|
"color-function-notation": "modern",
|
|
/**
|
|
* Interdit l'usage de notations hexadécimales pour les couleurs.
|
|
*
|
|
* @link [color-no-hex](https://stylelint.io/user-guide/rules/color-no-hex)
|
|
*/
|
|
"color-no-hex": true,
|
|
/**
|
|
* Émet une erreur si une couleur dépasse l'espace de couleurs sRGB sans être enveloppée dans une requête média pour
|
|
* le support de l'espace de couleur P3.
|
|
*
|
|
* @link [color-no-out-gamut-range](https://github.com/fpetrakov/stylelint-gamut/blob/HEAD/src/README.md)
|
|
*/
|
|
"gamut/color-no-out-gamut-range": true,
|
|
};
|
|
|
|
export const configCss: Readonly<Stylelint.Config> = {
|
|
allowEmptyInput: false,
|
|
cache: true,
|
|
extends: ["stylelint-config-clean-order", "stylelint-config-standard", "stylelint-config-html"],
|
|
ignoreFiles: ["node_modules/**", "dist/**", "**/reset.css", "**/*.min.css"],
|
|
plugins: [
|
|
/** @link [stylelint-gamut](https://github.com/fpetrakov/stylelint-gamut) */
|
|
"stylelint-gamut",
|
|
"stylelint-no-unresolved-module",
|
|
"stylelint-no-unsupported-browser-features",
|
|
"stylelint-plugin-logical-css",
|
|
"stylelint-value-no-unknown-custom-properties",
|
|
],
|
|
reportDescriptionlessDisables: true,
|
|
reportInvalidScopeDisables: true,
|
|
reportNeedlessDisables: true,
|
|
reportUnscopedDisables: true,
|
|
rules: {
|
|
...règlesCouleur,
|
|
/**
|
|
* Impose un motif pour le nom des propriétés personnalisées. Ici **désactivé** pour permettre l'usage d'accents.
|
|
*
|
|
* @link [custom-property-pattern](https://stylelint.io/user-guide/rules/custom-property-pattern).
|
|
*/
|
|
"custom-property-pattern": null,
|
|
"declaration-block-no-redundant-longhand-properties": true,
|
|
"declaration-block-no-shorthand-property-overrides": true,
|
|
"font-weight-notation": "numeric",
|
|
"function-disallowed-list": ["rgba", "hsla", "rgb", "hsl"],
|
|
"no-duplicate-selectors": [true, { disallowInList: false }],
|
|
"order/properties-order": [ordrePropriétés, { severity: "error", unspecified: "bottomAlphabetical" }],
|
|
"plugin/no-unresolved-module": true,
|
|
"plugin/no-unsupported-browser-features": [
|
|
true,
|
|
{
|
|
ignore: [
|
|
// Incompatible avec Safari iOS mais ne change rien.
|
|
"css-selection",
|
|
// L'imbrication est prise en charge depuis au moins 2 ans.
|
|
"css-nesting",
|
|
// Safari...
|
|
"css-media-range-syntax",
|
|
],
|
|
ignorePartialSupport: true,
|
|
severity: "warning",
|
|
},
|
|
],
|
|
"plugin/use-logical-properties-and-values": [true, { severity: "warning" }],
|
|
"plugin/use-logical-units": [true, { severity: "warning" }],
|
|
"unit-no-unknown": true,
|
|
},
|
|
};
|