vzcode 1.31.0 → 1.32.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/dist/assets/index-sreAszZh.js +240 -0
- package/dist/assets/worker-BKfYWklR.js +136 -0
- package/dist/assets/worker-COyDRdqW.js +453 -0
- package/dist/assets/{worker-CaP6zYz7.js → worker-CWsWXMyk.js} +70 -70
- package/dist/index.html +1 -1
- package/package.json +40 -33
- package/src/client/App/index.tsx +3 -0
- package/src/client/CodeEditor/getOrCreateEditor.ts +80 -4
- package/src/client/CodeEditor/index.tsx +56 -24
- package/src/client/CodeEditor/typescriptExtension/worker.ts +32 -0
- package/src/client/VZMiddle.tsx +11 -0
- package/src/client/VZSidebar/Search.tsx +11 -0
- package/src/client/useESLint/index.ts +72 -0
- package/src/client/useESLint/worker.ts +113 -0
- package/src/server/featureFlags.js +2 -0
- package/dist/assets/index-D01yzCWj.js +0 -234
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import * as eslint from 'eslint-linter-browserify';
|
|
2
|
+
import globals from 'globals';
|
|
3
|
+
|
|
4
|
+
// Feature flag to enable or disable JSX linting
|
|
5
|
+
// It's disabled for now since it doesn't work.
|
|
6
|
+
// See issue:
|
|
7
|
+
// https://github.com/vizhub-core/vzcode/issues/921
|
|
8
|
+
const enableJSXLinting = false;
|
|
9
|
+
|
|
10
|
+
const linter = new eslint.Linter();
|
|
11
|
+
|
|
12
|
+
const config = {
|
|
13
|
+
languageOptions: {
|
|
14
|
+
globals: {
|
|
15
|
+
...globals.browser,
|
|
16
|
+
...globals.es2021,
|
|
17
|
+
},
|
|
18
|
+
parserOptions: {
|
|
19
|
+
ecmaVersion: 2022,
|
|
20
|
+
sourceType: 'module',
|
|
21
|
+
ecmaFeatures: {
|
|
22
|
+
// Add this to enable JSX parsing
|
|
23
|
+
jsx: true,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
rules: {
|
|
28
|
+
'no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
|
|
29
|
+
'no-undef': 'error',
|
|
30
|
+
semi: 'off',
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// Helper function to convert line/column to character offset
|
|
35
|
+
function getOffset(
|
|
36
|
+
docLines: string[],
|
|
37
|
+
line: number,
|
|
38
|
+
column: number,
|
|
39
|
+
): number {
|
|
40
|
+
let offset = 0;
|
|
41
|
+
for (let i = 0; i < line - 1; i++) {
|
|
42
|
+
offset += (docLines[i] ? docLines[i].length : 0) + 1; // +1 for newline
|
|
43
|
+
}
|
|
44
|
+
return offset + column - 1;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
self.onmessage = (event) => {
|
|
48
|
+
const { code, requestId, fileName } = event.data;
|
|
49
|
+
if (typeof code !== 'string') {
|
|
50
|
+
self.postMessage({
|
|
51
|
+
diagnostics: [],
|
|
52
|
+
requestId,
|
|
53
|
+
error: 'Invalid code received',
|
|
54
|
+
});
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Only lint .js files, and .jsx files if enableJSXLinting is true
|
|
59
|
+
if (!fileName) {
|
|
60
|
+
self.postMessage({ diagnostics: [], requestId });
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const isJsFile = /\.js$/i.test(fileName);
|
|
65
|
+
const isJsxFile = /\.jsx$/i.test(fileName);
|
|
66
|
+
|
|
67
|
+
if (!isJsFile && (!isJsxFile || !enableJSXLinting)) {
|
|
68
|
+
self.postMessage({ diagnostics: [], requestId });
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
const messages = linter.verify(code, config as any);
|
|
74
|
+
const docLines = code.split('\n');
|
|
75
|
+
|
|
76
|
+
const diagnostics = messages.map((msg) => {
|
|
77
|
+
const from = getOffset(
|
|
78
|
+
docLines,
|
|
79
|
+
msg.line,
|
|
80
|
+
msg.column,
|
|
81
|
+
);
|
|
82
|
+
// endLine and endColumn may not always exist
|
|
83
|
+
const to =
|
|
84
|
+
msg.endLine && msg.endColumn
|
|
85
|
+
? getOffset(docLines, msg.endLine, msg.endColumn)
|
|
86
|
+
: from +
|
|
87
|
+
(msg.fix?.range[1] - msg.fix?.range[0] || 1);
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
from,
|
|
91
|
+
to,
|
|
92
|
+
severity:
|
|
93
|
+
msg.severity === 2
|
|
94
|
+
? 'error'
|
|
95
|
+
: msg.severity === 1
|
|
96
|
+
? 'warning'
|
|
97
|
+
: 'info',
|
|
98
|
+
message: msg.message,
|
|
99
|
+
source: msg.ruleId
|
|
100
|
+
? `eslint(${msg.ruleId})`
|
|
101
|
+
: 'eslint',
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
self.postMessage({ diagnostics, requestId });
|
|
105
|
+
} catch (e: any) {
|
|
106
|
+
console.error('Error linting in ESLint worker:', e);
|
|
107
|
+
self.postMessage({
|
|
108
|
+
error: e.message,
|
|
109
|
+
diagnostics: [],
|
|
110
|
+
requestId,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
};
|