@alexlit/config-stylelint 63.0.0 → 64.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,17 +1,21 @@
1
+ [![version](https://npmx.dev/api/registry/badge/version/@alexlit/config-stylelint)](https://www.npmjs.com/package/@alexlit/config-stylelint)
2
+ [![downloads](https://npmx.dev/api/registry/badge/downloads/@alexlit/config-stylelint)](https://npmx.dev/package/@alexlit/config-stylelint)
3
+ [![license](https://npmx.dev/api/registry/badge/license/@alexlit/config-stylelint)](LICENSE)
4
+
1
5
  # Stylelint Configuration
2
6
 
3
7
  Готовая конфигурация [Stylelint](https://stylelint.io/) для проверки CSS, SCSS и
4
- Vue-файлов: настроенные правила из популярных stylelint-плагинов — порядок и
8
+ Vue-файлов: настроенные правила из популярных stylelint-плагинов - порядок и
5
9
  синтаксис свойств, доступность, БЭМ, поддержка SCSS и т.д. Вместо того чтобы
6
10
  подключать и настраивать каждый плагин вручную, соберите конфигурацию из готовых
7
11
  проверок.
8
12
 
9
- Проверки модульные: по умолчанию ничего не включено — вы сами перечисляете
13
+ Проверки модульные: по умолчанию ничего не включено - вы сами перечисляете
10
14
  нужные в `defineConfig`.
11
15
 
12
16
  ## Установка
13
17
 
14
- ```sh
18
+ ```bash
15
19
  npm i @alexlit/config-stylelint -D
16
20
  ```
17
21
 
@@ -24,36 +28,38 @@ import { defineConfig, plugins } from '@alexlit/config-stylelint';
24
28
  export default defineConfig([
25
29
  plugins.scss(),
26
30
  plugins.vue(),
31
+
27
32
  plugins.prettier(),
28
33
  ]);
29
34
  ```
30
35
 
31
- Каждый вызов `plugins.*()` — отдельная проверка. Добавьте только то, что нужно
32
- проекту; полный список — в разделе [Проверки](#проверки).
36
+ Каждый вызов `plugins.*()` - отдельная проверка. Добавьте только то, что нужно
37
+ проекту; полный список - в разделе [Проверки](#проверки).
33
38
 
34
- Больше проверок — просто допишите их в массив:
39
+ Больше проверок - просто допишите их в массив:
35
40
 
36
41
  ```js
37
42
  // stylelint.config.js
38
43
  import { defineConfig, plugins } from '@alexlit/config-stylelint';
39
44
 
40
45
  export default defineConfig([
46
+ plugins.a11y(),
47
+ plugins.bem(),
41
48
  plugins.colorFormat(),
42
49
  plugins.declarationBlockNoIgnoredProperties(),
50
+ plugins.gamut(),
43
51
  plugins.highPerformanceAnimation(),
52
+ plugins.logicalCss(),
53
+ plugins.mediaUseCustomMedia(),
44
54
  plugins.noNestedMedia(),
55
+ plugins.noUnresolvedModule(),
56
+ plugins.noUnsupportedBrowserFeatures(),
45
57
  plugins.order(),
46
58
  plugins.scss(),
47
59
  plugins.selectorNoEmpty(),
48
60
  plugins.useNesting(),
49
61
  plugins.vue(),
50
- plugins.a11y(),
51
- plugins.bem(),
52
- plugins.gamut(),
53
- plugins.logicalCss(),
54
- plugins.mediaUseCustomMedia(),
55
- plugins.noUnresolvedModule(),
56
- plugins.noUnsupportedBrowserFeatures(),
62
+
57
63
  plugins.prettier(),
58
64
  ]);
59
65
  ```
@@ -76,9 +82,43 @@ export default defineConfig([
76
82
  ]);
77
83
  ```
78
84
 
85
+ `rules` мержатся поверхностно: настройка одноимённого правила из опций заменяет
86
+ дефолтную целиком.
87
+
88
+ ### Правила для отдельных файлов
89
+
90
+ Чтобы применить правила только к части файлов, используйте `overrides` в опциях
91
+ проверки. Пользовательские overrides добавляются после дефолтных, поэтому
92
+ выигрывают у них:
93
+
94
+ ```js
95
+ // stylelint.config.js
96
+ import { defineConfig, plugins } from '@alexlit/config-stylelint';
97
+
98
+ export default defineConfig([
99
+ plugins.useNesting({
100
+ overrides: [
101
+ { files: ['**/*.vue'], rules: { 'csstools/use-nesting': 'never' } },
102
+ ],
103
+ }),
104
+ ]);
105
+ ```
106
+
107
+ `files` обязателен: Stylelint падает с ошибкой, если в override его нет.
108
+
109
+ ### Приоритет настроек
110
+
111
+ Внутри одной проверки: дефолты → `options.rules` → `options.overrides` (для
112
+ подходящих файлов). Между проверками и вторым аргументом `defineConfig`
113
+ действует тот же порядок: база → проверки по порядку → `options`.
114
+
115
+ Коллекции (`extends`, `ignoreFiles`, `overrides`, `plugins`) дополняются,
116
+ `plugins` дедуплицируются. Остальные поля, например `customSyntax`, заменяются
117
+ значениями из опций.
118
+
79
119
  ### Общие настройки Stylelint
80
120
 
81
- Второй аргумент `defineConfig` — общие опции: собственные правила, файлы для
121
+ Второй аргумент `defineConfig` - общие опции: собственные правила, файлы для
82
122
  игнора и т.д. Он перебивает настройки всех проверок:
83
123
 
84
124
  ```js
@@ -93,30 +133,45 @@ export default defineConfig([plugins.scss(), plugins.vue()], {
93
133
 
94
134
  ## Проверки
95
135
 
96
- | Проверка | Что делает | Плагин |
97
- | ----------------------------------------------- | ---------------------------------------------------- | --------------------------------------------------- |
98
- | `plugins.a11y()` | Проверяет типичные ошибки доступности | `@double-great/stylelint-a11y` |
99
- | `plugins.bem()` | Настраивает линтинг по методологии БЭМ | `@morev/stylelint-plugin` |
100
- | `plugins.colorFormat()` | Нормализует формат цветов (hex → rgb/hsl) | встроенное правило `color-format/format` |
101
- | `plugins.declarationBlockNoIgnoredProperties()` | Запрещает бесполезные свойства в блоке объявлений | `stylelint-declaration-block-no-ignored-properties` |
102
- | `plugins.gamut()` | Проверяет цвета на выход за пределы цветового охвата | `stylelint-gamut` |
103
- | `plugins.highPerformanceAnimation()` | Запрещает анимации, нагружающие рендеринг | `stylelint-high-performance-animation` |
104
- | `plugins.logicalCss()` | Проверяет использование логических CSS-свойств | `stylelint-plugin-logical-css` |
105
- | `plugins.mediaUseCustomMedia()` | Требует использования кастомных медиа-запросов | `stylelint-media-use-custom-media` |
106
- | `plugins.noIndistinguishableColors()` | Запрещает неразличимые цвета | `stylelint-no-indistinguishable-colors` |
107
- | `plugins.noNestedMedia()` | Запрещает вложенные медиа-запросы | `stylelint-no-nested-media` |
108
- | `plugins.noUnresolvedModule()` | Проверяет разрешение импортов | `stylelint-no-unresolved-module` |
109
- | `plugins.noUnsupportedBrowserFeatures()` | Проверяет поддержку CSS-функций целевыми браузерами | `stylelint-no-unsupported-browser-features` |
110
- | `plugins.order()` | Настраивает порядок свойств и селекторов | `stylelint-order` |
111
- | `plugins.prettier()` | Интегрирует Prettier | `stylelint-prettier` |
112
- | `plugins.scss()` | Настраивает линтинг SCSS | `stylelint-scss` |
113
- | `plugins.selectorNoEmpty()` | Запрещает пустые селекторы | `stylelint-selector-no-empty` |
114
- | `plugins.useNesting()` | Требует использования CSS-вложенности | `stylelint-use-nesting` |
115
- | `plugins.vue()` | Подключает поддержку Vue.js SFC | `stylelint-config-recommended-vue` |
136
+ | Проверка | Что делает | Плагин |
137
+ | ----------------------------------------------- | ---------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
138
+ | `plugins.a11y()` | Проверяет типичные ошибки доступности | [`@double-great/stylelint-a11y`](https://github.com/double-great/stylelint-a11y) |
139
+ | `plugins.bem()` | Настраивает линтинг по методологии БЭМ | [`@morev/stylelint-plugin`](https://morevm.github.io/stylelint-plugin/) |
140
+ | `plugins.colorFormat()` | Нормализует формат цветов (hex → rgb/hsl) | встроенное правило `color-format/format` |
141
+ | `plugins.declarationBlockNoIgnoredProperties()` | Запрещает бесполезные свойства в блоке объявлений | [`stylelint-declaration-block-no-ignored-properties`](https://github.com/kristerkari/stylelint-declaration-block-no-ignored-properties) |
142
+ | `plugins.gamut()` | Проверяет цвета на выход за пределы цветового охвата | [`stylelint-gamut`](https://github.com/fpetrakov/stylelint-gamut) |
143
+ | `plugins.highPerformanceAnimation()` | Запрещает анимации, нагружающие рендеринг | [`stylelint-high-performance-animation`](https://github.com/kristerkari/stylelint-high-performance-animation) |
144
+ | `plugins.logicalCss()` | Проверяет использование логических CSS-свойств | [`stylelint-plugin-logical-css`](https://github.com/yuschick/stylelint-plugin-logical-css) |
145
+ | `plugins.mediaUseCustomMedia()` | Требует использования кастомных медиа-запросов | [`stylelint-media-use-custom-media`](https://github.com/csstools/stylelint-media-use-custom-media) |
146
+ | `plugins.noIndistinguishableColors()` | Запрещает неразличимые цвета | [`stylelint-no-indistinguishable-colors`](https://github.com/ierhyna/stylelint-no-indistinguishable-colors) |
147
+ | `plugins.noNestedMedia()` | Запрещает вложенные медиа-запросы | [`stylelint-no-nested-media`](https://github.com/dkrnl/stylelint-no-nested-media) |
148
+ | `plugins.noUnresolvedModule()` | Проверяет разрешение импортов | [`stylelint-no-unresolved-module`](https://github.com/niksy/stylelint-no-unresolved-module) |
149
+ | `plugins.noUnsupportedBrowserFeatures()` | Проверяет поддержку CSS-функций целевыми браузерами | [`stylelint-no-unsupported-browser-features`](https://github.com/ismay/stylelint-no-unsupported-browser-features) |
150
+ | `plugins.order()` | Настраивает порядок свойств и селекторов | [`stylelint-order`](https://github.com/hudochenkov/stylelint-order) |
151
+ | `plugins.prettier()` | Интегрирует Prettier | [`stylelint-prettier`](https://github.com/prettier/stylelint-prettier) |
152
+ | `plugins.scss()` | Настраивает линтинг SCSS | [`stylelint-scss`](https://github.com/kristerkari/stylelint-scss) |
153
+ | `plugins.selectorNoEmpty()` | Запрещает пустые селекторы | [`stylelint-selector-no-empty`](https://github.com/ssivanatarajan/stylelint-selector-no-empty) |
154
+ | `plugins.useNesting()` | Требует использования CSS-вложенности | [`stylelint-use-nesting`](https://github.com/csstools/stylelint-use-nesting) |
155
+ | `plugins.vue()` | Подключает поддержку Vue.js SFC | [`stylelint-config-recommended-vue`](https://github.com/ota-meshi/stylelint-config-recommended-vue) |
156
+
157
+ ## Миграция с v63
158
+
159
+ v64 - major-релиз: коллекции в опциях проверок теперь дополняют дефолты, а не
160
+ заменяют их.
161
+
162
+ | Было | Стало |
163
+ | --------------------------------------------------------- | ------------------------------------------------------------------- |
164
+ | `plugins.scss({ extends: ['custom'] })` заменял дефолтный | `extends` дополняется, `custom` применяется после дефолтного |
165
+ | `plugins.useNesting({ plugins: ['custom'] })` заменял | `plugins` дополняется, дубли убираются |
166
+ | `plugins.bem({ overrides: [...] })` заменял дефолтные | overrides дополняются, пользовательские применяются после дефолтных |
167
+
168
+ Отключить конкретное дефолтное правило можно через `rules: { 'rule': null }`.
169
+ Общие настройки, которые должны перебивать всё, передавайте вторым аргументом
170
+ `defineConfig`.
116
171
 
117
172
  ## Миграция с v61
118
173
 
119
- v62 — breaking-релиз: проверок по умолчанию больше нет, всё подключается явно.
174
+ v62 - breaking-релиз: проверок по умолчанию больше нет, всё подключается явно.
120
175
 
121
176
  | v61 | v62 |
122
177
  | ------------------------------- | ---------------------------------------------- |
@@ -134,7 +189,7 @@ v62 — breaking-релиз: проверок по умолчанию больш
134
189
 
135
190
  - Проверка актуальности правил:
136
191
 
137
- ```sh
192
+ ```bash
138
193
  npx stylelint-find-new-rules
139
194
  ```
140
195
 
package/index.d.ts CHANGED
@@ -1,13 +1,17 @@
1
1
  import type { Config } from 'stylelint';
2
2
 
3
3
  /**
4
- * Опции фабрики плагина — частичный конфиг Stylelint, накладываемый поверх
4
+ * Опции фабрики плагина - частичный конфиг Stylelint, накладываемый поверх
5
5
  * значений по умолчанию.
6
+ *
7
+ * Коллекции (`extends`, `ignoreFiles`, `overrides`, `plugins`) дополняют
8
+ * значения по умолчанию, `rules` мержатся поверхностно, остальные поля
9
+ * заменяются. Для каждого элемента `overrides` обязателен `files`.
6
10
  */
7
11
  type PluginOptions = Partial<Config>;
8
12
 
9
13
  /**
10
- * Пространство имён фабрик конфигов плагинов. Дефолтных плагинов нет —
14
+ * Пространство имён фабрик конфигов плагинов. Дефолтных плагинов нет -
11
15
  * подключайте нужные явно.
12
16
  */
13
17
  interface Plugins {
@@ -39,10 +43,10 @@ declare const plugins: Plugins;
39
43
  *
40
44
  * Приоритет (от низкого к высокому): база → конфиги плагинов по порядку →
41
45
  * `options`. `extends`, `ignoreFiles`, `overrides` и `plugins` конкатенируются
42
- * (дубли `plugins` убираются), `rules` — shallow merge.
46
+ * (дубли `plugins` убираются), `rules` - shallow merge.
43
47
  *
44
- * @param pluginConfigs — конфиги плагинов (например, `[plugins.scss()]`)
45
- * @param options — базовые опции Stylelint, наивысший приоритет
48
+ * @param pluginConfigs - Конфиги плагинов (например, `[plugins.scss()]`)
49
+ * @param options - Базовые опции Stylelint, наивысший приоритет
46
50
  */
47
51
  declare function defineConfig(
48
52
  pluginConfigs?: Config[],
package/index.js CHANGED
@@ -17,8 +17,9 @@ import { scss } from './plugins/scss.js';
17
17
  import { selectorNoEmpty } from './plugins/selector-no-empty.js';
18
18
  import { useNesting } from './plugins/use-nesting.js';
19
19
  import { vue } from './plugins/vue.js';
20
+ import { mergeConfigs } from './utils/merge-configs.js';
20
21
 
21
- /** Плагины. Дефолтных плагинов нет — подключайте нужные явно в `defineConfig`. */
22
+ /** Плагины. Дефолтных плагинов нет - подключайте нужные явно в `defineConfig`. */
22
23
  const plugins = {
23
24
  a11y,
24
25
  bem,
@@ -141,12 +142,12 @@ const BASE_RULES = {
141
142
  * Создать конфиг Stylelint.
142
143
  *
143
144
  * Приоритет (от низкого к высокому): база → конфиги плагинов по порядку →
144
- * `options`. `extends`, `ignoreFiles`, `overrides` и `plugins` конкатенируются
145
- * (дубли `plugins` убираются), `rules` — shallow merge.
145
+ * `options`. Коллекции (`extends`, `ignoreFiles`, `overrides`, `plugins`)
146
+ * конкатенируются (дубли `plugins` убираются), `rules` - shallow merge.
146
147
  *
147
- * @param {import('stylelint').Config[]} [pluginConfigs] — конфиги плагинов
148
+ * @param {import('stylelint').Config[]} [pluginConfigs] - Конфиги плагинов
148
149
  * (например, `[plugins.scss(), plugins.vue()]`)
149
- * @param {import('stylelint').Config} [options] — базовые опции Stylelint,
150
+ * @param {import('stylelint').Config} [options] - Базовые опции Stylelint,
150
151
  * наивысший приоритет
151
152
  *
152
153
  * @returns {import('stylelint').Config}
@@ -167,16 +168,7 @@ const defineConfig = (pluginConfigs = [], options = {}) => {
167
168
  rules: BASE_RULES,
168
169
  };
169
170
 
170
- const sources = [baseConfig, ...pluginConfigs, options];
171
-
172
- return {
173
- ...Object.assign({}, ...sources),
174
- extends: sources.flatMap((source) => source.extends ?? []),
175
- ignoreFiles: sources.flatMap((source) => source.ignoreFiles ?? []),
176
- overrides: sources.flatMap((source) => source.overrides ?? []),
177
- plugins: [...new Set(sources.flatMap((source) => source.plugins ?? []))],
178
- rules: Object.assign({}, ...sources.map((source) => source.rules ?? {})),
179
- };
171
+ return mergeConfigs(baseConfig, ...pluginConfigs, options);
180
172
  };
181
173
 
182
174
  export { defineConfig, plugins };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alexlit/config-stylelint",
3
- "version": "63.0.0",
3
+ "version": "64.0.0",
4
4
  "private": false,
5
5
  "description": "Stylelint config",
6
6
  "keywords": [
@@ -28,7 +28,8 @@
28
28
  "README.md",
29
29
  "index.js",
30
30
  "index.d.ts",
31
- "plugins"
31
+ "plugins",
32
+ "utils"
32
33
  ],
33
34
  "scripts": {
34
35
  "lint": "cd ../../ && ./scripts/lint.stylelint.sh",
package/plugins/a11y.js CHANGED
@@ -1,31 +1,25 @@
1
1
  /* eslint-disable unicorn/no-null */
2
+ import { mergeConfigs } from '../utils/merge-configs.js';
3
+
4
+ const DEFAULTS = {
5
+ plugins: ['@double-great/stylelint-a11y'],
6
+ rules: {
7
+ 'a11y/media-prefers-reduced-motion': null,
8
+ 'a11y/no-obsolete-attribute': true,
9
+ 'a11y/no-obsolete-element': true,
10
+ 'a11y/no-outline-none': true,
11
+ 'a11y/no-text-align-justify': true,
12
+ 'a11y/selector-pseudo-class-focus': true,
13
+ },
14
+ };
2
15
 
3
16
  /**
4
17
  * Проверяет типичные ошибки доступности.
5
18
  *
6
- * @param {Partial<import('stylelint').Config>} [options] — опции, накладываемые
7
- * поверх значений по умолчанию (shallow merge)
19
+ * @param {Partial<import('stylelint').Config>} [options]
8
20
  *
9
21
  * @returns {import('stylelint').Config}
10
22
  *
11
23
  * @see [stylelint-a11y](https://github.com/double-great/stylelint-a11y)
12
24
  */
13
- export const a11y = (options = {}) => {
14
- const baseConfig = {
15
- plugins: ['@double-great/stylelint-a11y'],
16
- rules: {
17
- 'a11y/media-prefers-reduced-motion': null,
18
- 'a11y/no-obsolete-attribute': true,
19
- 'a11y/no-obsolete-element': true,
20
- 'a11y/no-outline-none': true,
21
- 'a11y/no-text-align-justify': true,
22
- 'a11y/selector-pseudo-class-focus': true,
23
- },
24
- };
25
-
26
- return {
27
- ...baseConfig,
28
- ...options,
29
- rules: { ...baseConfig.rules, ...options.rules },
30
- };
31
- };
25
+ export const a11y = (options = {}) => mergeConfigs(DEFAULTS, options);
package/plugins/bem.js CHANGED
@@ -1,21 +1,13 @@
1
1
  /* eslint-disable unicorn/no-null */
2
2
  import { createDefineRules } from '@morev/stylelint-plugin';
3
3
 
4
+ import { mergeConfigs } from '../utils/merge-configs.js';
5
+
4
6
  const defineRules = createDefineRules({
5
7
  separators: { element: '__', modifier: '--', modifierValue: '--' },
6
8
  });
7
9
 
8
- /**
9
- * Настраивает линтинг по методологии БЭМ.
10
- *
11
- * @param {Partial<import('stylelint').Config>} [options] — опции, накладываемые
12
- * поверх значений по умолчанию (shallow merge)
13
- *
14
- * @returns {import('stylelint').Config}
15
- *
16
- * @see [@morev/stylelint-plugin](https://morevm.github.io/stylelint-plugin/)
17
- */
18
- export const bem = (options = {}) => ({
10
+ const DEFAULTS = {
19
11
  overrides: [
20
12
  {
21
13
  files: ['**/*.{css,scss,vue}'],
@@ -45,6 +37,15 @@ export const bem = (options = {}) => ({
45
37
  },
46
38
  ],
47
39
  plugins: ['@morev/stylelint-plugin'],
40
+ };
48
41
 
49
- ...options,
50
- });
42
+ /**
43
+ * Настраивает линтинг по методологии БЭМ.
44
+ *
45
+ * @param {Partial<import('stylelint').Config>} [options]
46
+ *
47
+ * @returns {import('stylelint').Config}
48
+ *
49
+ * @see [@morev/stylelint-plugin](https://morevm.github.io/stylelint-plugin/)
50
+ */
51
+ export const bem = (options = {}) => mergeConfigs(DEFAULTS, options);
@@ -1,5 +1,7 @@
1
1
  import stylelint from 'stylelint';
2
2
 
3
+ import { mergeConfigs } from '../utils/merge-configs.js';
4
+
3
5
  const { createPlugin } = stylelint;
4
6
  const { report, ruleMessages, validateOptions } = stylelint.utils;
5
7
 
@@ -168,18 +170,18 @@ const rule = function (actual, options, context) {
168
170
  rule.ruleName = ruleName;
169
171
  rule.messages = messages;
170
172
 
173
+ const DEFAULTS = {
174
+ plugins: [createPlugin(ruleName, rule)],
175
+ rules: { 'color-format/format': { format: 'rgb' } },
176
+ };
177
+
171
178
  /**
172
179
  * Нормализует формат цветов (hex → rgb/hsl).
173
180
  *
174
- * @param {Partial<import('stylelint').Config>} [options] — опции, накладываемые
175
- * поверх значений по умолчанию (shallow merge)
181
+ * @param {Partial<import('stylelint').Config>} [options] - Опции, накладываемые
182
+ * поверх значений по умолчанию. Коллекции (`extends`, `ignoreFiles`,
183
+ * `overrides`, `plugins`) дополняются, `rules` мержатся поверхностно
176
184
  *
177
185
  * @returns {import('stylelint').Config}
178
186
  */
179
- export const colorFormat = (options = {}) => ({
180
- plugins: [createPlugin(ruleName, rule)],
181
-
182
- ...options,
183
-
184
- rules: { 'color-format/format': { format: 'rgb' }, ...options.rules },
185
- });
187
+ export const colorFormat = (options = {}) => mergeConfigs(DEFAULTS, options);
@@ -1,20 +1,18 @@
1
+ import { mergeConfigs } from '../utils/merge-configs.js';
2
+
3
+ const DEFAULTS = {
4
+ plugins: ['stylelint-declaration-block-no-ignored-properties'],
5
+ rules: { 'plugin/declaration-block-no-ignored-properties': true },
6
+ };
7
+
1
8
  /**
2
9
  * Запрещает бесполезные свойства в блоке объявлений.
3
10
  *
4
- * @param {Partial<import('stylelint').Config>} [options] — опции, накладываемые
5
- * поверх значений по умолчанию (shallow merge)
11
+ * @param {Partial<import('stylelint').Config>} [options]
6
12
  *
7
13
  * @returns {import('stylelint').Config}
8
14
  *
9
15
  * @see [stylelint-declaration-block-no-ignored-properties](https://github.com/kristerkari/stylelint-declaration-block-no-ignored-properties)
10
16
  */
11
- export const declarationBlockNoIgnoredProperties = (options = {}) => ({
12
- plugins: ['stylelint-declaration-block-no-ignored-properties'],
13
-
14
- ...options,
15
-
16
- rules: {
17
- 'plugin/declaration-block-no-ignored-properties': true,
18
- ...options.rules,
19
- },
20
- });
17
+ export const declarationBlockNoIgnoredProperties = (options = {}) =>
18
+ mergeConfigs(DEFAULTS, options);
package/plugins/gamut.js CHANGED
@@ -1,17 +1,17 @@
1
+ import { mergeConfigs } from '../utils/merge-configs.js';
2
+
3
+ const DEFAULTS = {
4
+ plugins: ['stylelint-gamut'],
5
+ rules: { 'gamut/color-no-out-gamut-range': true },
6
+ };
7
+
1
8
  /**
2
9
  * Проверяет цвета на выход за пределы цветового охвата (gamut).
3
10
  *
4
- * @param {Partial<import('stylelint').Config>} [options] — опции, накладываемые
5
- * поверх значений по умолчанию (shallow merge)
11
+ * @param {Partial<import('stylelint').Config>} [options]
6
12
  *
7
13
  * @returns {import('stylelint').Config}
8
14
  *
9
15
  * @see [stylelint-gamut](https://github.com/fpetrakov/stylelint-gamut)
10
16
  */
11
- export const gamut = (options = {}) => ({
12
- plugins: ['stylelint-gamut'],
13
-
14
- ...options,
15
-
16
- rules: { 'gamut/color-no-out-gamut-range': true, ...options.rules },
17
- });
17
+ export const gamut = (options = {}) => mergeConfigs(DEFAULTS, options);
@@ -1,23 +1,23 @@
1
+ import { mergeConfigs } from '../utils/merge-configs.js';
2
+
3
+ const DEFAULTS = {
4
+ plugins: ['stylelint-high-performance-animation'],
5
+ rules: {
6
+ 'plugin/no-low-performance-animation-properties': [
7
+ true,
8
+ { ignore: 'paint-properties', ignoreProperties: [] },
9
+ ],
10
+ },
11
+ };
12
+
1
13
  /**
2
14
  * Запрещает анимации, нагружающие рендеринг.
3
15
  *
4
- * @param {Partial<import('stylelint').Config>} [options] — опции, накладываемые
5
- * поверх значений по умолчанию (shallow merge)
16
+ * @param {Partial<import('stylelint').Config>} [options]
6
17
  *
7
18
  * @returns {import('stylelint').Config}
8
19
  *
9
20
  * @see [stylelint-high-performance-animation](https://github.com/kristerkari/stylelint-high-performance-animation)
10
21
  */
11
- export const highPerformanceAnimation = (options = {}) => ({
12
- plugins: ['stylelint-high-performance-animation'],
13
-
14
- ...options,
15
-
16
- rules: {
17
- 'plugin/no-low-performance-animation-properties': [
18
- true,
19
- { ignore: 'paint-properties', ignoreProperties: [] },
20
- ],
21
- ...options.rules,
22
- },
23
- });
22
+ export const highPerformanceAnimation = (options = {}) =>
23
+ mergeConfigs(DEFAULTS, options);
@@ -1,16 +1,17 @@
1
+ import { mergeConfigs } from '../utils/merge-configs.js';
2
+
3
+ const DEFAULTS = {
4
+ extends: ['stylelint-plugin-logical-css/configs/recommended'],
5
+ plugins: ['stylelint-plugin-logical-css'],
6
+ };
7
+
1
8
  /**
2
9
  * Проверяет использование логических CSS-свойств.
3
10
  *
4
- * @param {Partial<import('stylelint').Config>} [options] — опции, накладываемые
5
- * поверх значений по умолчанию (shallow merge)
11
+ * @param {Partial<import('stylelint').Config>} [options]
6
12
  *
7
13
  * @returns {import('stylelint').Config}
8
14
  *
9
15
  * @see [stylelint-plugin-logical-css](https://github.com/yuschick/stylelint-plugin-logical-css)
10
16
  */
11
- export const logicalCss = (options = {}) => ({
12
- extends: ['stylelint-plugin-logical-css/configs/recommended'],
13
- plugins: ['stylelint-plugin-logical-css'],
14
-
15
- ...options,
16
- });
17
+ export const logicalCss = (options = {}) => mergeConfigs(DEFAULTS, options);
@@ -1,17 +1,18 @@
1
+ import { mergeConfigs } from '../utils/merge-configs.js';
2
+
3
+ const DEFAULTS = {
4
+ plugins: ['stylelint-media-use-custom-media'],
5
+ rules: { 'csstools/media-use-custom-media': 'always' },
6
+ };
7
+
1
8
  /**
2
9
  * Требует использования кастомных медиа-запросов.
3
10
  *
4
- * @param {Partial<import('stylelint').Config>} [options] — опции, накладываемые
5
- * поверх значений по умолчанию (shallow merge)
11
+ * @param {Partial<import('stylelint').Config>} [options]
6
12
  *
7
13
  * @returns {import('stylelint').Config}
8
14
  *
9
15
  * @see [stylelint-media-use-custom-media](https://github.com/csstools/stylelint-media-use-custom-media)
10
16
  */
11
- export const mediaUseCustomMedia = (options = {}) => ({
12
- plugins: ['stylelint-media-use-custom-media'],
13
-
14
- ...options,
15
-
16
- rules: { 'csstools/media-use-custom-media': 'always', ...options.rules },
17
- });
17
+ export const mediaUseCustomMedia = (options = {}) =>
18
+ mergeConfigs(DEFAULTS, options);
@@ -1,20 +1,18 @@
1
+ import { mergeConfigs } from '../utils/merge-configs.js';
2
+
3
+ const DEFAULTS = {
4
+ plugins: ['stylelint-no-indistinguishable-colors'],
5
+ rules: { 'plugin/stylelint-no-indistinguishable-colors': true },
6
+ };
7
+
1
8
  /**
2
9
  * Запрещает неразличимые цвета.
3
10
  *
4
- * @param {Partial<import('stylelint').Config>} [options] — опции, накладываемые
5
- * поверх значений по умолчанию (shallow merge)
11
+ * @param {Partial<import('stylelint').Config>} [options]
6
12
  *
7
13
  * @returns {import('stylelint').Config}
8
14
  *
9
15
  * @see [stylelint-no-indistinguishable-colors](https://github.com/ierhyna/stylelint-no-indistinguishable-colors)
10
16
  */
11
- export const noIndistinguishableColors = (options = {}) => ({
12
- plugins: ['stylelint-no-indistinguishable-colors'],
13
-
14
- ...options,
15
-
16
- rules: {
17
- 'plugin/stylelint-no-indistinguishable-colors': true,
18
- ...options.rules,
19
- },
20
- });
17
+ export const noIndistinguishableColors = (options = {}) =>
18
+ mergeConfigs(DEFAULTS, options);
@@ -1,17 +1,17 @@
1
+ import { mergeConfigs } from '../utils/merge-configs.js';
2
+
3
+ const DEFAULTS = {
4
+ plugins: ['stylelint-no-nested-media'],
5
+ rules: { 'pitcher/no-nested-media': true },
6
+ };
7
+
1
8
  /**
2
9
  * Запрещает вложенные медиа-запросы.
3
10
  *
4
- * @param {Partial<import('stylelint').Config>} [options] — опции, накладываемые
5
- * поверх значений по умолчанию (shallow merge)
11
+ * @param {Partial<import('stylelint').Config>} [options]
6
12
  *
7
13
  * @returns {import('stylelint').Config}
8
14
  *
9
15
  * @see [stylelint-no-nested-media](https://github.com/dkrnl/stylelint-no-nested-media)
10
16
  */
11
- export const noNestedMedia = (options = {}) => ({
12
- plugins: ['stylelint-no-nested-media'],
13
-
14
- ...options,
15
-
16
- rules: { 'pitcher/no-nested-media': true, ...options.rules },
17
- });
17
+ export const noNestedMedia = (options = {}) => mergeConfigs(DEFAULTS, options);
@@ -1,18 +1,7 @@
1
- /**
2
- * Проверяет разрешение импортов.
3
- *
4
- * @param {Partial<import('stylelint').Config>} [options] — опции, накладываемые
5
- * поверх значений по умолчанию (shallow merge)
6
- *
7
- * @returns {import('stylelint').Config}
8
- *
9
- * @see [stylelint-no-unresolved-module](https://github.com/niksy/stylelint-no-unresolved-module)
10
- */
11
- export const noUnresolvedModule = (options = {}) => ({
12
- plugins: ['stylelint-no-unresolved-module'],
13
-
14
- ...options,
1
+ import { mergeConfigs } from '../utils/merge-configs.js';
15
2
 
3
+ const DEFAULTS = {
4
+ plugins: ['stylelint-no-unresolved-module'],
16
5
  rules: {
17
6
  'plugin/no-unresolved-module': {
18
7
  alias: { '~assets': 'assets', '~public': 'public', '~static': 'static' },
@@ -27,6 +16,17 @@ export const noUnresolvedModule = (options = {}) => ({
27
16
  'static',
28
17
  ],
29
18
  },
30
- ...options.rules,
31
19
  },
32
- });
20
+ };
21
+
22
+ /**
23
+ * Проверяет разрешение импортов.
24
+ *
25
+ * @param {Partial<import('stylelint').Config>} [options]
26
+ *
27
+ * @returns {import('stylelint').Config}
28
+ *
29
+ * @see [stylelint-no-unresolved-module](https://github.com/niksy/stylelint-no-unresolved-module)
30
+ */
31
+ export const noUnresolvedModule = (options = {}) =>
32
+ mergeConfigs(DEFAULTS, options);
@@ -1,18 +1,7 @@
1
- /**
2
- * Проверяет поддержку CSS-функций целевыми браузерами.
3
- *
4
- * @param {Partial<import('stylelint').Config>} [options] — опции, накладываемые
5
- * поверх значений по умолчанию (shallow merge)
6
- *
7
- * @returns {import('stylelint').Config}
8
- *
9
- * @see [stylelint-no-unsupported-browser-features](https://github.com/ismay/stylelint-no-unsupported-browser-features)
10
- */
11
- export const noUnsupportedBrowserFeatures = (options = {}) => ({
12
- plugins: ['stylelint-no-unsupported-browser-features'],
13
-
14
- ...options,
1
+ import { mergeConfigs } from '../utils/merge-configs.js';
15
2
 
3
+ const DEFAULTS = {
4
+ plugins: ['stylelint-no-unsupported-browser-features'],
16
5
  rules: {
17
6
  'plugin/no-unsupported-browser-features': [
18
7
  true,
@@ -22,6 +11,17 @@ export const noUnsupportedBrowserFeatures = (options = {}) => ({
22
11
  severity: 'warning',
23
12
  },
24
13
  ],
25
- ...options.rules,
26
14
  },
27
- });
15
+ };
16
+
17
+ /**
18
+ * Проверяет поддержку CSS-функций целевыми браузерами.
19
+ *
20
+ * @param {Partial<import('stylelint').Config>} [options]
21
+ *
22
+ * @returns {import('stylelint').Config}
23
+ *
24
+ * @see [stylelint-no-unsupported-browser-features](https://github.com/ismay/stylelint-no-unsupported-browser-features)
25
+ */
26
+ export const noUnsupportedBrowserFeatures = (options = {}) =>
27
+ mergeConfigs(DEFAULTS, options);
package/plugins/order.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { mergeConfigs } from '../utils/merge-configs.js';
2
+
1
3
  const LETTERS = 'abcdefghijklmnopqrstuvwxyz'.split('');
2
4
 
3
5
  const MEDIA_FEATURES = [
@@ -115,21 +117,8 @@ const buildPseudoElementRules = () => [
115
117
  { selector: '::', type: 'rule' },
116
118
  ];
117
119
 
118
- /**
119
- * Настраивает порядок свойств и селекторов.
120
- *
121
- * @param {Partial<import('stylelint').Config>} [options] — опции, накладываемые
122
- * поверх значений по умолчанию (shallow merge)
123
- *
124
- * @returns {import('stylelint').Config}
125
- *
126
- * @see [stylelint-order](https://github.com/hudochenkov/stylelint-order)
127
- */
128
- export const order = (options = {}) => ({
120
+ const DEFAULTS = {
129
121
  plugins: ['stylelint-order'],
130
-
131
- ...options,
132
-
133
122
  rules: {
134
123
  'order/custom-properties-alphabetical-order': true,
135
124
  'order/order': [
@@ -198,7 +187,16 @@ export const order = (options = {}) => ({
198
187
  ...buildLetterRules('__'),
199
188
  ],
200
189
  'order/properties-alphabetical-order': true,
201
-
202
- ...options.rules,
203
190
  },
204
- });
191
+ };
192
+
193
+ /**
194
+ * Настраивает порядок свойств и селекторов.
195
+ *
196
+ * @param {Partial<import('stylelint').Config>} [options]
197
+ *
198
+ * @returns {import('stylelint').Config}
199
+ *
200
+ * @see [stylelint-order](https://github.com/hudochenkov/stylelint-order)
201
+ */
202
+ export const order = (options = {}) => mergeConfigs(DEFAULTS, options);
@@ -1,17 +1,17 @@
1
+ import { mergeConfigs } from '../utils/merge-configs.js';
2
+
3
+ const DEFAULTS = {
4
+ plugins: ['stylelint-prettier'],
5
+ rules: { 'prettier/prettier': true },
6
+ };
7
+
1
8
  /**
2
9
  * Интегрирует Prettier.
3
10
  *
4
- * @param {Partial<import('stylelint').Config>} [options] — опции, накладываемые
5
- * поверх значений по умолчанию (shallow merge)
11
+ * @param {Partial<import('stylelint').Config>} [options]
6
12
  *
7
13
  * @returns {import('stylelint').Config}
8
14
  *
9
15
  * @see [stylelint-prettier](https://github.com/prettier/stylelint-prettier)
10
16
  */
11
- export const prettier = (options = {}) => ({
12
- plugins: ['stylelint-prettier'],
13
-
14
- ...options,
15
-
16
- rules: { 'prettier/prettier': true, ...options.rules },
17
- });
17
+ export const prettier = (options = {}) => mergeConfigs(DEFAULTS, options);
package/plugins/scss.js CHANGED
@@ -1,23 +1,11 @@
1
1
  /* eslint-disable unicorn/no-null */
2
+ import { mergeConfigs } from '../utils/merge-configs.js';
2
3
 
3
4
  const KEBAB_CASE_PATTERN = '^[a-z]+([a-z0-9-]+[a-z0-9]+)?$';
4
5
 
5
- /**
6
- * Настраивает линтинг SCSS.
7
- *
8
- * @param {Partial<import('stylelint').Config>} [options] — опции, накладываемые
9
- * поверх значений по умолчанию (shallow merge)
10
- *
11
- * @returns {import('stylelint').Config}
12
- *
13
- * @see [stylelint-scss](https://github.com/kristerkari/stylelint-scss)
14
- */
15
- export const scss = (options = {}) => ({
6
+ const DEFAULTS = {
16
7
  extends: ['stylelint-config-standard-scss'],
17
8
  plugins: ['stylelint-scss'],
18
-
19
- ...options,
20
-
21
9
  rules: {
22
10
  'scss/at-each-key-value-single-line': true,
23
11
  'scss/at-else-if-parentheses-space-before': 'always',
@@ -100,7 +88,16 @@ export const scss = (options = {}) => ({
100
88
  true,
101
89
  { ignoreKeywords: [] },
102
90
  ],
103
-
104
- ...options.rules,
105
91
  },
106
- });
92
+ };
93
+
94
+ /**
95
+ * Настраивает линтинг SCSS.
96
+ *
97
+ * @param {Partial<import('stylelint').Config>} [options]
98
+ *
99
+ * @returns {import('stylelint').Config}
100
+ *
101
+ * @see [stylelint-scss](https://github.com/kristerkari/stylelint-scss)
102
+ */
103
+ export const scss = (options = {}) => mergeConfigs(DEFAULTS, options);
@@ -1,17 +1,18 @@
1
+ import { mergeConfigs } from '../utils/merge-configs.js';
2
+
3
+ const DEFAULTS = {
4
+ plugins: ['stylelint-selector-no-empty'],
5
+ rules: { 'plugin/stylelint-selector-no-empty': true },
6
+ };
7
+
1
8
  /**
2
9
  * Запрещает пустые селекторы.
3
10
  *
4
- * @param {Partial<import('stylelint').Config>} [options] — опции, накладываемые
5
- * поверх значений по умолчанию (shallow merge)
11
+ * @param {Partial<import('stylelint').Config>} [options]
6
12
  *
7
13
  * @returns {import('stylelint').Config}
8
14
  *
9
15
  * @see [stylelint-selector-no-empty](https://github.com/ssivanatarajan/stylelint-selector-no-empty)
10
16
  */
11
- export const selectorNoEmpty = (options = {}) => ({
12
- plugins: ['stylelint-selector-no-empty'],
13
-
14
- ...options,
15
-
16
- rules: { 'plugin/stylelint-selector-no-empty': true, ...options.rules },
17
- });
17
+ export const selectorNoEmpty = (options = {}) =>
18
+ mergeConfigs(DEFAULTS, options);
@@ -1,20 +1,17 @@
1
+ import { mergeConfigs } from '../utils/merge-configs.js';
2
+
3
+ const DEFAULTS = {
4
+ plugins: ['stylelint-use-nesting'],
5
+ rules: { 'csstools/use-nesting': ['always', { except: [], syntax: 'scss' }] },
6
+ };
7
+
1
8
  /**
2
9
  * Требует использования CSS-вложенности.
3
10
  *
4
- * @param {Partial<import('stylelint').Config>} [options] — опции, накладываемые
5
- * поверх значений по умолчанию (shallow merge)
11
+ * @param {Partial<import('stylelint').Config>} [options]
6
12
  *
7
13
  * @returns {import('stylelint').Config}
8
14
  *
9
15
  * @see [stylelint-use-nesting](https://github.com/csstools/stylelint-use-nesting)
10
16
  */
11
- export const useNesting = (options = {}) => ({
12
- plugins: ['stylelint-use-nesting'],
13
-
14
- ...options,
15
-
16
- rules: {
17
- 'csstools/use-nesting': ['always', { except: [], syntax: 'scss' }],
18
- ...options.rules,
19
- },
20
- });
17
+ export const useNesting = (options = {}) => mergeConfigs(DEFAULTS, options);
package/plugins/vue.js CHANGED
@@ -1,15 +1,14 @@
1
+ import { mergeConfigs } from '../utils/merge-configs.js';
2
+
3
+ const DEFAULTS = { extends: 'stylelint-config-recommended-vue' };
4
+
1
5
  /**
2
6
  * Подключает поддержку Vue.js SFC.
3
7
  *
4
- * @param {Partial<import('stylelint').Config>} [options] — опции, накладываемые
5
- * поверх значений по умолчанию (shallow merge)
8
+ * @param {Partial<import('stylelint').Config>} [options]
6
9
  *
7
10
  * @returns {import('stylelint').Config}
8
11
  *
9
12
  * @see [stylelint-config-recommended-vue](https://github.com/ota-meshi/stylelint-config-recommended-vue)
10
13
  */
11
- export const vue = (options = {}) => ({
12
- extends: 'stylelint-config-recommended-vue',
13
-
14
- ...options,
15
- });
14
+ export const vue = (options = {}) => mergeConfigs(DEFAULTS, options);
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Объединяет конфиги Stylelint по единой политике.
3
+ *
4
+ * Коллекции (`extends`, `ignoreFiles`, `overrides`, `plugins`) дополняются в
5
+ * порядке аргументов, `plugins` дедуплицируются. `rules` мержатся поверхностно:
6
+ * настройка одноимённого правила из последнего конфига заменяет предыдущую
7
+ * целиком. Остальные поля перезаписываются последним конфигом.
8
+ *
9
+ * @param {...import('stylelint').Config} configs - Конфиги в порядке приоритета
10
+ *
11
+ * @returns {import('stylelint').Config}
12
+ */
13
+ export const mergeConfigs = (...configs) => ({
14
+ ...Object.assign({}, ...configs),
15
+ extends: configs.flatMap((config) => config.extends ?? []),
16
+ ignoreFiles: configs.flatMap((config) => config.ignoreFiles ?? []),
17
+ overrides: configs.flatMap((config) => config.overrides ?? []),
18
+ plugins: [...new Set(configs.flatMap((config) => config.plugins ?? []))],
19
+ rules: Object.assign({}, ...configs.map((config) => config.rules ?? {})),
20
+ });