@alexlit/lint-kit 215.0.0 → 216.1.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.
Files changed (73) hide show
  1. package/eslint.config.js +8 -4
  2. package/package.json +1 -1
  3. package/packages/config-eslint/README.md +57 -32
  4. package/packages/config-eslint/base.js +4 -1
  5. package/packages/config-eslint/index.d.ts +34 -32
  6. package/packages/config-eslint/index.js +5 -2
  7. package/packages/config-eslint/package.json +4 -4
  8. package/packages/config-eslint/plugins/de-morgan.js +4 -2
  9. package/packages/config-eslint/plugins/import-x.js +5 -1
  10. package/packages/config-eslint/plugins/javascript.js +5 -1
  11. package/packages/config-eslint/plugins/jsdoc.js +5 -1
  12. package/packages/config-eslint/plugins/json.js +5 -1
  13. package/packages/config-eslint/plugins/perfectionist.js +5 -1
  14. package/packages/config-eslint/plugins/pinia.js +5 -1
  15. package/packages/config-eslint/plugins/prettier.js +10 -2
  16. package/packages/config-eslint/plugins/regexp.js +5 -1
  17. package/packages/config-eslint/plugins/sonar.js +5 -1
  18. package/packages/config-eslint/plugins/stylistic.js +5 -1
  19. package/packages/config-eslint/plugins/tailwindcss.js +20 -17
  20. package/packages/config-eslint/plugins/tanstack-query.js +5 -1
  21. package/packages/config-eslint/plugins/typescript-type-checked.js +5 -1
  22. package/packages/config-eslint/plugins/typescript.js +5 -1
  23. package/packages/config-eslint/plugins/unicorn.js +5 -1
  24. package/packages/config-eslint/plugins/unocss.js +5 -1
  25. package/packages/config-eslint/plugins/vitest.js +5 -1
  26. package/packages/config-eslint/plugins/vue-accessibility.js +5 -1
  27. package/packages/config-eslint/plugins/vue-i18n.js +10 -5
  28. package/packages/config-eslint/plugins/vue.js +5 -1
  29. package/packages/config-eslint/plugins/zod.js +5 -1
  30. package/packages/config-hooks/README.md +2 -2
  31. package/packages/config-htmllint/README.md +2 -2
  32. package/packages/config-markdownlint/README.md +2 -2
  33. package/packages/config-npmlint/README.md +2 -2
  34. package/packages/config-prettier/README.md +68 -16
  35. package/packages/config-prettier/index.d.ts +9 -1
  36. package/packages/config-prettier/index.js +20 -28
  37. package/packages/config-prettier/package.json +3 -2
  38. package/packages/config-prettier/plugins/jsdoc.js +14 -8
  39. package/packages/config-prettier/plugins/mdc.js +12 -6
  40. package/packages/config-prettier/plugins/packagejson.js +9 -5
  41. package/packages/config-prettier/plugins/php.js +9 -5
  42. package/packages/config-prettier/plugins/pug.js +15 -9
  43. package/packages/config-prettier/plugins/ruby.js +12 -6
  44. package/packages/config-prettier/plugins/sh.js +9 -5
  45. package/packages/config-prettier/plugins/solidity.js +9 -5
  46. package/packages/config-prettier/plugins/sort-json.js +12 -6
  47. package/packages/config-prettier/plugins/sql.js +9 -5
  48. package/packages/config-prettier/plugins/tailwindcss.js +18 -12
  49. package/packages/config-prettier/plugins/xml.js +12 -6
  50. package/packages/config-prettier/utils/merge-configs.js +18 -0
  51. package/packages/config-stylelint/README.md +80 -29
  52. package/packages/config-stylelint/index.d.ts +4 -0
  53. package/packages/config-stylelint/index.js +4 -12
  54. package/packages/config-stylelint/package.json +3 -2
  55. package/packages/config-stylelint/plugins/a11y.js +15 -21
  56. package/packages/config-stylelint/plugins/bem.js +14 -13
  57. package/packages/config-stylelint/plugins/color-format.js +10 -8
  58. package/packages/config-stylelint/plugins/declaration-block-no-ignored-properties.js +10 -12
  59. package/packages/config-stylelint/plugins/gamut.js +9 -9
  60. package/packages/config-stylelint/plugins/high-performance-animation.js +15 -15
  61. package/packages/config-stylelint/plugins/logical-css.js +9 -8
  62. package/packages/config-stylelint/plugins/media-use-custom-media.js +10 -9
  63. package/packages/config-stylelint/plugins/no-indistinguishable-colors.js +10 -12
  64. package/packages/config-stylelint/plugins/no-nested-media.js +9 -9
  65. package/packages/config-stylelint/plugins/no-unresolved-module.js +16 -16
  66. package/packages/config-stylelint/plugins/no-unsupported-browser-features.js +16 -16
  67. package/packages/config-stylelint/plugins/order.js +15 -17
  68. package/packages/config-stylelint/plugins/prettier.js +9 -9
  69. package/packages/config-stylelint/plugins/scss.js +14 -17
  70. package/packages/config-stylelint/plugins/selector-no-empty.js +10 -9
  71. package/packages/config-stylelint/plugins/use-nesting.js +9 -12
  72. package/packages/config-stylelint/plugins/vue.js +6 -7
  73. package/packages/config-stylelint/utils/merge-configs.js +20 -0
