@cherepanov.pavel/shareable-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 (54) hide show
  1. package/.editorconfig +11 -0
  2. package/.editorconfig-get.js +19 -0
  3. package/.get-all.js +29 -0
  4. package/.gitattributes +1 -0
  5. package/.gitattributes-get.js +19 -0
  6. package/.gitignore +15 -0
  7. package/.gitignore-get.js +47 -0
  8. package/.vscode/.code-snippets-get.js +49 -0
  9. package/.vscode/all-files.code-snippets +18 -0
  10. package/.vscode/extensions.json +25 -0
  11. package/.vscode/extensions.json-get.js +43 -0
  12. package/.vscode/settings.json +42 -0
  13. package/.vscode/settings.json-get.js +43 -0
  14. package/.vscode/vue.code-snippets +28 -0
  15. package/README.md +10 -0
  16. package/env.json5.set.js +14 -0
  17. package/jsconfig.json +9 -0
  18. package/package.json +54 -0
  19. package/tools/eslint-config/configs/global.js +26 -0
  20. package/tools/eslint-config/configs/javascript.js +21 -0
  21. package/tools/eslint-config/configs/typescript.js +28 -0
  22. package/tools/eslint-config/configs/vue.js +43 -0
  23. package/tools/eslint-config/index.js +4 -0
  24. package/tools/eslint-config/rules/constants.js +15 -0
  25. package/tools/eslint-config/rules/javascript/index.js +7 -0
  26. package/tools/eslint-config/rules/javascript/possible-problems.js +62 -0
  27. package/tools/eslint-config/rules/javascript/suggestions.js +254 -0
  28. package/tools/eslint-config/rules/severity.js +3 -0
  29. package/tools/eslint-config/rules/stylistic/index.js +2 -0
  30. package/tools/eslint-config/rules/stylistic/jsFormatting.js +172 -0
  31. package/tools/eslint-config/rules/stylistic/tsFormatting.js +9 -0
  32. package/tools/eslint-config/rules/typescript/common.js +130 -0
  33. package/tools/eslint-config/rules/typescript/compatibility.js +24 -0
  34. package/tools/eslint-config/rules/typescript/extension.js +52 -0
  35. package/tools/eslint-config/rules/typescript/index.js +9 -0
  36. package/tools/eslint-config/rules/vue/base.js +6 -0
  37. package/tools/eslint-config/rules/vue/extension.js +58 -0
  38. package/tools/eslint-config/rules/vue/formatting.js +41 -0
  39. package/tools/eslint-config/rules/vue/index.js +13 -0
  40. package/tools/eslint-config/rules/vue/possibleProblems.js +113 -0
  41. package/tools/eslint-config/rules/vue/suggestions.js +83 -0
  42. package/tools/stylelint-config/config.js +29 -0
  43. package/tools/stylelint-config/rules/base.js +26 -0
  44. package/tools/stylelint-config/rules/conflicts.js +7 -0
  45. package/tools/stylelint-config/rules/order.js +42 -0
  46. package/tools/stylelint-config/rules/property-groups.js +404 -0
  47. package/tools/stylelint-config/rules/scss.js +8 -0
  48. package/tools/stylelint-config/rules/stylistic.js +124 -0
  49. package/utils/communication.js +33 -0
  50. package/utils/copy-with-override.js +43 -0
  51. package/utils/env.js +16 -0
  52. package/utils/file-header.js +16 -0
  53. package/utils/file.js +64 -0
  54. package/utils/merge.js +180 -0
