@mednet/lint-config 0.0.0-stage → 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ФГБУ «ЦНИИОИЗ» Минздрава России
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 CHANGED
@@ -1,3 +1,69 @@
1
- # Temporary Holding Version
1
+ # @mednet/lint-config
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ ESLint и stylelint для проектов ЦНИИОИЗ: не пускают в проект чужие UI-библиотеки, примитивы мимо `@mednet/ui`, иконки не из `lucide-react` и цвета вне токенов бренда. Только встроенные правила — без своих плагинов.
4
+
5
+ ## ESLint (Next 16)
6
+
7
+ ```bash
8
+ npm i -D eslint@^9 eslint-config-next @mednet/lint-config
9
+ ```
10
+
11
+ `eslint.config.mjs` — после конфигов Next:
12
+
13
+ ```js
14
+ import { defineConfig, globalIgnores } from 'eslint/config';
15
+ import nextVitals from 'eslint-config-next/core-web-vitals';
16
+ import nextTs from 'eslint-config-next/typescript';
17
+ import mednet from '@mednet/lint-config/eslint';
18
+
19
+ export default defineConfig([
20
+ ...nextVitals,
21
+ ...nextTs,
22
+ ...mednet,
23
+ globalIgnores(['.next/**', 'out/**', 'build/**', 'next-env.d.ts']),
24
+ ]);
25
+ ```
26
+
27
+ Свои запреты **дополняйте**, а не объявляйте заново — правило с тем же именем заменяет наше целиком:
28
+
29
+ ```js
30
+ import mednet, { restrictedImports } from '@mednet/lint-config/eslint';
31
+
32
+ // …после ...mednet:
33
+ {
34
+ rules: {
35
+ 'no-restricted-imports': [
36
+ 'error',
37
+ { ...restrictedImports, paths: [...restrictedImports.paths, { name: 'lodash', message: 'Берите lodash-es' }] },
38
+ ],
39
+ },
40
+ },
41
+ ```
42
+
43
+ ## stylelint
44
+
45
+ ```bash
46
+ npm i -D stylelint @mednet/lint-config
47
+ ```
48
+
49
+ `stylelint.config.mjs`:
50
+
51
+ ```js
52
+ /** @type {import('stylelint').Config} */
53
+ const config = {
54
+ extends: ['@mednet/lint-config/stylelint'],
55
+ ignoreFiles: ['.next/**', 'out/**', 'build/**'],
56
+ };
57
+
58
+ export default config;
59
+ ```
60
+
61
+ `package.json`: `"lint:css": "stylelint \"**/*.css\" --allow-empty-input"`. Не подключайте `stylelint-config-standard`: на Tailwind v4 он даёт ложные ошибки.
62
+
63
+ ## Что не ловится
64
+
65
+ Цвет через переменную (`const c = '#fff'; style={{ color: c }}`), именованные цвета в `style`, `@apply bg-[#fff]` в CSS, динамический `import('antd')`. Это ловит ревью.
66
+
67
+ ## Лицензия
68
+
69
+ MIT, © 2026 ФГБУ «ЦНИИОИЗ» Минздрава России.
package/eslint.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import type { Linter } from 'eslint';
2
+
3
+ export declare const restrictedImports: {
4
+ paths: { name: string; message: string }[];
5
+ patterns: { group: string[]; message: string }[];
6
+ };
7
+ export declare const restrictedSyntax: { selector: string; message: string }[];
8
+
9
+ declare const config: Linter.Config[];
10
+ export default config;
package/eslint.js ADDED
@@ -0,0 +1,92 @@
1
+ // @mednet/lint-config/eslint — flat config: только правила ядра ESLint, без парсера и плагинов.
2
+ // Парсер (typescript-eslint для .ts/.tsx) приходит из eslint-config-next; ставьте этот массив после него.
3
+ // Правила проекта с теми же именами ЗАМЕНЯЮТ наши (ESLint не сливает опции) — расширяйте
4
+ // через экспортируемые restrictedImports / restrictedSyntax.
5
+
6
+ // ---------- Импорты ----------
7
+
8
+ const UI_KIT =
9
+ 'Сторонние UI-библиотеки в проектах ЦНИИОИЗ не используются: компоненты берите из @mednet/ui (список — node_modules/@mednet/ui/llms.md).';
10
+ const PRIMITIVES =
11
+ 'Примитивы напрямую не импортируйте — только через @mednet/ui (например, @mednet/ui/dialog). Композиция — через проп render, не asChild.';
12
+ const ICONS = 'Иконки — только lucide-react.';
13
+
14
+ /** Опции правила no-restricted-imports; экспортируются, чтобы проект мог дополнить список. */
15
+ export const restrictedImports = {
16
+ paths: [
17
+ { name: 'antd', message: UI_KIT },
18
+ { name: 'bootstrap', message: UI_KIT },
19
+ { name: 'react-bootstrap', message: UI_KIT },
20
+ { name: 'radix-ui', message: PRIMITIVES },
21
+ // @base-ui/react не дублируем в paths: его ловит паттерн '@base-ui/*' (иначе два сообщения на строку)
22
+ { name: 'react-icons', message: ICONS },
23
+ { name: '@tabler/icons-react', message: ICONS },
24
+ ],
25
+ patterns: [
26
+ {
27
+ group: ['antd/*', 'bootstrap/*', 'react-bootstrap/*', '@mui/*', '@mantine/*', '@chakra-ui/*'],
28
+ message: UI_KIT,
29
+ },
30
+ {
31
+ group: ['radix-ui/*', '@radix-ui/*', '@base-ui/*', '@base-ui-components/*'],
32
+ message: PRIMITIVES,
33
+ },
34
+ {
35
+ group: [
36
+ 'react-icons/*',
37
+ '@tabler/icons-react/*',
38
+ '@heroicons/*',
39
+ '@fortawesome/*',
40
+ '@phosphor-icons/*',
41
+ '@hugeicons/*',
42
+ ],
43
+ message: ICONS,
44
+ },
45
+ ],
46
+ };
47
+
48
+ // ---------- Литеральные цвета ----------
49
+ // Регулярки вставляются в селекторы esquery как /…/i. В них нельзя использовать «/»
50
+ // (esquery заканчивает регулярку на первом «/»), флаги — только i m s u.
51
+ // Hex: после него не буква/цифра/дефис, но «_» можно — Tailwind пишет пробелы как «_» (#fff_0%).
52
+ // Функции: буква, цифра или дефис перед именем — часть более длинного имени (color-mix(, --x-rgb),
53
+ // такое не ловим; «_» и пробел — разделители (shadow-[0_1px_2px_rgb(0_0_0/0.05)]), там ловим.
54
+
55
+ const HEX = String.raw`#(?:[\da-f]{8}|[\da-f]{6}|[\da-f]{3,4})(?![\da-z-])`;
56
+ const FN = String.raw`(?<![\da-z-])(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch|color)\(`;
57
+ const COLOR = `${HEX}|${FN}`;
58
+
59
+ /** Строка или кусок шаблонной строки с литеральным цветом. */
60
+ const COLOR_STRING = `:matches(Literal[value=/${COLOR}/i], TemplateElement[value.raw=/${COLOR}/i])`;
61
+
62
+ const CLASS_ATTR = String.raw`JSXAttribute[name.name=/^(?:className|classNames)$|ClassName$/]`;
63
+ const CLASS_CALL = String.raw`CallExpression[callee.name=/^(?:cn|cva|clsx|cx|tv|twMerge|twJoin)$/]`;
64
+ const STYLE_ATTR = String.raw`JSXAttribute[name.name=/^style$|Style$/]`;
65
+
66
+ /** Записи правила no-restricted-syntax; экспортируются, чтобы проект мог дополнить список. */
67
+ export const restrictedSyntax = [
68
+ {
69
+ // Один селектор на оба контекста: className={cn('bg-[#fff]')} — одно сообщение, а не два.
70
+ selector: `:matches(${CLASS_ATTR}, ${CLASS_CALL}) ${COLOR_STRING}`,
71
+ message:
72
+ 'Цвет литералом в классах (#fff, rgb(…), oklch(…), bg-[#…], text-[rgb(…)]) запрещён: берите семантический класс — bg-primary, text-muted-foreground, border-border, bg-destructive, bg-field — или шкалу бренда (bg-red-500).',
73
+ },
74
+ {
75
+ selector: `${STYLE_ATTR} ${COLOR_STRING}`,
76
+ message:
77
+ 'Цвет литералом в style запрещён: используйте класс (bg-primary, text-muted-foreground, border-border) или переменную токена — var(--primary), var(--muted-foreground), var(--border).',
78
+ },
79
+ ];
80
+
81
+ /** @type {import('eslint').Linter.Config[]} */
82
+ const config = [
83
+ {
84
+ name: '@mednet/lint-config/eslint',
85
+ rules: {
86
+ 'no-restricted-imports': ['error', restrictedImports],
87
+ 'no-restricted-syntax': ['error', ...restrictedSyntax],
88
+ },
89
+ },
90
+ ];
91
+
92
+ export default config;
package/package.json CHANGED
@@ -1,6 +1,61 @@
1
1
  {
2
2
  "name": "@mednet/lint-config",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.0",
4
+ "description": "ESLint и stylelint для проектов ЦНИИОИЗ: защита бренда",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/hpnssflw/mednet-kit.git",
10
+ "directory": "packages/lint-config"
11
+ },
12
+ "files": [
13
+ "eslint.js",
14
+ "eslint.d.ts",
15
+ "stylelint.js",
16
+ "stylelint.d.ts",
17
+ "README.md"
18
+ ],
19
+ "exports": {
20
+ "./eslint": {
21
+ "types": "./eslint.d.ts",
22
+ "default": "./eslint.js"
23
+ },
24
+ "./stylelint": {
25
+ "types": "./stylelint.d.ts",
26
+ "default": "./stylelint.js"
27
+ },
28
+ "./package.json": "./package.json"
29
+ },
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "peerDependencies": {
34
+ "eslint": "^9.0.0 || ^10.0.0",
35
+ "stylelint": "^17.0.0"
36
+ },
37
+ "peerDependenciesMeta": {
38
+ "eslint": {
39
+ "optional": true
40
+ },
41
+ "stylelint": {
42
+ "optional": true
43
+ }
44
+ },
45
+ "devDependencies": {
46
+ "@types/node": "^24",
47
+ "eslint": "^9.39.5",
48
+ "eslint-config-next": "16.4.0",
49
+ "next": "^16.4.0",
50
+ "react": "^19.3.0",
51
+ "react-dom": "^19.3.0",
52
+ "stylelint": "^17.16.0",
53
+ "typescript": "~6.0.3",
54
+ "typescript-eslint": "^8.71.2",
55
+ "vitest": "^5.0.4"
56
+ },
57
+ "scripts": {
58
+ "test": "vitest run",
59
+ "typecheck": "tsc -p tsconfig.json"
60
+ }
6
61
  }