@@ -6,11 +6,13 @@ import { DATA_FILES } from '../base.js';
6
6
  /**
7
7
  * Правила для TanStack Query.
8
8
  *
9
+ * @param {import('eslint').Linter.Config | import('eslint').Linter.Config[]} [config]
10
+ *
9
11
  * @returns {import('eslint').Linter.Config[]}
10
12
  *
11
13
  * @see [@tanstack/query](https://tanstack.com/query/latest/docs/eslint/eslint-plugin-query)
12
14
  */
13
- export const tanstackQuery = () =>
15
+ export const tanstackQuery = (config = []) =>
14
16
  defineConfig([
15
17
  // The shipped config has no `files` key, so it would also cover data files.
16
18
  ...plugin.configs['flat/recommended'].map((config) => ({
@@ -18,4 +20,6 @@ export const tanstackQuery = () =>
18
20
  ignores: [...(config.ignores ?? []), ...DATA_FILES],
19
21
  })),
20
22
  { rules: { '@tanstack/query/infinite-query-property-order': 'off' } },
23
+
24
+ config,
21
25
  ]);
@@ -11,11 +11,13 @@ import { TS_RULES } from '../rules/typescript.js';
11
11
  * which makes linting slower. Use it instead of `typescript`, not alongside
12
12
  * it.
13
13
  *
14
+ * @param {import('eslint').Linter.Config | import('eslint').Linter.Config[]} [config]
15
+ *
14
16
  * @returns {import('eslint').Linter.Config[]}
15
17
  *
16
18
  * @see [typescript-eslint](https://github.com/typescript-eslint/typescript-eslint)
17
19
  */
18
- export const typescriptTypeChecked = () =>
20
+ export const typescriptTypeChecked = (config = []) =>
19
21
  defineConfig([
20
22
  // The parser is needed for every JS/TS/Vue file, not only for TypeScript ones,
21
23
  // otherwise `.js` files fall back to the default parser and modern syntax
@@ -52,4 +54,6 @@ export const typescriptTypeChecked = () =>
52
54
  files: TEST_FILES,
53
55
  rules: { '@typescript-eslint/no-empty-function': 'off' },
54
56
  },
57
+
58
+ config,
55
59
  ]);
@@ -7,11 +7,13 @@ import { TS_RULES } from '../rules/typescript.js';
7
7
  /**
8
8
  * Правила TypeScript без анализа типов.
9
9
  *
10
+ * @param {import('eslint').Linter.Config | import('eslint').Linter.Config[]} [config]
11
+ *
10
12
  * @returns {import('eslint').Linter.Config[]}
11
13
  *
12
14
  * @see [typescript-eslint](https://github.com/typescript-eslint/typescript-eslint)
13
15
  */
14
- export const typescript = () =>
16
+ export const typescript = (config = []) =>
15
17
  defineConfig([
16
18
  // `plugin.configs.strict`/`stylistic` contain blocks without a `files` key,
17
19
  // so they would also land on data files that are not JavaScript at all.
@@ -27,4 +29,6 @@ export const typescript = () =>
27
29
  files: TEST_FILES,
28
30
  rules: { '@typescript-eslint/no-empty-function': 'off' },
29
31
  },
32
+
33
+ config,
30
34
  ]);
@@ -6,11 +6,13 @@ import { DTS_FILES, FILES, VUE_FILES } from '../base.js';
6
6
  /**
7
7
  * Правила unicorn.
8
8
  *
9
+ * @param {import('eslint').Linter.Config | import('eslint').Linter.Config[]} [config]
10
+ *
9
11
  * @returns {import('eslint').Linter.Config[]}
10
12
  *
11
13
  * @see [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn)
12
14
  */
13
- export const unicorn = () =>
15
+ export const unicorn = (config = []) =>
14
16
  defineConfig([
15
17
  { ...plugin.configs.recommended, files: FILES },
16
18
  {
@@ -78,4 +80,6 @@ export const unicorn = () =>
78
80
  files: ['**/temp/**/*.vue'],
79
81
  rules: { 'unicorn/name-replacements': 'off' },
80
82
  },
83
+
84
+ config,
81
85
  ]);
