devbonzai 2.2.3 → 2.2.21
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,7 +25,7 @@ module.exports = async function scanCodeQuality(req, res) {
|
|
|
23
25
|
const ignorePatterns = getIgnorePatterns();
|
|
24
26
|
const issues = [];
|
|
25
27
|
|
|
26
|
-
//
|
|
28
|
+
// Get all files (needed for multiple checks)
|
|
27
29
|
const allFiles = glob.sync('**/*.{js,ts,jsx,tsx,py,java,go}', {
|
|
28
30
|
cwd: projectPath,
|
|
29
31
|
nodir: true
|
|
@@ -31,48 +33,53 @@ module.exports = async function scanCodeQuality(req, res) {
|
|
|
31
33
|
|
|
32
34
|
const files = allFiles.filter(file => !shouldIgnore(file, ignorePatterns));
|
|
33
35
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
36
|
+
// 1. Check file sizes
|
|
37
|
+
if (willEnforceLines) {
|
|
38
|
+
files.forEach(file => {
|
|
39
|
+
const fullPath = path.join(projectPath, file);
|
|
40
|
+
const content = fs.readFileSync(fullPath, 'utf8');
|
|
41
|
+
const lines = content.split('\n').length;
|
|
42
|
+
|
|
43
|
+
if (lines > maxFileLines) {
|
|
44
|
+
issues.push({
|
|
45
|
+
type: 'large_file',
|
|
46
|
+
file: file,
|
|
47
|
+
lines: lines,
|
|
48
|
+
limit: maxFileLines
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
48
53
|
|
|
49
54
|
// 2. Check folder sizes
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const folders = allFolders.filter(folder => !shouldIgnore(folder, ignorePatterns));
|
|
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;
|
|
55
|
+
if (willEnforceFolders) {
|
|
56
|
+
const allFolders = glob.sync('**/', {
|
|
57
|
+
cwd: projectPath
|
|
58
|
+
});
|
|
63
59
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
60
|
+
const folders = allFolders.filter(folder => !shouldIgnore(folder, ignorePatterns));
|
|
61
|
+
|
|
62
|
+
folders.forEach(folder => {
|
|
63
|
+
const fullPath = path.join(projectPath, folder);
|
|
64
|
+
const contents = fs.readdirSync(fullPath);
|
|
65
|
+
const fileCount = contents.filter(item => {
|
|
66
|
+
const itemPath = path.join(fullPath, item);
|
|
67
|
+
return fs.statSync(itemPath).isFile();
|
|
68
|
+
}).length;
|
|
69
|
+
|
|
70
|
+
if (fileCount > maxFolderFiles) {
|
|
71
|
+
issues.push({
|
|
72
|
+
type: 'crowded_folder',
|
|
73
|
+
folder: folder,
|
|
74
|
+
count: fileCount,
|
|
75
|
+
limit: maxFolderFiles
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
73
80
|
|
|
74
81
|
// 3. Check unused imports and dead code with ESLint
|
|
75
|
-
if (
|
|
82
|
+
if (willFlagUnusedImports || willFlagDeadCode) {
|
|
76
83
|
try {
|
|
77
84
|
const eslint = new ESLint({
|
|
78
85
|
cwd: projectPath,
|
|
@@ -89,8 +96,8 @@ module.exports = async function scanCodeQuality(req, res) {
|
|
|
89
96
|
ecmaFeatures: { jsx: true }
|
|
90
97
|
},
|
|
91
98
|
rules: {
|
|
92
|
-
'no-unused-vars':
|
|
93
|
-
'@typescript-eslint/no-unused-vars':
|
|
99
|
+
'no-unused-vars': willFlagDeadCode ? 'error' : 'off',
|
|
100
|
+
'@typescript-eslint/no-unused-vars': willFlagDeadCode ? 'error' : 'off'
|
|
94
101
|
}
|
|
95
102
|
}
|
|
96
103
|
});
|
|
@@ -120,7 +127,7 @@ module.exports = async function scanCodeQuality(req, res) {
|
|
|
120
127
|
}
|
|
121
128
|
|
|
122
129
|
// 4. Check circular dependencies
|
|
123
|
-
if (
|
|
130
|
+
if (willFlagCircularDeps) {
|
|
124
131
|
try {
|
|
125
132
|
const result = await madge(projectPath, {
|
|
126
133
|
fileExtensions: ['js', 'jsx', 'ts', 'tsx'],
|