package/stylelint.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import type { Config } from 'stylelint';
2
+
3
+ export declare const colorFunctions: string[];
4
+
5
+ declare const config: Config;
6
+ export default config;
package/stylelint.js ADDED
@@ -0,0 +1,43 @@
1
+ // @mednet/lint-config/stylelint — только встроенные правила stylelint.
2
+ // Не подключайте вместе с ним stylelint-config-standard: на Tailwind v4 он даёт ложные ошибки
3
+ // (@apply, --spacing(), блочный @custom-variant) и отвергает currentColor.
4
+
5
+ /** Литеральные цветовые функции. color-mix() не входит: color-mix(in oklab, var(--a) 30%, transparent) разрешён. */
6
+ export const colorFunctions = [
7
+ 'rgb',
8
+ 'rgba',
9
+ 'hsl',
10
+ 'hsla',
11
+ 'hwb',
12
+ 'lab',
13
+ 'lch',
14
+ 'oklab',
15
+ 'oklch',
16
+ 'color',
17
+ ];
18
+
19
+ const HINT =
20
+ 'берите токен — var(--primary), var(--muted-foreground), var(--border) — или @apply с семантическим классом (bg-primary, text-muted-foreground, border-border); полупрозрачность — color-mix(in oklab, var(--primary) 30%, transparent)';
21
+
22
+ /** @type {import('stylelint').Config} */
23
+ const config = {
24
+ rules: {
25
+ 'color-no-hex': [
26
+ true,
27
+ { message: (/** @type {string} */ hex) => `Цвет литералом (${hex}) запрещён: ${HINT}.` },
28
+ ],
29
+ 'color-named': [
30
+ 'never',
31
+ { message: (/** @type {string} */ name) => `Именованный цвет (${name}) запрещён: ${HINT}.` },
32
+ ],
33
+ 'function-disallowed-list': [
34
+ colorFunctions,
35
+ {
36
+ message: (/** @type {string} */ fn) =>
37
+ `Цветовая функция ${fn}() с литералом запрещена: ${HINT}.`,
38
+ },
39
+ ],
40
+ },
41
+ };
42
+
43
+ export default config;