arui-presets-lint 8.0.0-beta.9 → 8.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
@@ -18,7 +18,7 @@
18
18
 
19
19
  Установить библиотеку в проект нужно как dev dependency:
20
20
 
21
- ```bash
21
+ ```sh
22
22
  yarn add -D arui-presets-lint
23
23
  ```
24
24
 
@@ -48,28 +48,103 @@
48
48
  ```json
49
49
  {
50
50
  "scripts": {
51
- "lint:css": "arui-presets-lint css",
51
+ "lint:styles": "arui-presets-lint styles",
52
52
  "lint:scripts": "arui-presets-lint scripts",
53
- "lint": "arui-presets-lint lint",
54
- "lint:fix": "arui-presets-lint fix",
53
+ "format": "arui-presets-lint format",
54
+ "format:check": "arui-presets-lint format:check",
55
+ "lint": "yarn lint:styles && yarn lint:scripts && yarn format:check",
56
+ "lint:fix": "yarn lint:styles --fix && yarn lint:scripts --fix && yarn format"
55
57
  }
56
58
  }
57
59
  ```
58
60
 
59
- Если eslint/stylelint/prettier затрагивают файлы, над которыми вы не имеете контроль, вы можете исключить
60
- их с помощью [.eslintignore](https://eslint.org/docs/latest/user-guide/configuring/ignoring-code#the-eslintignore-file) / [.stylelintignore](https://stylelint.io/user-guide/ignore-code/#files-entirely) / [.prettierignore](https://prettier.io/docs/en/ignore.html#ignoring-files-prettierignore)
61
+ Чтобы eslint / stylelint / prettier не проверял конкретные файлы и папки, можно исключить их с помощью файлов .eslintignore / .stylelintignore / .prettierignore. Прописывать там файлы, которые уже есть в .gitignore не требуется!
61
62
 
62
63
  Для запуска eslint/stylelint рекомендуется использовать флаг [--max-warnings](https://eslint.org/docs/latest/user-guide/command-line-interface#--max-warnings), который позволяет ограничить количество возникающих предупреждений.
63
64
 
65
+ Пример такой конфигурации:
66
+ ```json
67
+ {
68
+ "scripts": {
69
+ "lint:styles": "arui-presets-lint styles --max-warnings=0",
70
+ "lint:scripts": "arui-presets-lint scripts --max-warnings=0",
71
+ ...
72
+ }
73
+ }
64
74
  ```
65
75
 
66
- ## Конфигурация [lefthook](https://github.com/evilmartians/lefthook)
76
+ ## Настройка [lefthook](https://github.com/evilmartians/lefthook)
77
+
78
+ При установке библиотеки в корне проекта создался файл lefthook.yml,
79
+ он должен содержать следующее:
67
80
 
68
81
  ```yaml
69
82
  extends:
70
- - arui-presets-lint/lefthook/index.yml
83
+ - ./node_modules/arui-presets-lint/lefthook/index.yml
71
84
  ```
72
85
 
86
+ Этот конфиг можно расширить специфичными для вашего проекта настройками, см. [документацию](https://github.com/evilmartians/lefthook/blob/master/docs/configuration.md) Примеры такого расширения:
87
+
88
+ ```yml
89
+ extends:
90
+ - ./node_modules/arui-presets-lint/lefthook/index.yml
91
+
92
+ # Добавить сборку typescript на pre-commit:
93
+ pre-commit:
94
+ commands:
95
+ check-ts:
96
+ run: npx --no-install tsc --noEmit
97
+
98
+ # Запустить тесты, относящиеся к измененному файлу:
99
+ run-tests:
100
+ glob: '*.{js,ts,jsx,tsx,mts,mjs,cjs,cts}'
101
+ run: npx --no-install jest --findRelatedTests --passWithNoTests {staged_files}
102
+
103
+ # Запустить команду 'lint' на pre-push:
104
+ pre-push:
105
+ commands:
106
+ run-lint:
107
+ run: yarn lint
108
+ ```
109
+
110
+
111
+ ## Гибкая конфигурация
112
+
113
+ Так как `yarn run` в yarn 2+ не поддерживает возможность запускать бинарные файлы, которые не установлены как прямые зависимости, а `yarn dlx` не умеет запускать бинарники без скачивания его из npm, существует возможность это сделать через вызов `npx --no-install ...`:
114
+
115
+ ```sh
116
+ # Применить конфигурацию lefthook:
117
+ npx --no-install lefthook install
118
+
119
+ # Вызов prettier, для того чтобы отформатировать только js и jsx файлы:
120
+ npx --no-install prettier --write "./**/*.{js,jsx}" --no-error-on-unmatched-pattern --cache
121
+
122
+ # Вызов eslint, для того чтобы проверить только js и jsx файлы:
123
+ npx --no-install eslint "**/*.{js,jsx}" --ext .js,.jsx --ignore-pattern=.gitignore,.eslintignore --cache --cache-location="./node_modules/.cache/eslint/.eslintcache"
124
+ ```
125
+
126
+ Таким образом можно гибко настраивать поведение линтеров для вашего проекта, если по какой-то причине стандартная конфигурация вам не подходит.
127
+
128
+ ## Дебаг
129
+ Если нужно увидеть в консоли чему именно соответствует алиас в cli-утилите, нужно запустить arui-presets-lint с флагом --echo, например:
130
+ ```sh
131
+ yarn arui-presets-lint --echo format
132
+ # >> prettier --write "./**/*.{ts,tsx,js,jsx,mjs,mts,cjs,cts,css,json}" --no-error-on-unmatched-pattern --cache
133
+ ```
134
+
135
+ Если нужно посмотреть, какой именно конфиг применяется в текущем проекте:
136
+ ```sh
137
+ # eslint:
138
+ npx --no-install eslint --print-config file.tsx > eslintconfig.json
139
+
140
+ # stylelint:
141
+ npx --no-install stylelint --print-config file.css > stylelintconfig.json
142
+
143
+ # commitlint:
144
+ npx --no-install commitlint --print-config > commitlintconfig.txt
145
+ ```
146
+
147
+
73
148
  ## Настройка IDE:
74
149
 
75
150
  1. Включить ESLint
@@ -1,5 +1,78 @@
1
- Для обновления библиотеки с версии ниже чем 8.0.0, в проекте нужно выполнить команду:
1
+ # Гид по миграции на arui-presets-lint@8
2
+
3
+ ## Введение
4
+ Обновление содержит в себе множество изменений, которые позволяют работать с конфигурацией линтеров в проектах проще. Ключевые изменения:
5
+ - Поставляется готовая конфигурация lefthook - инструмента, который заменяет lint-staged и husky
6
+ - Больше никаких peer dependency - работа с ними вызывала боль, инструменты по их автоматической установке не работают в yarn 4. Никто больше не сможет сломать вашу конфигурацию случайным поднятием зависимости
7
+ - CLI для запуска команд позволяет не писать копипасту в каждом проекте
8
+ - Новые решения гибкие - возможность писать собственные команды остается, как и возможность расширить конфигурацию lefthook (см [README](./README.md))
9
+
10
+ 1. Для начала нужно выполнить команду:
2
11
 
3
12
  ```bash
