You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-ignore expr ignore files matching the given regexp
180
183
181
184
The (default) output fields for each line are:
182
185
@@ -191,10 +194,24 @@ or equal to <complexity> <package> <function> <file:row:column>
191
194
The struct being passed to the template is:
192
195
193
196
type Stat struct {
194
-
PkgName string
195
-
FuncName string
196
-
Complexity int
197
-
Pos token.Position
197
+
PkgName string
198
+
FuncName string
199
+
Complexity int
200
+
Pos token.Position
201
+
Diagnostics []Diagnostics
202
+
}
203
+
204
+
type Diagnostic struct {
205
+
Inc string
206
+
Nesting int
207
+
Text string
208
+
Pos DiagnosticPosition
209
+
}
210
+
211
+
type DiagnosticPosition struct {
212
+
Offset int
213
+
Line int
214
+
Column int
198
215
}
199
216
```
200
217
@@ -223,6 +240,76 @@ func IgnoreMe() {
223
240
}
224
241
```
225
242
243
+
## Diagnostic
244
+
To understand how the complexity are calculated, we can enable the diagnostic by using `-d` flag.
245
+
246
+
Example:
247
+
```shell
248
+
$ gocognit -json -d .
249
+
```
250
+
251
+
It will show the diagnostic output in JSON format
252
+
<details>
253
+
254
+
<summary>JSON Output</summary>
255
+
256
+
```json
257
+
[
258
+
{
259
+
"PkgName": "prime",
260
+
"FuncName": "SumOfPrimes",
261
+
"Complexity": 7,
262
+
"Pos": {
263
+
"Filename": "prime.go",
264
+
"Offset": 15,
265
+
"Line": 3,
266
+
"Column": 1
267
+
},
268
+
"Diagnostics": [
269
+
{
270
+
"Inc": 1,
271
+
"Text": "for",
272
+
"Pos": {
273
+
"Offset": 69,
274
+
"Line": 7,
275
+
"Column": 2
276
+
}
277
+
},
278
+
{
279
+
"Inc": 2,
280
+
"Nesting": 1,
281
+
"Text": "for",
282
+
"Pos": {
283
+
"Offset": 104,
284
+
"Line": 8,
285
+
"Column": 3
286
+
}
287
+
},
288
+
{
289
+
"Inc": 3,
290
+
"Nesting": 2,
291
+
"Text": "if",
292
+
"Pos": {
293
+
"Offset": 152,
294
+
"Line": 9,
295
+
"Column": 4
296
+
}
297
+
},
298
+
{
299
+
"Inc": 1,
300
+
"Text": "continue",
301
+
"Pos": {
302
+
"Offset": 190,
303
+
"Line": 10,
304
+
"Column": 5
305
+
}
306
+
}
307
+
]
308
+
}
309
+
]
310
+
```
311
+
</details>
312
+
226
313
## Related project
227
314
-[Gocyclo](https://github.com/fzipp/gocyclo) where the code are based on.
228
315
-[Cognitive Complexity: A new way of measuring understandability](https://www.sonarsource.com/docs/CognitiveComplexity.pdf) white paper by G. Ann Campbell.
0 commit comments