@@ -6,12 +6,16 @@ import { FILES } from '../base.js';
6
6
  /**
7
7
  * Правила для UnoCSS.
8
8
  *
9
+ * @param {import('eslint').Linter.Config | import('eslint').Linter.Config[]} [config]
10
+ *
9
11
  * @returns {import('eslint').Linter.Config[]}
10
12
  *
11
13
  * @see [@unocss/eslint-config](https://unocss.dev/integrations/eslint)
12
14
  */
13
- export const unocss = () =>
15
+ export const unocss = (config = []) =>
14
16
  defineConfig([
15
17
  { files: FILES, ...plugin },
16
18
  { files: FILES, rules: { 'unocss/order-attributify': 'off' } },
19
+
20
+ config,
17
21
  ]);
@@ -6,11 +6,13 @@ import { TEST_FILES } from '../base.js';
6
6
  /**
7
7
  * Правила для тестов Vitest.
8
8
  *
9
+ * @param {import('eslint').Linter.Config | import('eslint').Linter.Config[]} [config]
10
+ *
9
11
  * @returns {import('eslint').Linter.Config[]}
10
12
  *
11
13
  * @see [eslint-plugin-vitest](https://github.com/veritem/eslint-plugin-vitest)
12
14
  */
13
- export const vitest = () =>
15
+ export const vitest = (config = []) =>
14
16
  defineConfig([
15
17
  {
16
18
  files: TEST_FILES,
@@ -24,4 +26,6 @@ export const vitest = () =>
24
26
  'vitest/require-to-throw-message': 'off',
25
27
  },
26
28
  },
29
+
30
+ config,
27
31
  ]);
@@ -6,11 +6,13 @@ import { VUE_FILES } from '../base.js';
6
6
  /**
7
7
  * Правила доступности Vue.js-компонентов.
8
8
  *
9
+ * @param {import('eslint').Linter.Config | import('eslint').Linter.Config[]} [config]
10
+ *
9
11
  * @returns {import('eslint').Linter.Config[]}
10
12
  *
11
13
  * @see [eslint-plugin-vuejs-accessibility](https://vue-a11y.github.io/eslint-plugin-vuejs-accessibility/)
12
14
  */
13
- export const vueAccessibility = () =>
15
+ export const vueAccessibility = (config = []) =>
14
16
  defineConfig([
15
17
  ...plugin.configs['flat/recommended'],
16
18
 
@@ -24,4 +26,6 @@ export const vueAccessibility = () =>
24
26
  'vuejs-accessibility/no-autofocus': ['warn', { ignoreNonDOM: true }],
25
27
  },
26
28
  },
29
+
30
+ config,
27
31
  ]);
@@ -6,16 +6,19 @@ import { DATA_FILES, VUE_FILES } from '../base.js';
6
6
  /**
7
7
  * Правила для Vue.js I18n.
8
8
  *
9
+ * @param {import('eslint').Linter.Config | import('eslint').Linter.Config[]} [config]
10
+ *
9
11
  * @returns {import('eslint').Linter.Config[]}
10
12
  *
11
13
  * @see [eslint-plugin-vue-i18n](https://eslint-plugin-vue-i18n.intlify.dev/)
12
14
  */
13
- export const vueI18n = () =>
15
+ export const vueI18n = (config = []) =>
14
16
  defineConfig([
15
- ...plugin.configs['flat/recommended'].map((config) => ({
16
- ...config,
17
- ignores: [...(config.ignores ?? []), ...DATA_FILES],
18
- })),
17
+ ...plugin.configs['flat/recommended'].map((config) =>
18
+ config.files
19
+ ? config
20
+ : { ...config, ignores: [...(config.ignores ?? []), ...DATA_FILES] },
21
+ ),
19
22
 
20
23
  {
21
24
  files: VUE_FILES,
@@ -43,4 +46,6 @@ export const vueI18n = () =>
43
46
  },
44
47
  },
45
48
  },
49
+
50
+ config,
46
51
  ]);
@@ -8,11 +8,13 @@ import { NO_RESTRICTED_SYNTAX } from '../rules/restricted-syntax.js';
8
8
  /**
9
9
  * Правила для Vue.js.
10
10
  *
11
+ * @param {import('eslint').Linter.Config | import('eslint').Linter.Config[]} [config]
12
+ *
11
13
  * @returns {import('eslint').Linter.Config[]}
12
14
  *
13
15
  * @see [eslint-plugin-vue](https://eslint.vuejs.org/rules/)
14
16
  */