4
- yarn remove eslint eslint-config-airbnb eslint-config-airbnb-typescript eslint-config-prettier eslint-import-resolver-typescript eslint-plugin-cypress eslint-plugin-dirnames eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-simple-import-sort eslint-plugin-unicorn lint-staged prettier stylelint @typescript-eslint/parser @typescript-eslint/eslint-plugin kebab-case
13
+ yarn remove eslint eslint-config-airbnb eslint-config-airbnb-typescript eslint-config-prettier eslint-import-resolver-typescript eslint-plugin-cypress eslint-plugin-dirnames eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-simple-import-sort eslint-plugin-unicorn lint-staged prettier stylelint @typescript-eslint/parser @typescript-eslint/eslint-plugin stylelint-config-prettier husky kebab-case
14
+ ```
15
+ -- отмечу, что никаких зависимостей с плагинами stylelint/eslint в проекте быть не должно, кроме тех, которые использует ваш локальный конфиг
16
+
17
+ 2. Удалить конфигурации husky и lint-staged (могут находится в .husky, .huskyrc.js, package.json.husky, .lintstagedrc.js, package.json.lint-staged, итп)
18
+
19
+ 3. Добавить в lefthook.yml следующее:
20
+ ```yml
21
+ extends:
22
+ - ./node_modules/arui-presets-lint/lefthook/index.yml
23
+ ```
24
+
25
+ В этот файл нужно дописать конфигурацию, которая присутствует в ваших текущих lint-staged/husky настройках, но отсутствует в `arui-presets-lint/lefthook/index.yml` см. [документацию](https://github.com/evilmartians/lefthook/blob/master/docs/configuration.md) Например:
26
+
27
+ ```yml
28
+ extends:
29
+ - ./node_modules/arui-presets-lint/lefthook/index.yml
30
+
31
+ # Добавить сборку typescript на pre-commit:
32
+ pre-commit:
33
+ commands:
34
+ check-ts:
35
+ run: npx --no-install tsc --noEmit
36
+
37
+ # Запустить тесты, относящиеся к измененному файлу:
38
+ run-tests:
39
+ glob: '*.{js,ts,jsx,tsx,mts,mjs,cjs,cts}'
40
+ run: npx --no-install jest --findRelatedTests --passWithNoTests {staged_files}
41
+
42
+ # Запустить команду 'lint' на pre-push:
43
+ pre-push:
44
+ commands:
45
+ run-lint:
46
+ run: yarn lint
5
47
  ```
48
+
49
+
50
+ 4. Выполнить следующую команду:
51
+ ```
52
+ npx --no-install lefthook install
53
+ ```
54
+ чтобы установить новую конфигурацию git-hooks. Отмечу, что в библиотеке lefthook есть скрипт, который делает это автоматически при каждой установке библиотеки arui-presets-lint.
55
+
56
+ 5. Поменять команды для запуска в package.json.scripts, они должны выглядить следующим образом:
57
+
58
+ ```json
59
+ {
60
+ "scripts": {
61
+ "lint:styles": "arui-presets-lint styles",
62
+ "lint:scripts": "arui-presets-lint scripts",
63
+ "format": "arui-presets-lint format",
64
+ "format:check": "arui-presets-lint format:check",
65
+ "lint": "yarn lint:styles && yarn lint:scripts && yarn format:check",
66
+ "lint:fix": "yarn lint:styles --fix && yarn lint:scripts --fix && yarn format"
67
+ }
68
+ }
69
+ ```
70
+
71
+ 6. Выполнить команду ```yarn lint:fix```, и исправить возникающие ошибки
72
+
73
+ ## Возможные проблемы и способы их решения:
74
+
75
+ > Q: Получаю ошибку `node_modules/.bin/prettier: Permission denied`
76
+
77
+ > A: Это плавающая проблема с установкой библиотеки prettier, которая решается командой: `chmod +x ./node_modules/.bin/prettier`
78
+ Происходит такое только на системах macOS [issue](https://github.com/prettier/prettier/issues/15164)
@@ -4,13 +4,13 @@
4
4
  pre-commit:
5
5
  parallel: true
6
6
  commands:
7
- js:
7
+ check-scripts:
8
8
  glob: '*.{js,ts,jsx,tsx,mts,mjs,cjs,cts}'
9
9
  run: npx --no-install prettier --write {staged_files} --cache && npx --no-install eslint {staged_files} --cache --cache-location="./node_modules/.cache/eslint/.eslintcache" && git add {staged_files}
10
- css:
10
+ check-styles:
11
11
  glob: '*.{css}'
12
12
  run: npx --no-install prettier --write {staged_files} --cache && npx --no-install stylelint {staged_files} --cache --cache-location="./node_modules/.cache/stylelint/.stylelintcache" && git add {staged_files}
13
- json:
13
+ check-json:
14
14
  glob: '*.{json}'
15
15
  run: npx --no-install prettier --write {staged_files} --cache && git add {staged_files}
16
16
  commit-msg:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arui-presets-lint",
3
- "version": "8.0.0-beta.9",
3
+ "version": "8.0.0",
4
4
  "description": "Config files for arui-apps",
5
5
  "author": "core-ds contributors",
6
6
  "license": "MIT",
@@ -9,7 +9,6 @@
9
9
  "@alfalab/stylelint-core-vars": "1.6.0",
10
10
  "@commitlint/cli": "18.4.4",
11
11
  "@commitlint/config-conventional": "18.4.4",
12
- "@evilmartians/lefthook": "1.8.1",
13
12
  "@typescript-eslint/eslint-plugin": "7.18.0",
14
13
  "@typescript-eslint/parser": "7.18.0",
15
14
  "eslint": "8.57.0",
@@ -27,6 +26,7 @@
27
26
  "eslint-plugin-unicorn": "55.0.0",
28
27
  "execa": "9.4.1",
29
28
  "kebab-case": "1.0.0",
29
+ "lefthook": "1.8.1",
30
30
  "prettier": "3.3.3",
31
31
  "stylelint": "16.10.0"
32
32
  },
@@ -46,7 +46,7 @@
46
46
  "typescript": "5.5.4"
47
47
  },
48
48
  "scripts": {
49
- "test": "yarn lint:scripts && eslint-config-prettier ./eslint/index.js && yarn lint:styles && yarn format:check",
49
+ "test": "eslint-config-prettier ./eslint/index.js && yarn lint",
50
50
  "lint": "yarn lint:styles && yarn lint:scripts && yarn format:check",
51
51
  "lint:fix": "yarn lint:styles --fix && yarn lint:scripts --fix && yarn format",
52
52
  "lint:styles": "node ./cli/index.mjs styles",