@nitra/cursor 1.8.104 → 1.8.106

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.
@@ -12,66 +12,68 @@ import { createCheckReporter } from './utils/check-reporter.mjs'
12
12
  import { anyRunStepIncludesStylelint, parseWorkflowYaml } from './utils/gha-workflow.mjs'
13
13
 
14
14
  /**
15
- * Перевіряє відповідність проєкту правилам style-lint.mdc
16
- * @returns {Promise<number>} 0 — все OK, 1 — є проблеми
15
+ * @param {{ pass: (msg: string) => void, fail: (msg: string) => void }} reporter репортер для збору результатів
17
16
  */
18
- export async function check() {
19
- const reporter = createCheckReporter()
17
+ async function checkPackageJson(reporter) {
20
18
  const { pass, fail } = reporter
19
+ if (!existsSync('package.json')) return
20
+ const pkg = JSON.parse(await readFile('package.json', 'utf8'))
21
21
 
22
- if (existsSync('package.json')) {
23
- const pkg = JSON.parse(await readFile('package.json', 'utf8'))
24
-
25
- const lintStyle = pkg.scripts?.['lint-style']
26
- if (lintStyle) {
27
- pass('package.json містить скрипт lint-style')
28
- if (String(lintStyle).includes('npx stylelint')) {
29
- pass('lint-style викликає stylelint через npx')
30
- } else {
31
- fail("lint-style має викликати stylelint через npx — наприклад: npx stylelint '**/*.{css,scss,vue}' --fix")
32
- }
22
+ const lintStyle = pkg.scripts?.['lint-style']
23
+ if (lintStyle) {
24
+ pass('package.json містить скрипт lint-style')
25
+ if (String(lintStyle).includes('npx stylelint')) {
26
+ pass('lint-style викликає stylelint через npx')
33
27
  } else {
34
- fail('package.json не містить скрипт "lint-style"')
35
- }
36
-
37
- if (pkg.devDependencies?.['@nitra/stylelint-config']) {
38
- pass('@nitra/stylelint-config є в devDependencies')
39
- } else {
40
- fail('@nitra/stylelint-config відсутній — bun add -d @nitra/stylelint-config')
41
- }
42
-
43
- const stylelintCfg = pkg.stylelint
44
- if (stylelintCfg?.extends === '@nitra/stylelint-config') {
45
- pass('package.json stylelint extends @nitra/stylelint-config')
46
- } else if (existsSync('.stylelintrc.json') || existsSync('.stylelintrc.js') || existsSync('stylelint.config.js')) {
47
- pass('Окремий файл конфігу stylelint існує')
48
- } else {
49
- fail('Немає конфігу stylelint — додай "stylelint": { "extends": "@nitra/stylelint-config" } до package.json')
28
+ fail("lint-style має викликати stylelint через npx — наприклад: npx stylelint '**/*.{css,scss,vue}' --fix")
50
29
  }
30
+ } else {
31
+ fail('package.json не містить скрипт "lint-style"')
51
32
  }
52
33
 
53
- if (existsSync('.stylelintignore')) {
54
- pass('.stylelintignore існує')
34
+ if (pkg.devDependencies?.['@nitra/stylelint-config']) {
35
+ pass('@nitra/stylelint-config є в devDependencies')
55
36
  } else {
56
- fail('.stylelintignore не існує створи з вмістом: dist/')
37
+ fail('@nitra/stylelint-config відсутнійbun add -d @nitra/stylelint-config')
57
38
  }
58
39
 
59
- if (existsSync('.github/workflows/lint-style.yml')) {
60
- const content = await readFile('.github/workflows/lint-style.yml', 'utf8')
61
- pass('lint-style.yml існує')
62
- const root = parseWorkflowYaml(content)
63
- const ok = root ? anyRunStepIncludesStylelint(root) : content.includes('npx stylelint')
64
- if (ok) {
65
- pass('lint-style.yml містить npx stylelint у кроці run')
66
- } else {
67
- fail(
68
- "lint-style.yml має викликати stylelint у CI через npx — наприклад: npx stylelint '**/*.{css,scss,vue}' --fix"
69
- )
70
- }
40
+ const stylelintCfg = pkg.stylelint
41
+ const hasExternalCfg =
42
+ existsSync('.stylelintrc.json') || existsSync('.stylelintrc.js') || existsSync('stylelint.config.js')
43
+ if (stylelintCfg?.extends === '@nitra/stylelint-config') {
44
+ pass('package.json stylelint extends @nitra/stylelint-config')
45
+ } else if (hasExternalCfg) {
46
+ pass('Окремий файл конфігу stylelint існує')
71
47
  } else {
48
+ fail('Немає конфігу stylelint — додай "stylelint": { "extends": "@nitra/stylelint-config" } до package.json')
49
+ }
50
+ }
51
+
52
+ /**
53
+ * @param {import('./utils/check-reporter.mjs').CheckReporter} reporter репортер для збору результатів
54
+ */
55
+ async function checkStylelintWorkflow(reporter) {
56
+ const { pass, fail } = reporter
57
+ if (!existsSync('.github/workflows/lint-style.yml')) {
72
58
  fail('.github/workflows/lint-style.yml не існує — створи його')
59
+ return
60
+ }
61
+ const content = await readFile('.github/workflows/lint-style.yml', 'utf8')
62
+ pass('lint-style.yml існує')
63
+ const root = parseWorkflowYaml(content)
64
+ const ok = root ? anyRunStepIncludesStylelint(root) : content.includes('npx stylelint')
65
+ if (ok) {
66
+ pass('lint-style.yml містить npx stylelint у кроці run')
67
+ } else {
68
+ fail("lint-style.yml має викликати stylelint у CI через npx — наприклад: npx stylelint '**/*.{css,scss,vue}' --fix")
73
69
  }
70
+ }
74
71
 
72
+ /**
73
+ * @param {import('./utils/check-reporter.mjs').CheckReporter} reporter репортер для збору результатів
74
+ */
75
+ async function checkVscodeStylelint(reporter) {
76
+ const { pass, fail } = reporter
75
77
  if (existsSync('.vscode/extensions.json')) {
76
78
  const ext = JSON.parse(await readFile('.vscode/extensions.json', 'utf8'))
77
79
  if (ext.recommendations?.includes('stylelint.vscode-stylelint')) {
@@ -83,24 +85,35 @@ export async function check() {
83
85
  fail('.vscode/extensions.json не існує')
84
86
  }
85
87
 
86
- if (existsSync('.vscode/settings.json')) {
87
- const s = JSON.parse(await readFile('.vscode/settings.json', 'utf8'))
88
- if (s['css.validate'] === false) {
89
- pass('css.validate вимкнено')
88
+ if (!existsSync('.vscode/settings.json')) return
89
+ const s = JSON.parse(await readFile('.vscode/settings.json', 'utf8'))
90
+ for (const key of ['css.validate', 'scss.validate', 'less.validate']) {
91
+ if (s[key] === false) {
92
+ pass(`${key} вимкнено`)
90
93
  } else {
91
- fail('settings.json: css.validate має бути false')
92
- }
93
- if (s['scss.validate'] === false) {
94
- pass('scss.validate вимкнено')
95
- } else {
96
- fail('settings.json: scss.validate має бути false')
97
- }
98
- if (s['less.validate'] === false) {
99
- pass('less.validate вимкнено')
100
- } else {
101
- fail('settings.json: less.validate має бути false')
94
+ fail(`settings.json: ${key} має бути false`)
102
95
  }
103
96
  }
97
+ }
98
+
99
+ /**
100
+ * Перевіряє відповідність проєкту правилам style-lint.mdc
101
+ * @returns {Promise<number>} 0 — все OK, 1 — є проблеми
102
+ */
103
+ export async function check() {
104
+ const reporter = createCheckReporter()
105
+ const { pass, fail } = reporter
106
+
107
+ await checkPackageJson(reporter)
108
+
109
+ if (existsSync('.stylelintignore')) {
110
+ pass('.stylelintignore існує')
111
+ } else {
112
+ fail('.stylelintignore не існує — створи з вмістом: dist/')
113
+ }
114
+
115
+ await checkStylelintWorkflow(reporter)
116
+ await checkVscodeStylelint(reporter)
104
117
 
105
118
  return reporter.getExitCode()
106
119
  }