devbonzai 2.2.3 → 2.2.201
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
|
@@ -11,9 +11,11 @@ module.exports = async function scanCodeQuality(req, res) {
|
|
|
11
11
|
projectPath,
|
|
12
12
|
maxFileLines = 500,
|
|
13
13
|
maxFolderFiles = 20,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
willEnforceLines = true,
|
|
15
|
+
willEnforceFolders = true,
|
|
16
|
+
willFlagUnusedImports = true,
|
|
17
|
+
willFlagDeadCode = true,
|
|
18
|
+
willFlagCircularDeps = false
|
|
17
19
|
} = req.body;
|
|
18
20
|
|
|
19
21
|
if (!projectPath) {
|
|
@@ -23,56 +25,76 @@ module.exports = async function scanCodeQuality(req, res) {
|
|
|
23
25
|
const ignorePatterns = getIgnorePatterns();
|
|
24
26
|
const issues = [];
|
|
25
27
|
|
|
26
|
-
//
|
|
28
|
+
// Common build/output directories to always ignore
|
|
29
|
+
const defaultIgnoreGlobs = [
|
|
30
|
+
'**/node_modules/**',
|
|
31
|
+
'**/dist/**',
|
|
32
|
+
'**/build/**',
|
|
33
|
+
'**/static/**',
|
|
34
|
+
'**/out/**',
|
|
35
|
+
'**/.next/**',
|
|
36
|
+
'**/*.min.js',
|
|
37
|
+
'**/*.bundle.js',
|
|
38
|
+
'**/*.chunk.js'
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
// Get all files (needed for multiple checks)
|
|
27
42
|
const allFiles = glob.sync('**/*.{js,ts,jsx,tsx,py,java,go}', {
|
|
28
43
|
cwd: projectPath,
|
|
29
|
-
nodir: true
|
|
44
|
+
nodir: true,
|
|
45
|
+
ignore: defaultIgnoreGlobs
|
|
30
46
|
});
|
|
31
47
|
|
|
32
48
|
const files = allFiles.filter(file => !shouldIgnore(file, ignorePatterns));
|
|
33
49
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
50
|
+
// 1. Check file sizes
|
|
51
|
+
if (willEnforceLines) {
|
|
52
|
+
files.forEach(file => {
|
|
53
|
+
const fullPath = path.join(projectPath, file);
|
|
54
|
+
const content = fs.readFileSync(fullPath, 'utf8');
|
|
55
|
+
const lines = content.split('\n').length;
|
|
56
|
+
|
|
57
|
+
if (lines > maxFileLines) {
|
|
58
|
+
issues.push({
|
|
59
|
+
type: 'large_file',
|
|
60
|
+
file: file,
|
|
61
|
+
lines: lines,
|
|
62
|
+
limit: maxFileLines
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
48
67
|
|
|
49
68
|
// 2. Check folder sizes
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
folders.forEach(folder => {
|
|
57
|
-
const fullPath = path.join(projectPath, folder);
|
|
58
|
-
const contents = fs.readdirSync(fullPath);
|
|
59
|
-
const fileCount = contents.filter(item => {
|
|
60
|
-
const itemPath = path.join(fullPath, item);
|
|
61
|
-
return fs.statSync(itemPath).isFile();
|
|
62
|
-
}).length;
|
|
69
|
+
if (willEnforceFolders) {
|
|
70
|
+
const allFolders = glob.sync('**/', {
|
|
71
|
+
cwd: projectPath,
|
|
72
|
+
ignore: defaultIgnoreGlobs
|
|
73
|
+
});
|
|
63
74
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
75
|
+
const folders = allFolders.filter(folder => !shouldIgnore(folder, ignorePatterns));
|
|
76
|
+
|
|
77
|
+
folders.forEach(folder => {
|
|
78
|
+
const fullPath = path.join(projectPath, folder);
|
|
79
|
+
const contents = fs.readdirSync(fullPath);
|
|
80
|
+
const fileCount = contents.filter(item => {
|
|
81
|
+
const itemPath = path.join(fullPath, item);
|
|
82
|
+
return fs.statSync(itemPath).isFile();
|
|
83
|
+
}).length;
|
|
84
|
+
|
|
85
|
+
if (fileCount > maxFolderFiles) {
|
|
86
|
+
issues.push({
|
|
87
|
+
type: 'crowded_folder',
|
|
88
|
+
folder: folder,
|
|
89
|
+
count: fileCount,
|
|
90
|
+
limit: maxFolderFiles
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
73
95
|
|
|
74
96
|
// 3. Check unused imports and dead code with ESLint
|
|
75
|
-
if (
|
|
97
|
+
if (willFlagUnusedImports || willFlagDeadCode) {
|
|
76
98
|
try {
|
|
77
99
|
const eslint = new ESLint({
|
|
78
100
|
cwd: projectPath,
|
|
@@ -89,8 +111,7 @@ module.exports = async function scanCodeQuality(req, res) {
|
|
|
89
111
|
ecmaFeatures: { jsx: true }
|
|
90
112
|
},
|
|
91
113
|
rules: {
|
|
92
|
-
'no-unused-vars':
|
|
93
|
-
'@typescript-eslint/no-unused-vars': checkDeadCode ? 'error' : 'off'
|
|
114
|
+
'no-unused-vars': willFlagDeadCode ? 'error' : 'off'
|
|
94
115
|
}
|
|
95
116
|
}
|
|
96
117
|
});
|
|
@@ -102,7 +123,7 @@ module.exports = async function scanCodeQuality(req, res) {
|
|
|
102
123
|
const relativePath = path.relative(projectPath, result.filePath);
|
|
103
124
|
|
|
104
125
|
result.messages.forEach(msg => {
|
|
105
|
-
if (msg.ruleId === 'no-unused-vars'
|
|
126
|
+
if (msg.ruleId === 'no-unused-vars') {
|
|
106
127
|
issues.push({
|
|
107
128
|
type: 'unused_variable',
|
|
108
129
|
file: relativePath,
|
|
@@ -120,7 +141,7 @@ module.exports = async function scanCodeQuality(req, res) {
|
|
|
120
141
|
}
|
|
121
142
|
|
|
122
143
|
// 4. Check circular dependencies
|
|
123
|
-
if (
|
|
144
|
+
if (willFlagCircularDeps) {
|
|
124
145
|
try {
|
|
125
146
|
const result = await madge(projectPath, {
|
|
126
147
|
fileExtensions: ['js', 'jsx', 'ts', 'tsx'],
|