package/utils/file.js ADDED
@@ -0,0 +1,64 @@
1
+ import { fileURLToPath } from 'url';
2
+ import path from 'path';
3
+ import { readFile } from 'fs/promises';
4
+ import JSON5 from 'json5';
5
+
6
+ export async function getSrcFileData({ fileName }) {
7
+ const dirname = path.dirname(fileURLToPath(import.meta.url));
8
+ const src = path.join(dirname, '..', '.vscode', fileName);
9
+ const srcFileData = await readFile(src, 'utf8');
10
+
11
+ return srcFileData;
12
+ }
13
+
14
+ export async function getSrcJSONFileData({
15
+ fileName,
16
+ isTs = false,
17
+ removeDuplicateKeys = false,
18
+ }) {
19
+ const srcFileData = await getSrcFileData({ fileName });
20
+
21
+ // Если есть нет typescript, нет лишних проблем, возвращаем
22
+ if (!srcFileData.includes('// typescript')) {
23
+ return srcFileData;
24
+ }
25
+
26
+ const lines = srcFileData.split('\n');
27
+ const result = [];
28
+ let nextLineIsTypescript = false;
29
+ let nextLineIsTypescriptMultiline = false;
30
+
31
+ lines.forEach((line) => {
32
+ // если следующая строка typescript only
33
+ if (line.includes('// typescript')) {
34
+ // если несколько следующих строк typescript only
35
+ if (line.includes('// typescript multiline')) {
36
+ // проверяем это конец multiline typescript комментария, или начало, и в соответствии
37
+ // с этим ставим флаг
38
+ nextLineIsTypescriptMultiline = !(line.includes('// typescript multiline end'));
39
+ } else {
40
+ nextLineIsTypescript = true; // Следующая строка будет typescript-only
41
+ }
42
+ // флаги проставлены, с этой строкой больше нечего делать, выходим
43
+ return;
44
+ }
45
+
46
+ if (nextLineIsTypescript || nextLineIsTypescriptMultiline) {
47
+ // Включаем строку только если нужен typescript
48
+ if (isTs) {
49
+ result.push(line);
50
+ }
51
+ nextLineIsTypescript = false; // Сбрасываем флаг
52
+ } else {
53
+ // Обычная строка - всегда включаем
54
+ result.push(line);
55
+ }
56
+ });
57
+
58
+ const stringResult = result.join('\n');
59
+ if (removeDuplicateKeys) {
60
+ return JSON.stringify(JSON5.parse(stringResult), null, 2);
61
+ }
62
+
63
+ return stringResult;
64
+ }
package/utils/merge.js ADDED
@@ -0,0 +1,180 @@
1
+ export async function mergeWithOverride(baseContent, overrideContent) {
2
+ let result = baseContent;
3
+
4
+ if (!overrideContent.includes('// override')) {
5
+ return result;
6
+ }
7
+
8
+ const overrideBlocks = findOverrideBlocks(overrideContent);
9
+ for (const block of overrideBlocks) {
10
+ result = pasteOverrideInsideEndOfPath(block, result);
11
+ if (!block.isObjectOverride) {
12
+ // удалить элементы массива при необходимости
13
+ result = processArrayOverride(result, block);
14
+ }
15
+ }
16
+ return result;
17
+ }
18
+
19
+ function findOverrideBlocks(overrideContent) {
20
+ const lines = overrideContent.split('\n');
21
+ const overrideBlocks = [];
22
+ let currentBlock = null;
23
+ let braceCount = 0;
24
+
25
+ for (let i = 0; i < lines.length; i++) {
26
+ const line = lines[i];
27
+
28
+ if (line.includes('// override')) {
29
+ currentBlock = {
30
+ startLine: i,
31
+ lines: [line],
32
+ path: [],
33
+ isObjectOverride: false,
34
+ };
35
+ let braceCount2 = 0;
36
+ // ищем полный path до override поля
37
+ for (let j = i; j !== 0; j--) {
38
+ const line2 = lines[j];
39
+ braceCount2 += (
40
+ line2.match(/{/g)?.length
41
+ || line2.match(/\[/g)?.length
42
+ || 0
43
+ );
44
+ braceCount2 -= (
45
+ line2.match(/}/g)?.length
46
+ || line2.match(/]/g)?.length
47
+ || 0
48
+ );
49
+ if (braceCount2 > 0) {
50
+ const fieldName = line2.match(/"([^"]+)"\s*:/)?.[1];
51
+ if (fieldName) {
52
+ currentBlock.path.unshift(fieldName);
53
+ }
54
+ braceCount2 = 0;
55
+ }
56
+ }
57
+ continue;
58
+ }
59
+
60
+ if (currentBlock) {
61
+ braceCount += (
62
+ line.match(/{/g)?.length
63
+ || line.match(/\[/g)?.length
64
+ || 0
65
+ );
66
+ braceCount -= (
67
+ line.match(/}/g)?.length
68
+ || line.match(/]/g)?.length
69
+ || 0
70
+ );
71
+ if (braceCount < 0) {
72
+ if (line.match(/}/g)) {
73
+ currentBlock.isObjectOverride = true;
74
+ }
75
+ // currentBlock.endLine = i + 1
76
+ // currentBlock.path = lines.slice(startLine, endLine).join()
77
+ overrideBlocks.push(currentBlock);
78
+ currentBlock = null;
79
+ braceCount = 0;
80
+ } else {
81
+ currentBlock.lines.push(line);
82
+ }
83
+ }
84
+ }
85
+
86
+ if (currentBlock) {
87
+ overrideBlocks.push(currentBlock);
88
+ }
89
+
90
+ return overrideBlocks;
91
+ }
92
+
93
+ function processArrayOverride(baseContent, block) {
94
+ // Разбиваем на строки
95
+ const lines = baseContent.split('\n');
96
+ // Копируем только нужный диапазон
97
+ const overrideLines = lines.slice(block.startIdx, block.endIdx);
98
+
99
+ // Обрабатываем override-блок только в этом диапазоне
100
+ let processed = overrideLines;
101
+ for (const line of block.lines) {
102
+ const trimmed = line.trim();
103
+ if (trimmed.startsWith('//')) {
104
+ const match = trimmed.match(/^\/\/\s*"([^"]+)"/);
105
+ if (match) {
106
+ const elementToRemove = match[1];
107
+ // Удаляем строку с этим элементом только в overrideLines
108
+ processed = processed.filter((l) => {
109
+ return !l.includes(`"${elementToRemove}"`);
110
+ });
111
+ }
112
+ }
113
+ }
114
+
115
+ // Собираем итоговый массив строк:
116
+ const resultLines = [
117
+ ...lines.slice(0, block.startIdx),
118
+ ...processed,
119
+ ...lines.slice(block.endIdx),
120
+ ];
121
+
122
+ return resultLines.join('\n');
123
+ }
124
+
125
+ function findEndOfArrOrObj(startIdx, lines, block) {
126
+ let braceCount = 0;
127
+ for (let i = startIdx; i < lines.length; i++) {
128
+ const line = lines[i];
129
+ braceCount += (
130
+ line.match(/{/g)?.length
131
+ || line.match(/\[/g)?.length
132
+ || 0
133
+ );
134
+ braceCount -= (
135
+ line.match(/}/g)?.length
136
+ || line.match(/]/g)?.length
137
+ || 0
138
+ );
139
+ if (braceCount < 0) {
140
+ block.endIdx = i;
141
+ return;
142
+ }
143
+ }
144
+ }
145
+
146
+ function pasteOverrideInsideEndOfPath(block, result) {
147
+ if (block.path.length) {
148
+ const resultArr = [];
149
+ const lines = result.split('\n');
150
+ let pathCount = 0;
151
+ for (let i = 0; i < lines.length; i++) {
152
+ if (lines[i].includes(block.path[pathCount])) {
153
+ if (pathCount !== block.path.length - 1) {
154
+ pathCount += 1;
155
+ } else {
156
+ block.startIdx = i;
157
+ findEndOfArrOrObj(i + 1, lines, block);
158
+ }
159
+ }
160
+ if (i === block.endIdx) {
161
+ resultArr.push('');
162
+ resultArr.push(...block.lines);
163
+ }
164
+ resultArr.push(lines[i]);
165
+ }
166
+
167
+ return resultArr.join('\n');
168
+ }
169
+ const lastBraceIndex = result.lastIndexOf('}');
170
+ if (lastBraceIndex !== -1) {
171
+ const beforeBrace = result.substring(0, lastBraceIndex);
172
+ const afterBrace = result.substring(lastBraceIndex);
173
+ result = (
174
+ `${beforeBrace
175
+ }\n${block.lines.join('\n')}\n${
176
+ afterBrace}`
177
+ );
178
+ }
179
+ return result;
180
+ }