devbonzai 2.1.9 → 2.2.1
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "devbonzai",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "Quickly set up a local file server in any repository for browser-based file access",
|
|
5
5
|
"main": "cli.js",
|
|
6
6
|
"bin": {
|
|
@@ -26,6 +26,8 @@
|
|
|
26
26
|
"cors": "^2.8.5",
|
|
27
27
|
"body-parser": "^1.20.2",
|
|
28
28
|
"raw-body": "^2.5.2",
|
|
29
|
-
"glob": "^10.0.0"
|
|
29
|
+
"glob": "^10.0.0",
|
|
30
|
+
"eslint": "^8.57.0",
|
|
31
|
+
"madge": "^6.1.0"
|
|
30
32
|
}
|
|
31
33
|
}
|
|
@@ -1,24 +1,36 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const glob = require('glob');
|
|
4
|
+
const { ESLint } = require('eslint');
|
|
5
|
+
const madge = require('madge');
|
|
6
|
+
const { getIgnorePatterns, shouldIgnore } = require('../utils/ignore');
|
|
4
7
|
|
|
5
8
|
module.exports = async function scanCodeQuality(req, res) {
|
|
6
9
|
try {
|
|
7
|
-
const {
|
|
10
|
+
const {
|
|
11
|
+
projectPath,
|
|
12
|
+
maxFileLines = 500,
|
|
13
|
+
maxFolderFiles = 20,
|
|
14
|
+
checkUnusedImports = true,
|
|
15
|
+
checkDeadCode = true,
|
|
16
|
+
checkCircularDeps = false
|
|
17
|
+
} = req.body;
|
|
8
18
|
|
|
9
19
|
if (!projectPath) {
|
|
10
20
|
return res.status(400).json({ error: 'projectPath required' });
|
|
11
21
|
}
|
|
12
22
|
|
|
23
|
+
const ignorePatterns = getIgnorePatterns();
|
|
13
24
|
const issues = [];
|
|
14
25
|
|
|
15
26
|
// 1. Check file sizes
|
|
16
|
-
const
|
|
27
|
+
const allFiles = glob.sync('**/*.{js,ts,jsx,tsx,py,java,go}', {
|
|
17
28
|
cwd: projectPath,
|
|
18
|
-
nodir: true
|
|
19
|
-
ignore: ['node_modules/**', 'dist/**', 'build/**', '.git/**']
|
|
29
|
+
nodir: true
|
|
20
30
|
});
|
|
21
31
|
|
|
32
|
+
const files = allFiles.filter(file => !shouldIgnore(file, ignorePatterns));
|
|
33
|
+
|
|
22
34
|
files.forEach(file => {
|
|
23
35
|
const fullPath = path.join(projectPath, file);
|
|
24
36
|
const content = fs.readFileSync(fullPath, 'utf8');
|
|
@@ -35,11 +47,12 @@ module.exports = async function scanCodeQuality(req, res) {
|
|
|
35
47
|
});
|
|
36
48
|
|
|
37
49
|
// 2. Check folder sizes
|
|
38
|
-
const
|
|
39
|
-
cwd: projectPath
|
|
40
|
-
ignore: ['node_modules/**', 'dist/**', 'build/**', '.git/**']
|
|
50
|
+
const allFolders = glob.sync('**/', {
|
|
51
|
+
cwd: projectPath
|
|
41
52
|
});
|
|
42
53
|
|
|
54
|
+
const folders = allFolders.filter(folder => !shouldIgnore(folder, ignorePatterns));
|
|
55
|
+
|
|
43
56
|
folders.forEach(folder => {
|
|
44
57
|
const fullPath = path.join(projectPath, folder);
|
|
45
58
|
const contents = fs.readdirSync(fullPath);
|
|
@@ -58,6 +71,79 @@ module.exports = async function scanCodeQuality(req, res) {
|
|
|
58
71
|
}
|
|
59
72
|
});
|
|
60
73
|
|
|
74
|
+
// 3. Check unused imports and dead code with ESLint
|
|
75
|
+
if (checkUnusedImports || checkDeadCode) {
|
|
76
|
+
try {
|
|
77
|
+
const eslint = new ESLint({
|
|
78
|
+
cwd: projectPath,
|
|
79
|
+
useEslintrc: false,
|
|
80
|
+
overrideConfig: {
|
|
81
|
+
env: {
|
|
82
|
+
browser: true,
|
|
83
|
+
node: true,
|
|
84
|
+
es6: true
|
|
85
|
+
},
|
|
86
|
+
parserOptions: {
|
|
87
|
+
ecmaVersion: 2021,
|
|
88
|
+
sourceType: 'module',
|
|
89
|
+
ecmaFeatures: { jsx: true }
|
|
90
|
+
},
|
|
91
|
+
rules: {
|
|
92
|
+
'no-unused-vars': checkDeadCode ? 'error' : 'off',
|
|
93
|
+
'@typescript-eslint/no-unused-vars': checkDeadCode ? 'error' : 'off'
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const jsFiles = files.filter(f => /\.(js|jsx|ts|tsx)$/.test(f));
|
|
99
|
+
const results = await eslint.lintFiles(jsFiles.map(f => path.join(projectPath, f)));
|
|
100
|
+
|
|
101
|
+
results.forEach(result => {
|
|
102
|
+
const relativePath = path.relative(projectPath, result.filePath);
|
|
103
|
+
|
|
104
|
+
result.messages.forEach(msg => {
|
|
105
|
+
if (msg.ruleId === 'no-unused-vars' || msg.ruleId === '@typescript-eslint/no-unused-vars') {
|
|
106
|
+
issues.push({
|
|
107
|
+
type: 'unused_variable',
|
|
108
|
+
file: relativePath,
|
|
109
|
+
line: msg.line,
|
|
110
|
+
variable: msg.message.match(/'(.+?)'/)?.[1] || 'unknown',
|
|
111
|
+
message: msg.message
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
} catch (eslintError) {
|
|
117
|
+
console.error('ESLint scan error:', eslintError);
|
|
118
|
+
// Don't fail entire scan if ESLint fails
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// 4. Check circular dependencies
|
|
123
|
+
if (checkCircularDeps) {
|
|
124
|
+
try {
|
|
125
|
+
const result = await madge(projectPath, {
|
|
126
|
+
fileExtensions: ['js', 'jsx', 'ts', 'tsx'],
|
|
127
|
+
excludeRegExp: ignorePatterns.map(p => new RegExp(p))
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const circular = result.circular();
|
|
131
|
+
|
|
132
|
+
if (circular.length > 0) {
|
|
133
|
+
circular.forEach(cycle => {
|
|
134
|
+
issues.push({
|
|
135
|
+
type: 'circular_dependency',
|
|
136
|
+
files: cycle,
|
|
137
|
+
message: `Circular dependency: ${cycle.join(' → ')}`
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
} catch (madgeError) {
|
|
142
|
+
console.error('Madge scan error:', madgeError);
|
|
143
|
+
// Don't fail entire scan if madge fails
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
61
147
|
res.json({ issues });
|
|
62
148
|
|
|
63
149
|
} catch (error) {
|
|
@@ -65,4 +151,3 @@ module.exports = async function scanCodeQuality(req, res) {
|
|
|
65
151
|
res.status(500).json({ error: error.message });
|
|
66
152
|
}
|
|
67
153
|
};
|
|
68
|
-
|