-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcode-quality.js
More file actions
167 lines (133 loc) · 4.78 KB
/
code-quality.js
File metadata and controls
167 lines (133 loc) · 4.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
class CodeQuality {
constructor(commandExecutor, loggingUtils) {
this.commandExecutor = commandExecutor;
this.loggingUtils = loggingUtils;
}
async format(options = {}) {
const args = [];
if (options.check) {
args.push('--check-formatted');
}
if (options.dryRun) {
args.push('--dry-run');
}
if (options.files) {
args.push(...options.files.split(','));
}
if (options.verbose) {
args.push('--verbose');
}
try {
return await this.commandExecutor.executeMixCommand('format', args, options);
} catch (error) {
this.suggestFormatFix(error.message);
throw error;
}
}
async lint(options = {}) {
const args = [];
if (options.strict) {
args.push('--strict');
}
if (options.all) {
args.push('--all');
}
if (options.allPriorities) {
args.push('--all-priorities');
}
if (options.format) {
args.push('--format', options.format);
}
if (options.config) {
args.push('--config', options.config);
}
if (options.files) {
args.push(...options.files.split(','));
}
if (options.verbose) {
args.push('--verbose');
}
try {
return await this.commandExecutor.executeMixCommand('credo', args, options);
} catch (error) {
this.suggestLintFix(error.message);
throw error;
}
}
async typecheck(options = {}) {
const args = [];
if (options.noCheck) {
args.push('--no-check');
}
if (options.warnings) {
args.push('--warnings', options.warnings);
}
if (options.format) {
args.push('--format', options.format);
}
if (options.verbose) {
args.push('--verbose');
}
try {
return await this.commandExecutor.executeMixCommand('dialyzer', args, options);
} catch (error) {
this.suggestTypecheckFix(error.message);
throw error;
}
}
suggestFormatFix(errorMessage) {
this.loggingUtils.info('\n💡 Formatting Error Suggestions:');
if (errorMessage.includes('check-formatted')) {
this.loggingUtils.info(' • Files are not properly formatted');
this.loggingUtils.info(' • Run mix format without --check-formatted to fix');
this.loggingUtils.info(' • Check .formatter.exs configuration');
}
if (errorMessage.includes('syntax error')) {
this.loggingUtils.info(' • Fix syntax errors before formatting');
this.loggingUtils.info(' • Check for missing commas, parentheses, or do/end blocks');
this.loggingUtils.info(' • Verify Elixir version compatibility');
}
if (errorMessage.includes('file not found')) {
this.loggingUtils.info(' • Check file paths are correct');
this.loggingUtils.info(' • Ensure files exist in project directory');
this.loggingUtils.info(' • Use relative paths from project root');
}
}
suggestLintFix(errorMessage) {
this.loggingUtils.info('\n💡 Linting Error Suggestions:');
if (errorMessage.includes('Credo')) {
this.loggingUtils.info(' • Install Credo: mix archive.install hex credo');
this.loggingUtils.info(' • Check .credo.exs configuration file');
this.loggingUtils.info(' • Run mix credo --help for available options');
}
if (errorMessage.includes('warning')) {
this.loggingUtils.info(' • Review warnings in context');
this.loggingUtils.info(' • Use --strict for stricter checks');
this.loggingUtils.info(' • Consider fixing high-priority issues first');
}
if (errorMessage.includes('configuration')) {
this.loggingUtils.info(' • Check .credo.exs syntax');
this.loggingUtils.info(' • Verify check configurations');
this.loggingUtils.info(' • Ensure consistent code style rules');
}
}
suggestTypecheckFix(errorMessage) {
this.loggingUtils.info('\n💡 Type Checking Error Suggestions:');
if (errorMessage.includes('Dialyzer')) {
this.loggingUtils.info(' • Install Dialyzer: mix archive.install hex dialyxir');
this.loggingUtils.info(' • Build PLT first: mix dialyzer --plt');
this.loggingUtils.info(' • Check dialyzer.ignore-warnings file');
}
if (errorMessage.includes('type mismatch')) {
this.loggingUtils.info(' • Check function signatures match specifications');
this.loggingUtils.info(' • Review @spec annotations');
this.loggingUtils.info(' • Use dialyzer.ignore-warnings for false positives');
}
if (errorMessage.includes('undefined function')) {
this.loggingUtils.info(' • Ensure all functions are defined or imported');
this.loggingUtils.info(' • Check module dependencies');
this.loggingUtils.info(' • Verify function arity matches');
}
}
}
module.exports = CodeQuality;