15
- export const vue = () =>
17
+ export const vue = (config = []) =>
16
18
  defineConfig([
17
19
  ...plugin.configs['flat/recommended'].map((config) => ({
18
20
  ...config,
@@ -268,4 +270,6 @@ export const vue = () =>
268
270
  },
269
271
 
270
272
  { files: TEST_FILES, rules: { 'vue/one-component-per-file': 'off' } },
273
+
274
+ config,
271
275
  ]);
@@ -6,11 +6,13 @@ import { FILES } from '../base.js';
6
6
  /**
7
7
  * Правила для Zod-схем.
8
8
  *
9
+ * @param {import('eslint').Linter.Config | import('eslint').Linter.Config[]} [config]
10
+ *
9
11
  * @returns {import('eslint').Linter.Config[]}
10
12
  *
11
13
  * @see [eslint-plugin-zod](https://github.com/marcalexiei/eslint-zod/tree/main/plugins/eslint-plugin-zod)
12
14
  */
13
- export const zod = () =>
15
+ export const zod = (config = []) =>
14
16
  defineConfig([
15
17
  {
16
18
  ...plugin.configs.recommended,
@@ -20,4 +22,6 @@ export const zod = () =>
20
22
  'zod/consistent-import': ['error', { syntax: 'named' }],
21
23
  },
22
24
  },
25
+
26
+ config,
23
27
  ]);
@@ -1,9 +1,9 @@
1
+ # Hooks Configuration
2
+
1
3
  [![version](https://npmx.dev/api/registry/badge/version/@alexlit/config-hooks)](https://www.npmjs.com/package/@alexlit/config-hooks)
2
4
  [![downloads](https://npmx.dev/api/registry/badge/downloads/@alexlit/config-hooks)](https://npmx.dev/package/@alexlit/config-hooks)
3
5
  [![license](https://npmx.dev/api/registry/badge/license/@alexlit/config-hooks)](LICENSE)
4
6
 
5
- # Hooks Configuration
6
-
7
7
  Готовые конфигурации для git-хуков проекта - три инструмента, которые вместе
8
8
  следят за качеством коммитов:
9
9
 
@@ -1,9 +1,9 @@
1
+ # HTMLLint Configuration
2
+
1
3
  [![version](https://npmx.dev/api/registry/badge/version/@alexlit/config-htmllint)](https://www.npmjs.com/package/@alexlit/config-htmllint)
2
4
  [![downloads](https://npmx.dev/api/registry/badge/downloads/@alexlit/config-htmllint)](https://npmx.dev/package/@alexlit/config-htmllint)
3
5
  [![license](https://npmx.dev/api/registry/badge/license/@alexlit/config-htmllint)](LICENSE)
4
6
 
5
- # HTMLLint Configuration
6
-
7
7
  Готовая конфигурация [linthtml](https://github.com/linthtml/linthtml) - линтера
8
8
  HTML-разметки. Пакет объединяет рекомендованный базовый конфиг
9
9
  `@linthtml/linthtml-config-recommended` с дополнительными правилами (в том числе
@@ -1,9 +1,9 @@
1
+ # Markdownlint Configuration
2
+
1
3
  [![npm version](https://npmx.dev/api/registry/badge/version/@alexlit/config-markdownlint)](https://www.npmjs.com/package/@alexlit/config-markdownlint)
2
4
  [![downloads](https://npmx.dev/api/registry/badge/downloads/@alexlit/config-markdownlint)](https://npmx.dev/package/@alexlit/config-markdownlint)
3
5
  [![license](https://npmx.dev/api/registry/badge/license/@alexlit/config-markdownlint)](LICENSE)
4
6
 
5
- # Markdownlint Configuration
6
-
7
7
  Готовый набор правил
8
8
  [markdownlint](https://github.com/DavidAnson/markdownlint) - линтера
9
9
  Markdown-файлов. Пакет подключается одной строкой через `extends`, чтобы не
@@ -1,9 +1,9 @@
1
+ # NPMLint Configuration
2
+
1
3
  [![version](https://npmx.dev/api/registry/badge/version/@alexlit/config-npmlint)](https://www.npmjs.com/package/@alexlit/config-npmlint)
2
4
  [![downloads](https://npmx.dev/api/registry/badge/downloads/@alexlit/config-npmlint)](https://npmx.dev/package/@alexlit/config-npmlint)
3
5
  [![license](https://npmx.dev/api/registry/badge/license/@alexlit/config-npmlint)](LICENSE)
4
6
 
5
- # NPMLint Configuration
6
-
7
7
  Готовая конфигурация
8
8
  [npm-package-json-lint](https://github.com/tclindner/npm-package-json-lint) -
9
9
  линтера `package.json` файлов. Пакет собирает рекомендованный базовый конфиг
@@ -1,9 +1,9 @@
1
+ # Prettier Configuration
2
+
1
3
  [![version](https://npmx.dev/api/registry/badge/version/@alexlit/config-prettier)](https://www.npmjs.com/package/@alexlit/config-prettier)
2
4
  [![downloads](https://npmx.dev/api/registry/badge/downloads/@alexlit/config-prettier)](https://npmx.dev/package/@alexlit/config-prettier)
3
5
  [![license](https://npmx.dev/api/registry/badge/license/@alexlit/config-prettier)](LICENSE)
4
6
 
5
- # Prettier Configuration
6
-
7
7
  Готовая конфигурация [Prettier](https://prettier.io/) с плагинами для
8
8
  форматирования языков и форматов, которых Prettier не поддерживает из коробки
9
9
  (PHP, SQL, шаблоны, shell-скрипты и т.д.), а также расширений для сортировки
@@ -69,6 +69,10 @@ export default defineConfig([
69
69
  ]);
70
70
  ```
71
71
 
72
+ Скалярные опции заменяют значения плагина, а `plugins` и `overrides` дополняют
73
+ дефолтные списки. Подробнее - в разделе
74
+ [Приоритет настроек](#приоритет-настроек).
75
+
72
76
  ### Общие настройки Prettier
73
77
 
74
78
  Второй аргумент `defineConfig` - общие опции Prettier. Он перебивает настройки
@@ -84,22 +88,70 @@ export default defineConfig([plugins.php()], {
84
88
  });
85
89
  ```
86
90
 
91
+ ### Приоритет настроек
92
+
93
+ Настройки применяются в таком порядке:
94
+
95
+ 1. Базовые опции пакета.
96
+ 2. Конфиги плагинов в порядке массива `defineConfig`.
97
+ 3. Второй аргумент `defineConfig`.
98
+
99
+ Скалярные опции перекрывают друг друга. Коллекции `plugins` и `overrides`
100
+ дополняются, а не заменяются. `plugins` дедуплицируются, поэтому один и тот же
101
+ плагин можно безопасно указать несколько раз.
102
+
103
+ Для `overrides` более позднее правило выигрывает: пользовательские overrides
104
+ идут после дефолтных и перекрывают их при совпадении `files`.
105
+
106
+ ### Правила для отдельных файлов
107
+
108
+ `overrides` из фабрики добавляются к дефолтным. Например, чтобы форматировать
109
+ документацию как обычный Markdown, оставив MDC для остальных файлов:
110
+
111
+ ```js
112
+ // prettier.config.js
113
+ import { defineConfig, plugins } from '@alexlit/config-prettier';
114
+
115
+ export default defineConfig([
116
+ plugins.mdc({
117
+ overrides: [{ files: ['docs/**/*.md'], options: { parser: 'markdown' } }],
118
+ }),
119
+ ]);
120
+ ```
121
+
122
+ Пустой массив `overrides: []` не отключает дефолтные правила. Чтобы
123
+ переопределить поведение, добавьте свой override с теми же `files` - он будет
124
+ применён после дефолтного.
125
+
87
126
  ## Плагины
88
127
 
89
- | Плагин | Что делает | Пакет |
90
- | ----------------------- | ----------------------------------------------- | ------------------------------------------------- |
91
- | `plugins.jsdoc()` | Нормализует JSDoc-комментарии | `prettier-plugin-jsdoc` |
92
- | `plugins.mdc()` | Форматирует MDC-документы (Nuxt Content) | `prettier-plugin-mdc` |
93
- | `plugins.packageJson()` | Сортирует ключи в package.json | `prettier-plugin-packagejson` |
94
- | `plugins.php()` | Форматирует PHP-файлы | `@prettier/plugin-php` |
95
- | `plugins.pug()` | Форматирует Pug-шаблоны с сортировкой атрибутов | `@prettier/plugin-pug` |
96
- | `plugins.ruby()` | Форматирует Ruby и ERB файлы | `@prettier/plugin-ruby` + `prettier-plugin-eruby` |
97
- | `plugins.sh()` | Форматирует shell-скрипты | `prettier-plugin-sh` |
98
- | `plugins.sortJson()` | Рекурсивно сортирует ключи JSON-объектов | `prettier-plugin-sort-json` |
99
- | `plugins.solidity()` | Форматирует контракты Solidity | `prettier-plugin-solidity` |
100
- | `plugins.sql()` | Форматирует SQL-запросы | `prettier-plugin-sql` |
101
- | `plugins.tailwindcss()` | Сортирует утилитарные классы Tailwind CSS | `prettier-plugin-tailwindcss` |
102
- | `plugins.xml()` | Форматирует XML-файлы | `@prettier/plugin-xml` |
128
+ | Плагин | Что делает | Пакет |
129
+ | ----------------------- | ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
130
+ | `plugins.jsdoc()` | Нормализует JSDoc-комментарии | [`prettier-plugin-jsdoc`](https://github.com/hosseinmd/prettier-plugin-jsdoc) |
131
+ | `plugins.mdc()` | Форматирует MDC-документы (Nuxt Content) | [`prettier-plugin-mdc`](https://github.com/so1ve/prettier-plugin-mdc) |
132
+ | `plugins.packageJson()` | Сортирует ключи в package.json | [`prettier-plugin-packagejson`](https://github.com/matzkoh/prettier-plugin-packagejson) |
133
+ | `plugins.php()` | Форматирует PHP-файлы | [`@prettier/plugin-php`](https://github.com/prettier/plugin-php) |
134
+ | `plugins.pug()` | Форматирует Pug-шаблоны с сортировкой атрибутов | [`@prettier/plugin-pug`](https://github.com/prettier/plugin-pug) |
135
+ | `plugins.ruby()` | Форматирует Ruby и ERB файлы | [`@prettier/plugin-ruby`](https://github.com/prettier/plugin-ruby) + [`prettier-plugin-eruby`](https://github.com/ippachi/prettier-plugin-eruby) |
136
+ | `plugins.sh()` | Форматирует shell-скрипты | [`prettier-plugin-sh`](https://github.com/astorije/prettier-plugin-sh) |
137
+ | `plugins.sortJson()` | Рекурсивно сортирует ключи JSON-объектов | [`prettier-plugin-sort-json`](https://github.com/Gudahtt/prettier-plugin-sort-json) |
138
+ | `plugins.solidity()` | Форматирует контракты Solidity | [`prettier-plugin-solidity`](https://github.com/prettier-solidity/prettier-plugin-solidity) |
139
+ | `plugins.sql()` | Форматирует SQL-запросы | [`prettier-plugin-sql`](https://github.com/un-ts/prettier/tree/master/packages/sql) |
140
+ | `plugins.tailwindcss()` | Сортирует утилитарные классы Tailwind CSS | [`prettier-plugin-tailwindcss`](https://github.com/tailwindlabs/prettier-plugin-tailwindcss) |
141
+ | `plugins.xml()` | Форматирует XML-файлы | [`@prettier/plugin-xml`](https://github.com/prettier/plugin-xml) |
142
+
143
+ ## Миграция с v24
144
+
145
+ v25 - breaking-релиз: `plugins` и `overrides`, переданные в фабрику, теперь
146
+ дополняют дефолтные значения, а не заменяют их.
147
+
148
+ | v24 | v25 |
149
+ | --------------------------------------------------------- | ------------------------------------------------ |
150
+ | `plugins.mdc({ plugins: ['custom'] })` заменял MDC-плагин | добавляет `custom` к `prettier-plugin-mdc` |
151
+ | `plugins.mdc({ overrides: [...] })` заменял MDC-override | добавляет overrides после дефолтного |
152
+ | `plugins.ruby({ overrides: [] })` отключал ERB-override | не отключает; добавьте override для `*.html.erb` |
153
+
154
+ Скалярные опции работают как раньше: значения из `options` заменяют дефолтные.
103
155
 
104
156
  ## Миграция с v23
105
157
 
@@ -12,7 +12,11 @@ export interface JsdocOptions {
12
12
 
13
13
  /**
14
14
  * Plugin factories. Every plugin is connected explicitly: pass
15
- * `plugins.<name>()` to `defineConfig`
15
+ * `plugins.<name>()` to `defineConfig`.
16
+ *
17
+ * Collection options (`overrides`, `plugins`) are appended to the defaults:
18
+ * `plugins` are deduplicated and later `overrides` win. Other options replace
19
+ * default values.
16
20
  */
17
21
  export interface Plugins {
18
22
  /** @see prettier-plugin-jsdoc */
@@ -83,6 +87,10 @@ export declare const plugins: Plugins;
83
87
  * });
84
88
  * ```
85
89
  *
90
+ * Base options are replaced by plugin options and `options`. Collection options
91
+ * (`overrides`, `plugins`) are appended: `plugins` are deduplicated and later
92
+ * `overrides` win.
93
+ *
86
94
  * @param pluginConfigs Plugin configs, e.g. `[plugins.php()]`
87
95
  * @param options Base prettier options (highest precedence)
88
96
  */
@@ -10,6 +10,20 @@ import { sortJson } from './plugins/sort-json.js';
10
10
  import { sql } from './plugins/sql.js';
11
11
  import { tailwindcss } from './plugins/tailwindcss.js';
12
12
  import { xml } from './plugins/xml.js';
13
+ import { mergeConfigs } from './utils/merge-configs.js';
14
+
15
+ const DEFAULTS = {
16
+ bracketSameLine: false,
17
+ endOfLine: 'lf',
18
+ objectWrap: 'collapse',
19
+ proseWrap: 'always',
20
+ quoteProps: 'consistent',
21
+ singleAttributePerLine: true,
22
+ singleQuote: true,
23
+ tabWidth: 2,
24
+ trailingComma: 'all',
25
+ vueIndentScriptAndStyle: true,
26
+ };
13
27
 
14
28
  /**
15
29
  * Фабрики плагинов. Каждый плагин подключается явно: передайте
@@ -45,6 +59,10 @@ export const plugins = {
45
59
  * );
46
60
  * ```
47
61
  *
62
+ * Базовые опции заменяются опциями плагинов и `options`. Коллекции `overrides`
63
+ * и `plugins` дополняются, `plugins` дедуплицируются, более поздние `overrides`
64
+ * выигрывают.
65
+ *
48
66
  * @param {import('prettier').Config[]} pluginConfigs Конфиги плагинов, напр.
49
67
  * `[plugins.php()]`
50
68
  * @param {import('prettier').Config} options Базовые опции Prettier (наивысший
@@ -52,31 +70,5 @@ export const plugins = {
52
70
  *
53
71
  * @returns {import('prettier').Config} Конфигурация Prettier
54
72
  */
55
- export const defineConfig = (pluginConfigs = [], options = {}) => {
56
- const config = {
57
- bracketSameLine: false,
58
- endOfLine: 'lf',
59
- objectWrap: 'collapse',
60
- proseWrap: 'always',
61
- quoteProps: 'consistent',
62
- singleAttributePerLine: true,
63
- singleQuote: true,
64
- tabWidth: 2,
65
- trailingComma: 'all',
66
- vueIndentScriptAndStyle: true,
67
-
68
- // конфиги плагинов перекрывают базовые опции, а пользовательские опции
69
- // имеют наивысший приоритет
70
- ...Object.assign({}, ...pluginConfigs, options),
71
- };
72
-
73
- const sources = [...pluginConfigs, options];
74
-
75
- return {
76
- ...config,
77
-
78
- // `overrides` и `plugins` конкатенируются, а не заменяются
79
- overrides: sources.flatMap((source) => source.overrides ?? []),
80
- plugins: [...new Set(sources.flatMap((source) => source.plugins ?? []))],
81
- };
82
- };
73
+ export const defineConfig = (pluginConfigs = [], options = {}) =>
74
+ mergeConfigs(DEFAULTS, ...pluginConfigs, options);
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alexlit/config-prettier",
3
- "version": "24.1.3",
3
+ "version": "25.0.0",
4
4
  "private": false,
5
5
  "description": "prettier config",
6
6
  "keywords": [
@@ -28,7 +28,8 @@
28
28
  "README.md",
29
29
  "index.d.ts",
30
30
  "index.js",
31
- "plugins"
31
+ "plugins",
32
+ "utils"
32
33
  ],
33
34
  "scripts": {
34
35
  "ou": "../../scripts/ou.sh",
@@ -1,16 +1,22 @@
1
+ import { mergeConfigs } from '../utils/merge-configs.js';
2
+
3
+ const DEFAULTS = {
4
+ jsdocCommentLineStrategy: 'singleLine',
5
+ jsdocSeparateReturnsFromParam: true,
6
+ jsdocSeparateTagGroups: true,
7
+ plugins: ['prettier-plugin-jsdoc'],
8
+ };
9
+
1
10
  /**
2
11
  * Нормализует JSDoc-комментарии
3
12
  *
4
- * @param {Partial<import('prettier').Config>} [options]
13
+ * @param {Partial<import('prettier').Config>} [options] - Опции, накладываемые
14
+ * поверх значений по умолчанию. Коллекции (`overrides`, `plugins`)
15
+ * дополняются, `plugins` дедуплицируются, более поздние `overrides`
16
+ * выигрывают, остальные поля заменяются
5
17
  *
6
18
  * @returns {import('prettier').Config}
7
19
  *
8
20
  * @see [prettier-plugin-jsdoc](https://github.com/hosseinmd/prettier-plugin-jsdoc)
9
21
  */
10
- export const jsdoc = (options = {}) => ({
11
- jsdocCommentLineStrategy: 'singleLine',
12
- jsdocSeparateReturnsFromParam: true,
13
- jsdocSeparateTagGroups: true,
14
- plugins: ['prettier-plugin-jsdoc'],
15
- ...options,
16
- });
22
+ export const jsdoc = (options = {}) => mergeConfigs(DEFAULTS, options);
@@ -1,14 +1,20 @@
1
+ import { mergeConfigs } from '../utils/merge-configs.js';
2
+
3
+ const DEFAULTS = {
4
+ overrides: [{ files: ['*.md'], options: { parser: 'mdc' } }],
5
+ plugins: ['prettier-plugin-mdc'],
6
+ };
7
+
1
8
  /**
2
9
  * Форматирует MDC-документы (Nuxt Content)
3
10
  *
4
- * @param {Partial<import('prettier').Config>} [options]
11
+ * @param {Partial<import('prettier').Config>} [options] - Опции, накладываемые
12
+ * поверх значений по умолчанию. Коллекции (`overrides`, `plugins`)
13
+ * дополняются, `plugins` дедуплицируются, более поздние `overrides`
14
+ * выигрывают, остальные поля заменяются
5
15
  *
6
16
  * @returns {import('prettier').Config}
7
17
  *
8
18
  * @see [prettier-plugin-mdc](https://github.com/so1ve/prettier-plugin-mdc)
9
19
  */
10
- export const mdc = (options = {}) => ({
11
- overrides: [{ files: ['*.md'], options: { parser: 'mdc' } }],
12
- plugins: ['prettier-plugin-mdc'],
13
- ...options,
14
- });
20
+ export const mdc = (options = {}) => mergeConfigs(DEFAULTS, options);
@@ -1,13 +1,17 @@
1
+ import { mergeConfigs } from '../utils/merge-configs.js';
2
+
3
+ const DEFAULTS = { plugins: ['prettier-plugin-packagejson'] };
4
+
1
5
  /**
2
6
  * Сортирует ключи в package.json
3
7
  *
4
- * @param {Partial<import('prettier').Config>} [options]
8
+ * @param {Partial<import('prettier').Config>} [options] - Опции, накладываемые
9
+ * поверх значений по умолчанию. Коллекции (`overrides`, `plugins`)
10
+ * дополняются, `plugins` дедуплицируются, более поздние `overrides`
11
+ * выигрывают, остальные поля заменяются
5
12
  *
6
13
  * @returns {import('prettier').Config}
7
14
  *
8
15
  * @see [prettier-plugin-packagejson](https://github.com/matzkoh/prettier-plugin-packagejson)
9
16
  */
10
- export const packageJson = (options = {}) => ({
11
- plugins: ['prettier-plugin-packagejson'],
12
- ...options,
13
- });
17
+ export const packageJson = (options = {}) => mergeConfigs(DEFAULTS, options);
@@ -1,13 +1,17 @@
1
+ import { mergeConfigs } from '../utils/merge-configs.js';
2
+
3
+ const DEFAULTS = { plugins: ['@prettier/plugin-php'] };
4
+
1
5
  /**
2
6
  * Форматирует PHP-файлы
3
7
  *
4
- * @param {Partial<import('prettier').Config>} [options]
8
+ * @param {Partial<import('prettier').Config>} [options] - Опции, накладываемые
9
+ * поверх значений по умолчанию. Коллекции (`overrides`, `plugins`)
10
+ * дополняются, `plugins` дедуплицируются, более поздние `overrides`
11
+ * выигрывают, остальные поля заменяются
5
12
  *
6
13
  * @returns {import('prettier').Config}
7
14
  *
8
15
  * @see [plugin-php](https://github.com/prettier/plugin-php)
9
16
  */
10
- export const php = (options = {}) => ({
11
- plugins: ['@prettier/plugin-php'],
12
- ...options,
13
- });
17
+ export const php = (options = {}) => mergeConfigs(DEFAULTS, options);
@@ -1,17 +1,23 @@
1
+ import { mergeConfigs } from '../utils/merge-configs.js';
2
+
3
+ const DEFAULTS = {
4
+ plugins: ['@prettier/plugin-pug'],
5
+ pugCommentPreserveSpaces: 'trim-all',
6
+ pugSingleQuote: false,
7
+ pugSortAttributes: 'asc',
8
+ pugWrapAttributesThreshold: 3,
9
+ };
10
+
1
11
  /**
2
12
  * Форматирует Pug-шаблоны с сортировкой атрибутов и одинарными кавычками
3
13
  *
4
- * @param {Partial<import('prettier').Config>} [options]
14
+ * @param {Partial<import('prettier').Config>} [options] - Опции, накладываемые
15
+ * поверх значений по умолчанию. Коллекции (`overrides`, `plugins`)
16
+ * дополняются, `plugins` дедуплицируются, более поздние `overrides`
17
+ * выигрывают, остальные поля заменяются
5
18
  *
6
19
  * @returns {import('prettier').Config}
7
20
  *
8
21
  * @see [plugin-pug](https://github.com/prettier/plugin-pug)
9
22
  */
10
- export const pug = (options = {}) => ({
11
- plugins: ['@prettier/plugin-pug'],
12
- pugCommentPreserveSpaces: 'trim-all',
13
- pugSingleQuote: false,
14
- pugSortAttributes: 'asc',
15
- pugWrapAttributesThreshold: 3,
16
- ...options,
17
- });
23
+ export const pug = (options = {}) => mergeConfigs(DEFAULTS, options);