/**
 * Stylelint configuration.
 *
 * Moved from .stylelintrc.json so the rules can carry the reasoning that
 * explains them — several here exist to accommodate Tailwind v4, and a JSON
 * file cannot say so.
 *
 * stylelint stays on 16.x deliberately: @wordpress/stylelint-config@24 peers
 * `stylelint: ^16.8.2`, so moving to 17 would break the dependency graph for
 * no gain. Revisit when that package widens its range.
 */
export default {
	extends: [
		'@wordpress/stylelint-config/scss',
		'stylelint-config-recess-order',
		'stylelint-config-tailwindcss',
	],

	ignoreFiles: [
		'build/**',
		'node_modules/**',
		'vendor/**',
		'**/*.min.css',
	],

	rules: {
		'at-rule-empty-line-before': [
			'always',
			{
				except: [ 'blockless-after-same-name-blockless', 'first-nested' ],
				ignore: [ 'after-comment' ],
				ignoreAtRules: [ 'else' ],
			},
		],

		'declaration-property-unit-allowed-list': {
			'line-height': [],
		},

		'font-weight-notation': null,
		'no-descending-specificity': null,

		'scss/at-extend-no-missing-placeholder': null,
		'scss/at-function-pattern': '^[a-z]([a-z0-9-]+)*$',
		'scss/at-mixin-pattern': '^[a-z]([a-z0-9-]+)*$',
		'scss/dollar-variable-pattern': '^[a-z]([a-z0-9-]+)*$',
		'scss/percent-placeholder-pattern': '^[a-z]([a-z0-9-]+)*$',

		// Tailwind's at-rules are not part of the CSS grammar stylelint knows.
		'scss/at-rule-no-unknown': [
			true,
			{
				ignoreAtRules: [
					'source',
					'theme',
					'tailwind',
					'apply',
					'variants',
					'responsive',
					'screen',
					'layer',
					'config',
					'utility',
					'custom-variant',
					'plugin',
				],
			},
		],

		'scss/selector-no-redundant-nesting-selector': true,

		'selector-class-pattern': [
			'^[a-z]([a-z0-9-]+)*(__([a-z0-9]+-?)+)?(--([a-z0-9]+-?)+){0,2}$|^warranty(-[a-z0-9]+)*$',
			{
				message: "Class names should follow BEM methodology or use the 'warranty-' prefix",
			},
		],

		'value-keyword-case': [
			'lower',
			{
				ignoreProperties: [ '/font-family/' ],
			},
		],
	},
};
