@astral/commitlint-config 1.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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +92 -0
  3. package/config.js +93 -0
  4. package/package.json +18 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Astral.Soft
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # @astral/commitlint-config
2
+
3
+ # Usage
4
+
5
+ ## Installation
6
+
7
+ ### Npm
8
+ ```shell
9
+ npm i commitlint @astral/commitlint-config --save-dev
10
+ ```
11
+
12
+ ### Yarn
13
+ ```shell
14
+ yarn add commitlint @astral/commitlint-config -D
15
+ ```
16
+
17
+ ### Configuration
18
+ ```commitlint.config.js```
19
+ ```js
20
+ const { createConfig } = require('@astral/commitlint-config');
21
+
22
+ module.exports = createConfig({
23
+ scopes: ['ui', 'server'],
24
+ ticketPrefix: 'UIKIT',
25
+ });
26
+ ```
27
+
28
+ ```.huskyrc```
29
+ ```json
30
+ {
31
+ "hooks": {
32
+ "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
33
+ }
34
+ }
35
+ ```
36
+
37
+ ### Message example
38
+ #### Valid
39
+ ```feat(UIKIT-222,ui): Title```
40
+ ```feat: Title```
41
+ ```feat(UIKIT-222): Title```
42
+
43
+ #### Invalid
44
+ ```feat(UIKIT222): Title```
45
+ ```feat(unknown): Title```
46
+
47
+ # Format
48
+
49
+ ```${ENUM}(SCOPE|TASK): Description```
50
+
51
+ Default ENUM:
52
+ - feat - добавлена новая фича. Можно связать с релизом minor версии
53
+ - bug - исправлена ошибка. Можно связать с релизом patch версии
54
+ - wip (work in progress) - промежуточные изменения
55
+ - refactor - произведен рефакторинг. Можно связать с релизом patch версии
56
+ - doc - внесены изменения в .md файлы. Можно связать с релизом patch версии
57
+ - story - внесены изменения в storybook.
58
+ - build - внесены изменения в сборке пакетов. Можно связать с релизом patch версии
59
+ - chore - внесены изменения в настройку окружения проекта (линтеры, ci...).
60
+ - revert - удалены ранее внесенные изменения
61
+ - style - написаны или изменены стили проекта
62
+ - test - написаны или изменены тесты проекта
63
+ - major - breaking changes. Полезен для пакетов. Можно связать с релизом major версии
64
+
65
+ # API
66
+ ## createConfig
67
+ ```ts
68
+ const { createConfig } = require('@astral/commitlint-config');
69
+
70
+ type Params = {
71
+ /**
72
+ * Список доступных scopes.
73
+ * @example
74
+ * // createConfig({ scopes: ['server', 'ui'], ticketPrefix: 'UIKIT' })
75
+ */
76
+ scopes?: string[];
77
+ /**
78
+ * Название префикса задач, данный префикс будет доступен в scope.
79
+ * @example
80
+ * // createConfig({ ticketPrefix: 'UIKIT' })
81
+ */
82
+ ticketPrefix: string;
83
+ /**
84
+ * Список доступных type. Дефолтное значение указано в разделе Format
85
+ * @example
86
+ * // createConfig({ typeEnum: ['feat', 'ci'], ticketPrefix: 'UIKIT', })
87
+ */
88
+ typeEnum?: string[];
89
+ };
90
+
91
+ createConfig(params: Params);
92
+ ```
package/config.js ADDED
@@ -0,0 +1,93 @@
1
+ const DEFAULT_TYPE_ENUM = [
2
+ 'feat',
3
+ 'bug',
4
+ 'wip',
5
+ 'refactor',
6
+ 'doc',
7
+ 'build',
8
+ 'chore',
9
+ 'revert',
10
+ 'style',
11
+ 'test',
12
+ 'major',
13
+ 'story',
14
+ ];
15
+
16
+ /**
17
+ * Создает commitlint config
18
+ * @param {Object} params - Параметры инициализации конфига.
19
+ * @param {string[]} [params.scopes=[]] - Список доступных scopes.
20
+ * @param {string} params.ticketPrefix - Название префикса или список названий префиксов задач, данный префикс будет доступен в scope.
21
+ * @param {string[]} [params.typeEnum=[]] - Список доступных type.
22
+ * @example
23
+ * // createConfig({ scopes: ['server', 'ui'], ticketPrefix: 'UIKIT' })
24
+ */
25
+ const createConfig = ({
26
+ scopes = [],
27
+ ticketPrefix,
28
+ typeEnum = DEFAULT_TYPE_ENUM,
29
+ }) => ({
30
+ extends: ['@commitlint/config-conventional'],
31
+
32
+ plugins: ['commitlint-plugin-function-rules'],
33
+
34
+ rules: {
35
+ // Тело коммита должно начинаться с пустой строки
36
+ 'body-leading-blank': [2, 'always'],
37
+
38
+ // Нижний колонтитул коммита должен начинаться с пустой строки
39
+ 'footer-leading-blank': [2, 'always'],
40
+
41
+ // Максимальная длина заголовка
42
+ 'header-max-length': [2, 'always', 120],
43
+
44
+ // Описание не может быть пустым
45
+ 'subject-empty': [2, 'never'],
46
+
47
+ // Описание не должно заканчиваться '.'
48
+ 'subject-full-stop': [2, 'never', '.'],
49
+
50
+ // Описание должно начинаться с большой буквы
51
+ 'subject-case': [2, 'always', 'sentence-case'],
52
+
53
+ // Тип всегда только в нижнем регистре
54
+ 'type-case': [2, 'always', 'lower-case'],
55
+
56
+ // Тип не может быть пустым
57
+ 'type-empty': [2, 'never'],
58
+
59
+ // Перечислим все возможные варианты коммитов
60
+ 'type-enum': [2, 'always', typeEnum],
61
+
62
+ // функция вызывается при проверке scopes
63
+ 'function-rules/scope-enum': [
64
+ 2,
65
+ 'always',
66
+ ({ scope }) => {
67
+ const ticketPrefixes = Array.isArray(ticketPrefix)
68
+ ? ticketPrefix
69
+ : [ticketPrefix];
70
+
71
+ const isTicketScope = ticketPrefixes.some((prefix) =>
72
+ scope?.startsWith(`${prefix}-`),
73
+ );
74
+
75
+ if (!scope || scopes.includes(scope) || isTicketScope) {
76
+ return [true];
77
+ }
78
+
79
+ const formattedTickets = ticketPrefixes.map(
80
+ (ticket) => `${ticket}-XXXX`,
81
+ );
82
+
83
+ const scopesEnumsMessage = [...scopes, ...formattedTickets].join(', ');
84
+
85
+ return [false, `scope must be one of [${scopesEnumsMessage}]`];
86
+ },
87
+ ],
88
+ },
89
+ });
90
+
91
+ module.exports = {
92
+ createConfig,
93
+ };
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "@astral/commitlint-config",
3
+ "main": "./config.js",
4
+ "dependencies": {
5
+ "@commitlint/config-conventional": "^19.8.1",
6
+ "commitlint-plugin-function-rules": "^4.0.1"
7
+ },
8
+ "peerDependencies": {
9
+ "commitlint": ">=16.x.x"
10
+ },
11
+ "version": "1.0.0",
12
+ "author": "Astral.Soft",
13
+ "license": "MIT",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://git.astralnalog.ru/frontend.shared/commitlint-config"
17
+ }
18
+ }