@codacy/tools-revive-1 0.3.0

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/dist/index.js ADDED
@@ -0,0 +1,1300 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ default: () => index_default
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+ var import_tooling2 = require("@codacy/tooling");
37
+
38
+ // src/adapter.ts
39
+ var import_tooling = require("@codacy/tooling");
40
+ var import_path = __toESM(require("path"));
41
+ var import_promises = __toESM(require("fs/promises"));
42
+
43
+ // src/patterns.json
44
+ var patterns_default = [
45
+ {
46
+ id: "Revive_add-constant",
47
+ category: "BestPractice",
48
+ severityLevel: "Warning",
49
+ title: "Suggest Using Constants for Magic Numbers and String Literals",
50
+ enabled: false,
51
+ parameters: []
52
+ },
53
+ {
54
+ id: "Revive_argument-limit",
55
+ category: "Complexity",
56
+ severityLevel: "Warning",
57
+ title: "Enforce Maximum Number of Function Parameters",
58
+ enabled: false,
59
+ parameters: [
60
+ {
61
+ name: "unnamedParam",
62
+ default: "4",
63
+ description: "(int) the maximum number of parameters allowed per function"
64
+ }
65
+ ]
66
+ },
67
+ {
68
+ id: "Revive_atomic",
69
+ category: "ErrorProne",
70
+ severityLevel: "High",
71
+ title: "Avoid Common Mistakes with sync/atomic Package Usage",
72
+ enabled: false,
73
+ parameters: []
74
+ },
75
+ {
76
+ id: "Revive_banned-characters",
77
+ category: "CodeStyle",
78
+ severityLevel: "Info",
79
+ title: "Disallow Banned Characters in Identifiers",
80
+ enabled: false,
81
+ parameters: [
82
+ {
83
+ name: "unnamedParam",
84
+ default: "",
85
+ description: "comma-separated list of character to ban"
86
+ }
87
+ ]
88
+ },
89
+ {
90
+ id: "Revive_bare-return",
91
+ category: "Comprehensibility",
92
+ severityLevel: "Info",
93
+ title: "Avoid Bare Return Statements",
94
+ enabled: false,
95
+ parameters: []
96
+ },
97
+ {
98
+ id: "Revive_blank-imports",
99
+ category: "BestPractice",
100
+ severityLevel: "Warning",
101
+ title: "Enforce Proper Use of Blank Imports",
102
+ enabled: true,
103
+ parameters: []
104
+ },
105
+ {
106
+ id: "Revive_bool-literal-in-expr",
107
+ category: "Comprehensibility",
108
+ severityLevel: "Info",
109
+ title: "Avoid Boolean Literals in Logic Expressions",
110
+ enabled: false,
111
+ parameters: []
112
+ },
113
+ {
114
+ id: "Revive_call-to-gc",
115
+ category: "Performance",
116
+ severityLevel: "Warning",
117
+ title: "Avoid Explicit Calls to Garbage Collector",
118
+ enabled: false,
119
+ parameters: []
120
+ },
121
+ {
122
+ id: "Revive_cognitive-complexity",
123
+ category: "Complexity",
124
+ severityLevel: "Warning",
125
+ title: "Enforce Maximum Cognitive Complexity",
126
+ enabled: false,
127
+ parameters: [
128
+ {
129
+ name: "unnamedParam",
130
+ default: "7",
131
+ description: "(int) the maximum function complexity"
132
+ }
133
+ ]
134
+ },
135
+ {
136
+ id: "Revive_comments-density",
137
+ category: "Documentation",
138
+ severityLevel: "Info",
139
+ title: "Enforce Minimum Comments Density",
140
+ enabled: false,
141
+ parameters: []
142
+ },
143
+ {
144
+ id: "Revive_comment-spacings",
145
+ category: "CodeStyle",
146
+ severityLevel: "Info",
147
+ title: "Enforce Space After Comment Slashes",
148
+ enabled: false,
149
+ parameters: []
150
+ },
151
+ {
152
+ id: "Revive_confusing-naming",
153
+ category: "Comprehensibility",
154
+ severityLevel: "Info",
155
+ title: "Avoid Confusing Naming Differing Only by Capitalization",
156
+ enabled: false,
157
+ parameters: []
158
+ },
159
+ {
160
+ id: "Revive_confusing-results",
161
+ category: "ErrorProne",
162
+ severityLevel: "Warning",
163
+ title: "Avoid Returning Multiple Unnamed Values of the Same Type",
164
+ enabled: false,
165
+ parameters: []
166
+ },
167
+ {
168
+ id: "Revive_constant-logical-expr",
169
+ category: "ErrorProne",
170
+ severityLevel: "Warning",
171
+ title: "Avoid Constant Logical Expressions",
172
+ enabled: false,
173
+ parameters: []
174
+ },
175
+ {
176
+ id: "Revive_context-as-argument",
177
+ category: "CodeStyle",
178
+ severityLevel: "Info",
179
+ title: "Enforce context.Context as First Parameter",
180
+ enabled: true,
181
+ parameters: []
182
+ },
183
+ {
184
+ id: "Revive_context-keys-type",
185
+ category: "BestPractice",
186
+ severityLevel: "Warning",
187
+ title: "Avoid Using Basic Types as Keys in context.WithValue",
188
+ enabled: true,
189
+ parameters: []
190
+ },
191
+ {
192
+ id: "Revive_cyclomatic",
193
+ category: "Complexity",
194
+ severityLevel: "Warning",
195
+ title: "Enforce Maximum Cyclomatic Complexity",
196
+ enabled: false,
197
+ parameters: [
198
+ {
199
+ name: "unnamedParam",
200
+ default: "3",
201
+ description: "(int) the maximum function complexity"
202
+ }
203
+ ]
204
+ },
205
+ {
206
+ id: "Revive_datarace",
207
+ category: "ErrorProne",
208
+ severityLevel: "Error",
209
+ title: "Avoid Data Races in Go Routines by Capturing Variables Correctly",
210
+ enabled: false,
211
+ parameters: []
212
+ },
213
+ {
214
+ id: "Revive_deep-exit",
215
+ category: "BestPractice",
216
+ severityLevel: "Warning",
217
+ title: "Avoid Exiting Program in Non-Main Functions",
218
+ enabled: false,
219
+ parameters: []
220
+ },
221
+ {
222
+ id: "Revive_defer",
223
+ category: "ErrorProne",
224
+ severityLevel: "High",
225
+ title: "Warn on Common Mistakes Using defer Statement",
226
+ enabled: false,
227
+ parameters: [
228
+ {
229
+ name: "unnamedParam",
230
+ default: '"call-chain","loop"',
231
+ description: "(string) the unused params in functions"
232
+ }
233
+ ]
234
+ },
235
+ {
236
+ id: "Revive_dot-imports",
237
+ category: "Comprehensibility",
238
+ severityLevel: "Info",
239
+ title: "Avoid Dot Imports",
240
+ enabled: true,
241
+ parameters: []
242
+ },
243
+ {
244
+ id: "Revive_duplicated-imports",
245
+ category: "CodeStyle",
246
+ severityLevel: "Info",
247
+ title: "Avoid Duplicated Imports",
248
+ enabled: false,
249
+ parameters: []
250
+ },
251
+ {
252
+ id: "Revive_early-return",
253
+ category: "BestPractice",
254
+ severityLevel: "Info",
255
+ title: "Enforce Early Return to Minimize Nesting",
256
+ enabled: false,
257
+ parameters: []
258
+ },
259
+ {
260
+ id: "Revive_empty-block",
261
+ category: "CodeStyle",
262
+ severityLevel: "Info",
263
+ title: "Avoid Empty Blocks",
264
+ enabled: true,
265
+ parameters: []
266
+ },
267
+ {
268
+ id: "Revive_empty-lines",
269
+ category: "CodeStyle",
270
+ severityLevel: "Info",
271
+ title: "Avoid Heading or Trailing Empty Lines in Code Blocks",
272
+ enabled: false,
273
+ parameters: []
274
+ },
275
+ {
276
+ id: "Revive_enforce-map-style",
277
+ category: "CodeStyle",
278
+ severityLevel: "Info",
279
+ title: "Enforce Consistent Map Initialization Style",
280
+ enabled: false,
281
+ parameters: []
282
+ },
283
+ {
284
+ id: "Revive_enforce-repeated-arg-type-style",
285
+ category: "CodeStyle",
286
+ severityLevel: "Info",
287
+ title: "Enforce Consistent Repeated Argument and Return Value Type Style",
288
+ enabled: false,
289
+ parameters: []
290
+ },
291
+ {
292
+ id: "Revive_enforce-slice-style",
293
+ category: "CodeStyle",
294
+ severityLevel: "Info",
295
+ title: "Enforce Consistent Slice Initialization Style",
296
+ enabled: false,
297
+ parameters: []
298
+ },
299
+ {
300
+ id: "Revive_enforce-switch-style",
301
+ category: "BestPractice",
302
+ severityLevel: "Info",
303
+ title: "Enforce Consistent Default Case Usage in Switch Statements",
304
+ enabled: false,
305
+ parameters: []
306
+ },
307
+ {
308
+ id: "Revive_errorf",
309
+ category: "BestPractice",
310
+ severityLevel: "Info",
311
+ title: "Simplify error creation by replacing errors.New(fmt.Sprintf()) with fmt.Errorf()",
312
+ enabled: true,
313
+ parameters: []
314
+ },
315
+ {
316
+ id: "Revive_error-naming",
317
+ category: "CodeStyle",
318
+ severityLevel: "Info",
319
+ title: "Enforce error variable naming prefix",
320
+ enabled: true,
321
+ parameters: []
322
+ },
323
+ {
324
+ id: "Revive_error-return",
325
+ category: "CodeStyle",
326
+ severityLevel: "Info",
327
+ title: "Enforce Errors as Last Return Value",
328
+ enabled: true,
329
+ parameters: []
330
+ },
331
+ {
332
+ id: "Revive_error-strings",
333
+ category: "CodeStyle",
334
+ severityLevel: "Info",
335
+ title: "Enforce Error String Formatting",
336
+ enabled: true,
337
+ parameters: []
338
+ },
339
+ {
340
+ id: "Revive_exported",
341
+ category: "Documentation",
342
+ severityLevel: "Info",
343
+ title: "EnforceCommentsOnExportedFunctionsAndMethods",
344
+ enabled: true,
345
+ parameters: []
346
+ },
347
+ {
348
+ id: "Revive_file-header",
349
+ category: "CodeStyle",
350
+ severityLevel: "Info",
351
+ title: "Enforce File Header Presence",
352
+ enabled: false,
353
+ parameters: [
354
+ {
355
+ name: "unnamedParam",
356
+ default: "",
357
+ description: "(string) the header to look for in source files"
358
+ }
359
+ ]
360
+ },
361
+ {
362
+ id: "Revive_file-length-limit",
363
+ category: "Complexity",
364
+ severityLevel: "Warning",
365
+ title: "Enforce File Length Limit",
366
+ enabled: false,
367
+ parameters: []
368
+ },
369
+ {
370
+ id: "Revive_filename-format",
371
+ category: "CodeStyle",
372
+ severityLevel: "Info",
373
+ title: "Enforce Filename Format",
374
+ enabled: false,
375
+ parameters: []
376
+ },
377
+ {
378
+ id: "Revive_flag-parameter",
379
+ category: "BestPractice",
380
+ severityLevel: "Warning",
381
+ title: "Avoid Flag Parameters",
382
+ enabled: false,
383
+ parameters: []
384
+ },
385
+ {
386
+ id: "Revive_function-length",
387
+ category: "Complexity",
388
+ severityLevel: "Warning",
389
+ title: "Enforce Function Length Limits",
390
+ enabled: false,
391
+ parameters: []
392
+ },
393
+ {
394
+ id: "Revive_function-result-limit",
395
+ category: "Complexity",
396
+ severityLevel: "Warning",
397
+ title: "Limit Number of Return Values in Functions",
398
+ enabled: false,
399
+ parameters: [
400
+ {
401
+ name: "unnamedParam",
402
+ default: "3",
403
+ description: "(int) the maximum allowed return values"
404
+ }
405
+ ]
406
+ },
407
+ {
408
+ id: "Revive_get-return",
409
+ category: "BestPractice",
410
+ severityLevel: "Warning",
411
+ title: "Enforce Functions Prefixed with 'Get' to Return a Value",
412
+ enabled: false,
413
+ parameters: []
414
+ },
415
+ {
416
+ id: "Revive_identical-branches",
417
+ category: "ErrorProne",
418
+ severityLevel: "Warning",
419
+ title: "Avoid Identical Branches in If-Then-Else Conditionals",
420
+ enabled: false,
421
+ parameters: []
422
+ },
423
+ {
424
+ id: "Revive_identical-ifelseif-branches",
425
+ category: "BestPractice",
426
+ severityLevel: "Warning",
427
+ title: "Avoid identical if/else-if branches",
428
+ enabled: false,
429
+ parameters: []
430
+ },
431
+ {
432
+ id: "Revive_identical-ifelseif-conditions",
433
+ category: "ErrorProne",
434
+ severityLevel: "High",
435
+ title: "Avoid identical if/else-if conditions",
436
+ enabled: false,
437
+ parameters: []
438
+ },
439
+ {
440
+ id: "Revive_identical-switch-branches",
441
+ category: "BestPractice",
442
+ severityLevel: "Warning",
443
+ title: "Avoid identical switch branches",
444
+ enabled: false,
445
+ parameters: []
446
+ },
447
+ {
448
+ id: "Revive_identical-switch-conditions",
449
+ category: "ErrorProne",
450
+ severityLevel: "High",
451
+ title: "Avoid identical switch case conditions",
452
+ enabled: false,
453
+ parameters: []
454
+ },
455
+ {
456
+ id: "Revive_if-return",
457
+ category: "CodeStyle",
458
+ severityLevel: "Info",
459
+ title: "Avoid Redundant if-Error Return",
460
+ enabled: false,
461
+ parameters: []
462
+ },
463
+ {
464
+ id: "Revive_import-alias-naming",
465
+ category: "CodeStyle",
466
+ severityLevel: "Info",
467
+ title: "Enforce Import Alias Naming Conventions",
468
+ enabled: false,
469
+ parameters: []
470
+ },
471
+ {
472
+ id: "Revive_imports-blocklist",
473
+ category: "Security",
474
+ severityLevel: "High",
475
+ title: "Warn on Importing Block-Listed Packages",
476
+ enabled: false,
477
+ parameters: [
478
+ {
479
+ name: "unnamedParam",
480
+ default: '"crypto/md5", "crypto/sha1"',
481
+ description: "(list of string) block-list of package names (or regular expression package names)"
482
+ }
483
+ ]
484
+ },
485
+ {
486
+ id: "Revive_import-shadowing",
487
+ category: "ErrorProne",
488
+ severityLevel: "Warning",
489
+ title: "Avoid Import Shadowing",
490
+ enabled: false,
491
+ parameters: []
492
+ },
493
+ {
494
+ id: "Revive_increment-decrement",
495
+ category: "CodeStyle",
496
+ severityLevel: "Info",
497
+ title: "Enforce use of increment and decrement operators",
498
+ enabled: true,
499
+ parameters: []
500
+ },
501
+ {
502
+ id: "Revive_indent-error-flow",
503
+ category: "CodeStyle",
504
+ severityLevel: "Info",
505
+ title: "Avoid Redundant Else Blocks to Reduce Indentation",
506
+ enabled: true,
507
+ parameters: []
508
+ },
509
+ {
510
+ id: "Revive_line-length-limit",
511
+ category: "CodeStyle",
512
+ severityLevel: "Info",
513
+ title: "Enforce Maximum Line Length",
514
+ enabled: false,
515
+ parameters: [
516
+ {
517
+ name: "unnamedParam",
518
+ default: "80",
519
+ description: "(int) maximum line length in characters"
520
+ }
521
+ ]
522
+ },
523
+ {
524
+ id: "Revive_max-control-nesting",
525
+ category: "Complexity",
526
+ severityLevel: "Warning",
527
+ title: "Enforce Maximum Control Structure Nesting",
528
+ enabled: false,
529
+ parameters: [
530
+ {
531
+ name: "unnamedParam",
532
+ default: "5",
533
+ description: "(int) maximum accepted nesting level of control structures"
534
+ }
535
+ ]
536
+ },
537
+ {
538
+ id: "Revive_max-public-structs",
539
+ category: "Complexity",
540
+ severityLevel: "Warning",
541
+ title: "Limit Number of Public Structs",
542
+ enabled: false,
543
+ parameters: [
544
+ {
545
+ name: "unnamedParam",
546
+ default: "5",
547
+ description: "(int) the maximum allowed public structs"
548
+ }
549
+ ]
550
+ },
551
+ {
552
+ id: "Revive_modifies-parameter",
553
+ category: "BestPractice",
554
+ severityLevel: "Warning",
555
+ title: "Avoid Modifying Function Parameters",
556
+ enabled: false,
557
+ parameters: []
558
+ },
559
+ {
560
+ id: "Revive_modifies-value-receiver",
561
+ category: "ErrorProne",
562
+ severityLevel: "Warning",
563
+ title: "Avoid Modifying Value Receiver",
564
+ enabled: false,
565
+ parameters: []
566
+ },
567
+ {
568
+ id: "Revive_nested-structs",
569
+ category: "Comprehensibility",
570
+ severityLevel: "Info",
571
+ title: "Avoid Nested Structs",
572
+ enabled: false,
573
+ parameters: []
574
+ },
575
+ {
576
+ id: "Revive_optimize-operands-order",
577
+ category: "Performance",
578
+ severityLevel: "Warning",
579
+ title: "Optimize Operands Order in Conditional Expressions",
580
+ enabled: false,
581
+ parameters: []
582
+ },
583
+ {
584
+ id: "Revive_package-comments",
585
+ category: "Documentation",
586
+ severityLevel: "Info",
587
+ title: "Enforce Package Comments",
588
+ enabled: true,
589
+ parameters: []
590
+ },
591
+ {
592
+ id: "Revive_package-directory-mismatch",
593
+ category: "Comprehensibility",
594
+ severityLevel: "Info",
595
+ title: "Enforce package name matches directory",
596
+ enabled: false,
597
+ parameters: []
598
+ },
599
+ {
600
+ id: "Revive_range",
601
+ category: "ErrorProne",
602
+ severityLevel: "High",
603
+ title: "Avoid Using Address of Range Variables in Loops",
604
+ enabled: true,
605
+ parameters: []
606
+ },
607
+ {
608
+ id: "Revive_range-val-address",
609
+ category: "ErrorProne",
610
+ severityLevel: "High",
611
+ title: "Avoid Taking Address of Range Variables",
612
+ enabled: false,
613
+ parameters: []
614
+ },
615
+ {
616
+ id: "Revive_range-val-in-closure",
617
+ category: "ErrorProne",
618
+ severityLevel: "High",
619
+ title: "Avoid range variable reuse in closure",
620
+ enabled: false,
621
+ parameters: []
622
+ },
623
+ {
624
+ id: "Revive_receiver-naming",
625
+ category: "CodeStyle",
626
+ severityLevel: "Info",
627
+ title: "Enforce Receiver Naming Convention",
628
+ enabled: true,
629
+ parameters: []
630
+ },
631
+ {
632
+ id: "Revive_redefines-builtin-id",
633
+ category: "ErrorProne",
634
+ severityLevel: "High",
635
+ title: "Avoid Redefining Built-in Identifiers",
636
+ enabled: true,
637
+ parameters: []
638
+ },
639
+ {
640
+ id: "Revive_redundant-build-tag",
641
+ category: "CodeStyle",
642
+ severityLevel: "Info",
643
+ title: "Avoid Redundant Build Tag Comments",
644
+ enabled: false,
645
+ parameters: []
646
+ },
647
+ {
648
+ id: "Revive_redundant-import-alias",
649
+ category: "CodeStyle",
650
+ severityLevel: "Info",
651
+ title: "Avoid Redundant Import Aliases",
652
+ enabled: false,
653
+ parameters: []
654
+ },
655
+ {
656
+ id: "Revive_redundant-test-main-exit",
657
+ category: "BestPractice",
658
+ severityLevel: "Info",
659
+ title: "Avoid Redundant Exit Calls in TestMain",
660
+ enabled: false,
661
+ parameters: []
662
+ },
663
+ {
664
+ id: "Revive_string-format",
665
+ category: "BestPractice",
666
+ severityLevel: "Warning",
667
+ title: "Enforce String Literal Format in Specific Function Calls",
668
+ enabled: false,
669
+ parameters: []
670
+ },
671
+ {
672
+ id: "Revive_string-of-int",
673
+ category: "ErrorProne",
674
+ severityLevel: "High",
675
+ title: "Avoid Suspicious String Conversion of Integers",
676
+ enabled: false,
677
+ parameters: []
678
+ },
679
+ {
680
+ id: "Revive_struct-tag",
681
+ category: "ErrorProne",
682
+ severityLevel: "Warning",
683
+ title: "Check Struct Tags",
684
+ enabled: false,
685
+ parameters: []
686
+ },
687
+ {
688
+ id: "Revive_superfluous-else",
689
+ category: "Comprehensibility",
690
+ severityLevel: "Info",
691
+ title: "Avoid Superfluous Else Blocks",
692
+ enabled: true,
693
+ parameters: [
694
+ {
695
+ name: "unnamedParam",
696
+ default: "",
697
+ description: '(list of string) the flags ("preserveScope")'
698
+ }
699
+ ]
700
+ },
701
+ {
702
+ id: "Revive_time-date",
703
+ category: "ErrorProne",
704
+ severityLevel: "High",
705
+ title: "Avoid bad usage of time.Date",
706
+ enabled: false,
707
+ parameters: []
708
+ },
709
+ {
710
+ id: "Revive_time-equal",
711
+ category: "ErrorProne",
712
+ severityLevel: "High",
713
+ title: "Avoid Using == and != for Comparing time.Time Values",
714
+ enabled: false,
715
+ parameters: []
716
+ },
717
+ {
718
+ id: "Revive_time-naming",
719
+ category: "CodeStyle",
720
+ severityLevel: "Info",
721
+ title: "Avoid Unit-Specific Suffixes in time.Duration Variable Names",
722
+ enabled: true,
723
+ parameters: []
724
+ },
725
+ {
726
+ id: "Revive_unchecked-type-assertion",
727
+ category: "ErrorProne",
728
+ severityLevel: "Error",
729
+ title: "Enforce Checked Type Assertions",
730
+ enabled: false,
731
+ parameters: []
732
+ },
733
+ {
734
+ id: "Revive_unconditional-recursion",
735
+ category: "ErrorProne",
736
+ severityLevel: "Error",
737
+ title: "Avoid Unconditional Recursion",
738
+ enabled: false,
739
+ parameters: []
740
+ },
741
+ {
742
+ id: "Revive_unexported-naming",
743
+ category: "CodeStyle",
744
+ severityLevel: "Info",
745
+ title: "Enforce unexported symbol naming convention",
746
+ enabled: false,
747
+ parameters: []
748
+ },
749
+ {
750
+ id: "Revive_unexported-return",
751
+ category: "BestPractice",
752
+ severityLevel: "Warning",
753
+ title: "Avoid Exported Functions Returning Unexported Types",
754
+ enabled: true,
755
+ parameters: []
756
+ },
757
+ {
758
+ id: "Revive_unhandled-error",
759
+ category: "ErrorProne",
760
+ severityLevel: "High",
761
+ title: "Enforce Explicit Handling of Returned Errors",
762
+ enabled: false,
763
+ parameters: [
764
+ {
765
+ name: "unnamedParam",
766
+ default: '"fmt.Printf"',
767
+ description: "(list of string) function names regexp patterns to ignore"
768
+ }
769
+ ]
770
+ },
771
+ {
772
+ id: "Revive_unnecessary-format",
773
+ category: "Performance",
774
+ severityLevel: "Warning",
775
+ title: "Avoid Unnecessary Formatting Function Calls",
776
+ enabled: false,
777
+ parameters: []
778
+ },
779
+ {
780
+ id: "Revive_unnecessary-stmt",
781
+ category: "CodeStyle",
782
+ severityLevel: "Info",
783
+ title: "Remove Unnecessary Statements",
784
+ enabled: false,
785
+ parameters: []
786
+ },
787
+ {
788
+ id: "Revive_unreachable-code",
789
+ category: "CodeStyle",
790
+ severityLevel: "Info",
791
+ title: "Remove Unreachable Code",
792
+ enabled: true,
793
+ parameters: []
794
+ },
795
+ {
796
+ id: "Revive_unsecure-url-scheme",
797
+ category: "Security",
798
+ severityLevel: "High",
799
+ title: "Avoid unsecure URL schemes",
800
+ enabled: false,
801
+ parameters: []
802
+ },
803
+ {
804
+ id: "Revive_unused-parameter",
805
+ category: "UnusedCode",
806
+ severityLevel: "Warning",
807
+ title: "Avoid Unused Parameters",
808
+ enabled: true,
809
+ parameters: []
810
+ },
811
+ {
812
+ id: "Revive_unused-receiver",
813
+ category: "ErrorProne",
814
+ severityLevel: "Warning",
815
+ title: "Avoid Unused Method Receivers",
816
+ enabled: false,
817
+ parameters: []
818
+ },
819
+ {
820
+ id: "Revive_use-any",
821
+ category: "CodeStyle",
822
+ severityLevel: "Info",
823
+ title: "Replace interface{} with any",
824
+ enabled: false,
825
+ parameters: []
826
+ },
827
+ {
828
+ id: "Revive_use-errors-new",
829
+ category: "Performance",
830
+ severityLevel: "Warning",
831
+ title: "Use errors.New Instead of fmt.Errorf When No Formatting Is Needed",
832
+ enabled: false,
833
+ parameters: []
834
+ },
835
+ {
836
+ id: "Revive_use-fmt-print",
837
+ category: "BestPractice",
838
+ severityLevel: "Info",
839
+ title: "Enforce use of fmt.Print instead of built-in print/println",
840
+ enabled: false,
841
+ parameters: []
842
+ },
843
+ {
844
+ id: "Revive_useless-break",
845
+ category: "BestPractice",
846
+ severityLevel: "Warning",
847
+ title: "Avoid Useless Break Statements in Case Clauses",
848
+ enabled: false,
849
+ parameters: []
850
+ },
851
+ {
852
+ id: "Revive_useless-fallthrough",
853
+ category: "CodeStyle",
854
+ severityLevel: "Info",
855
+ title: "Avoid useless fallthrough",
856
+ enabled: false,
857
+ parameters: []
858
+ },
859
+ {
860
+ id: "Revive_use-waitgroup-go",
861
+ category: "BestPractice",
862
+ severityLevel: "Warning",
863
+ title: "Use WaitGroup.Go",
864
+ enabled: false,
865
+ parameters: []
866
+ },
867
+ {
868
+ id: "Revive_var-declaration",
869
+ category: "CodeStyle",
870
+ severityLevel: "Info",
871
+ title: "Enforce Simplified Variable Declarations",
872
+ enabled: true,
873
+ parameters: []
874
+ },
875
+ {
876
+ id: "Revive_var-naming",
877
+ category: "CodeStyle",
878
+ severityLevel: "Info",
879
+ title: "Enforce Variable and Package Naming Conventions",
880
+ enabled: true,
881
+ parameters: []
882
+ },
883
+ {
884
+ id: "Revive_waitgroup-by-value",
885
+ category: "ErrorProne",
886
+ severityLevel: "High",
887
+ title: "Avoid Passing sync.WaitGroup by Value",
888
+ enabled: false,
889
+ parameters: []
890
+ }
891
+ ];
892
+
893
+ // src/adapter.ts
894
+ var TOOL_ID = "Revive";
895
+ var VALID_CATEGORIES = /* @__PURE__ */ new Set([
896
+ "Security",
897
+ "ErrorProne",
898
+ "CodeStyle",
899
+ "Compatibility",
900
+ "Performance",
901
+ "UnusedCode",
902
+ "Complexity",
903
+ "BestPractice",
904
+ "Documentation"
905
+ ]);
906
+ var PATTERN_META = new Map(
907
+ patterns_default.map((p) => [
908
+ p.id,
909
+ {
910
+ category: VALID_CATEGORIES.has(p.category) ? p.category : "BestPractice",
911
+ severity: p.severityLevel ?? "Info"
912
+ }
913
+ ])
914
+ );
915
+ function ruleMetadata(ruleName) {
916
+ const patternId = `${TOOL_ID}_${ruleName}`;
917
+ return PATTERN_META.get(patternId) ?? { category: "BestPractice", severity: "Info" };
918
+ }
919
+ function getLineContent(lines, lineNumber) {
920
+ return lines[lineNumber - 1] ?? "";
921
+ }
922
+ async function readFileLines(filePath) {
923
+ try {
924
+ const content = await import_promises.default.readFile(filePath, "utf-8");
925
+ return content.split("\n");
926
+ } catch {
927
+ return [];
928
+ }
929
+ }
930
+ function buildResult(startedAt, completedAt, issues, errors, filesAnalyzed) {
931
+ const durationMs = completedAt.getTime() - startedAt.getTime();
932
+ return {
933
+ metadata: {
934
+ startedAt: startedAt.toISOString(),
935
+ completedAt: completedAt.toISOString(),
936
+ durationMs
937
+ },
938
+ issues,
939
+ errors,
940
+ summary: {
941
+ toolId: TOOL_ID,
942
+ status: errors.some((e) => e.level === "error") ? "partial" : "success",
943
+ issueCount: issues.length,
944
+ errorCount: errors.length,
945
+ durationMs,
946
+ filesAnalyzed
947
+ }
948
+ };
949
+ }
950
+ var BINARY = "revive";
951
+ var PLATFORM_MAP = {
952
+ "darwin-arm64": "darwin_arm64",
953
+ "darwin-x64": "darwin_amd64",
954
+ "linux-x64": "linux_amd64",
955
+ "linux-arm64": "linux_arm64"
956
+ };
957
+ async function getVersionFromBinary(binaryPath) {
958
+ try {
959
+ const { stdout, exitCode } = await (0, import_tooling.spawnTool)(binaryPath, ["-version"], {
960
+ cwd: process.cwd()
961
+ });
962
+ if (exitCode !== 0) return null;
963
+ const match = stdout.match(/(\d+\.\d+\.\d+)/);
964
+ return match ? match[1] : null;
965
+ } catch {
966
+ return null;
967
+ }
968
+ }
969
+ async function resolveBinaryPath(ctx) {
970
+ const codacyBin = import_path.default.join(ctx.toolInstallDir, BINARY);
971
+ const version = await getVersionFromBinary(codacyBin);
972
+ if (version) return codacyBin;
973
+ return BINARY;
974
+ }
975
+ function generateReviveToml(patterns) {
976
+ const lines = [];
977
+ lines.push("confidence = 0.0");
978
+ lines.push("");
979
+ for (const pattern of patterns) {
980
+ const ruleName = pattern.patternId.replace(`${TOOL_ID}_`, "");
981
+ lines.push(`[rule.${ruleName}]`);
982
+ if (pattern.parameters && pattern.parameters.length > 0) {
983
+ const args = pattern.parameters.map((p) => {
984
+ const num = Number(p.value);
985
+ if (!isNaN(num) && String(p.value).trim() !== "") {
986
+ return String(num);
987
+ }
988
+ return `"${String(p.value)}"`;
989
+ });
990
+ lines.push(` arguments = [${args.join(", ")}]`);
991
+ }
992
+ lines.push("");
993
+ }
994
+ return lines.join("\n");
995
+ }
996
+ var adapter = {
997
+ id: TOOL_ID,
998
+ displayName: "Revive",
999
+ preferredVersion: "1.12.0",
1000
+ compatibleVersions: ">=1.0.0",
1001
+ website: "https://github.com/mgechev/revive",
1002
+ languages: ["Go"],
1003
+ filePatterns: ["**/*.go"],
1004
+ supportedOS: ["linux", "darwin"],
1005
+ supportedArch: ["x64", "arm64"],
1006
+ supportedRunners: ["local", "container"],
1007
+ prerequisites: [],
1008
+ /**
1009
+ * Checks whether the `revive` binary is present and runnable.
1010
+ *
1011
+ * Checks in order:
1012
+ * 1. Codacy-managed path (`ctx.toolInstallDir/revive`) -> installation: "codacy"
1013
+ * 2. Global PATH (`revive`) -> installation: "global"
1014
+ *
1015
+ * Also probes for Go runtime availability via findGo(), reporting it as a
1016
+ * dependency. Go is needed for type-checked rules but revive can still run
1017
+ * basic rules without it.
1018
+ */
1019
+ async checkAvailability(ctx) {
1020
+ ctx.logger.debug("Checking availability", { toolId: TOOL_ID });
1021
+ const goInfo = await (0, import_tooling.findGo)(">=1.21", ctx.logger);
1022
+ const goDep = goInfo ? { name: "go", version: goInfo.version, path: goInfo.path, available: true } : { name: "go", available: false, reason: "Go not found; type-checked rules may not work" };
1023
+ const codacyBin = import_path.default.join(ctx.toolInstallDir, BINARY);
1024
+ const codacyVersion = await getVersionFromBinary(codacyBin);
1025
+ if (codacyVersion) {
1026
+ ctx.logger.debug("Found codacy-managed binary", {
1027
+ toolId: TOOL_ID,
1028
+ version: codacyVersion,
1029
+ path: codacyBin
1030
+ });
1031
+ return {
1032
+ available: true,
1033
+ version: codacyVersion,
1034
+ path: codacyBin,
1035
+ installation: "codacy",
1036
+ dependencies: [goDep]
1037
+ };
1038
+ }
1039
+ const globalVersion = await getVersionFromBinary(BINARY);
1040
+ if (globalVersion) {
1041
+ ctx.logger.debug("Found global binary", { toolId: TOOL_ID, version: globalVersion });
1042
+ return {
1043
+ available: true,
1044
+ version: globalVersion,
1045
+ installation: "global",
1046
+ dependencies: [goDep]
1047
+ };
1048
+ }
1049
+ ctx.logger.debug("Binary not found", {
1050
+ toolId: TOOL_ID,
1051
+ reason: "not in PATH or Codacy install directory"
1052
+ });
1053
+ return {
1054
+ available: false,
1055
+ reason: "revive binary not found in PATH or Codacy install directory",
1056
+ installHint: "go install github.com/mgechev/revive@latest # install via Go\ncodacy-analysis analyze . --install-dependencies # auto-install"
1057
+ };
1058
+ },
1059
+ /**
1060
+ * Downloads the revive binary from GitHub releases and ensures the Go
1061
+ * toolchain is available for type-checked analysis rules.
1062
+ *
1063
+ * 1. Downloads the pre-built revive binary (tar.gz) and extracts it.
1064
+ * 2. Downloads the Go SDK via ensureGo() if not already present.
1065
+ */
1066
+ async install(ctx) {
1067
+ ctx.logger.info("Starting install", { toolId: TOOL_ID });
1068
+ const platformKey = `${ctx.platform.os}-${ctx.platform.arch}`;
1069
+ const platformSuffix = PLATFORM_MAP[platformKey];
1070
+ if (!platformSuffix) {
1071
+ return {
1072
+ success: false,
1073
+ error: {
1074
+ toolId: TOOL_ID,
1075
+ phase: "toolInstall",
1076
+ kind: "UnsupportedPlatform",
1077
+ message: `Unsupported platform: ${platformKey}. Supported: ${Object.keys(PLATFORM_MAP).join(", ")}`,
1078
+ level: "error"
1079
+ }
1080
+ };
1081
+ }
1082
+ const version = adapter.preferredVersion;
1083
+ const url = `https://github.com/mgechev/revive/releases/download/v${version}/revive_${platformSuffix}.tar.gz`;
1084
+ const destDir = ctx.toolInstallDir;
1085
+ try {
1086
+ ctx.logger.info(`Downloading revive v${version} for ${platformKey}...`);
1087
+ await import_promises.default.mkdir(destDir, { recursive: true });
1088
+ await (0, import_tooling.downloadAndExtract)(url, destDir, void 0, ctx.logger);
1089
+ const destPath = import_path.default.join(destDir, BINARY);
1090
+ await import_promises.default.chmod(destPath, 493);
1091
+ ctx.logger.info(`Installed revive v${version} to ${destPath}`);
1092
+ } catch (err) {
1093
+ return {
1094
+ success: false,
1095
+ error: {
1096
+ toolId: TOOL_ID,
1097
+ phase: "toolInstall",
1098
+ kind: "DownloadError",
1099
+ message: `Failed to download revive: ${err instanceof Error ? err.message : String(err)}`,
1100
+ level: "error"
1101
+ }
1102
+ };
1103
+ }
1104
+ try {
1105
+ const goInfo = await (0, import_tooling.ensureGo)(ctx.globalDir, ">=1.21", ctx.logger);
1106
+ if (goInfo) {
1107
+ ctx.logger.info(`Go toolchain ready: v${goInfo.version} at ${goInfo.path}`);
1108
+ } else {
1109
+ ctx.logger.warn("Could not obtain Go toolchain; type-checked rules may not work");
1110
+ }
1111
+ } catch (err) {
1112
+ ctx.logger.warn(
1113
+ `Failed to set up Go toolchain: ${err instanceof Error ? err.message : String(err)}`
1114
+ );
1115
+ }
1116
+ return {
1117
+ success: true,
1118
+ installedPath: import_path.default.join(destDir, BINARY),
1119
+ installedVersion: version
1120
+ };
1121
+ },
1122
+ /**
1123
+ * Checks for `revive.toml` in the repository root.
1124
+ *
1125
+ * Revive uses TOML configuration files. The conventional name is `revive.toml`.
1126
+ */
1127
+ async checkLocalConfigurationFile(ctx) {
1128
+ ctx.logger.debug("Checking for local config", { toolId: TOOL_ID });
1129
+ const candidate = import_path.default.join(ctx.repositoryRoot, "revive.toml");
1130
+ try {
1131
+ await import_promises.default.access(candidate);
1132
+ ctx.logger.debug("Local config found", { toolId: TOOL_ID, path: candidate });
1133
+ return { found: true, path: candidate };
1134
+ } catch {
1135
+ }
1136
+ return { found: false };
1137
+ },
1138
+ /**
1139
+ * Runs `revive -formatter json -set_exit_status` against Go source files
1140
+ * and converts the JSON output into Codacy Issue objects.
1141
+ *
1142
+ * Config resolution:
1143
+ * - If `useLocalConfigurationFile` is true and `localConfigurationFile` is
1144
+ * set, passes `-config <path>` to revive.
1145
+ * - If patterns are provided (but no local config), generates a TOML config
1146
+ * enabling exactly those rules and passes it via `-config`.
1147
+ * - If no patterns and no local config, skips execution.
1148
+ *
1149
+ * Before running revive, if the project has a go.mod, runs `go mod download`
1150
+ * to fetch dependencies needed for type-checked analysis.
1151
+ *
1152
+ * Exit codes:
1153
+ * - 0: success, no issues found
1154
+ * - 1: success, issues found (normal — not treated as an error)
1155
+ *
1156
+ * Never throws — all errors are captured in the returned `errors` array.
1157
+ */
1158
+ async analyze(ctx, codacyConfig) {
1159
+ const startMs = Date.now();
1160
+ ctx.logger.info("Starting analysis", { toolId: TOOL_ID, fileCount: ctx.targetFiles.length });
1161
+ const startedAt = /* @__PURE__ */ new Date();
1162
+ const issues = [];
1163
+ const errors = [];
1164
+ if (ctx.targetFiles.length === 0) {
1165
+ return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, 0);
1166
+ }
1167
+ let configPath;
1168
+ if (codacyConfig.useLocalConfigurationFile && codacyConfig.localConfigurationFile) {
1169
+ configPath = codacyConfig.localConfigurationFile;
1170
+ } else if (codacyConfig.patterns.length > 0) {
1171
+ const tomlContent = generateReviveToml(codacyConfig.patterns);
1172
+ await import_promises.default.mkdir(ctx.generatedConfigDir, { recursive: true });
1173
+ configPath = import_path.default.join(ctx.generatedConfigDir, "revive.toml");
1174
+ await import_promises.default.writeFile(configPath, tomlContent, "utf-8");
1175
+ ctx.logger.debug("Generated revive config", { path: configPath });
1176
+ } else {
1177
+ ctx.logger.info("Skipping analysis: no local config and no patterns enabled", {
1178
+ toolId: TOOL_ID
1179
+ });
1180
+ return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
1181
+ }
1182
+ const binary = await resolveBinaryPath(ctx);
1183
+ const goInfo = await (0, import_tooling.findGo)(">=1.21", ctx.logger);
1184
+ let goEnv;
1185
+ if (goInfo) {
1186
+ goEnv = (0, import_tooling.buildGoEnv)(goInfo, ctx.globalDir);
1187
+ await (0, import_tooling.goModDownload)(goInfo, ctx.repositoryRoot, goEnv, ctx.logger);
1188
+ } else {
1189
+ ctx.logger.debug("Go not available; type-checked rules may produce errors");
1190
+ }
1191
+ const absoluteFiles = ctx.targetFiles.map((f) => import_path.default.resolve(ctx.repositoryRoot, f));
1192
+ const args = ["-formatter", "json", "-set_exit_status"];
1193
+ if (configPath) {
1194
+ args.push("-config", configPath);
1195
+ }
1196
+ args.push(...absoluteFiles);
1197
+ try {
1198
+ const spawnOpts = {
1199
+ cwd: ctx.repositoryRoot,
1200
+ logger: ctx.logger
1201
+ };
1202
+ if (goEnv) {
1203
+ spawnOpts.env = goEnv;
1204
+ }
1205
+ const { stdout, stderr, exitCode } = await (0, import_tooling.spawnTool)(binary, args, spawnOpts);
1206
+ if (exitCode >= 2) {
1207
+ errors.push({
1208
+ toolId: TOOL_ID,
1209
+ phase: "toolInvoke",
1210
+ kind: "NonZeroExit",
1211
+ message: `revive exited with code ${exitCode}${stderr ? `: ${stderr.trim()}` : ""}`,
1212
+ level: "error"
1213
+ });
1214
+ return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
1215
+ }
1216
+ if (!stdout.trim()) {
1217
+ return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
1218
+ }
1219
+ let findings;
1220
+ try {
1221
+ findings = JSON.parse(stdout);
1222
+ } catch (err) {
1223
+ errors.push({
1224
+ toolId: TOOL_ID,
1225
+ phase: "outputParse",
1226
+ kind: "MalformedOutput",
1227
+ message: `Failed to parse revive JSON output: ${err instanceof Error ? err.message : String(err)}`,
1228
+ level: "error"
1229
+ });
1230
+ return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
1231
+ }
1232
+ const enabledPatterns = new Set(codacyConfig.patterns.map((p) => p.patternId));
1233
+ const findingsByFile = /* @__PURE__ */ new Map();
1234
+ for (const finding of findings) {
1235
+ const filePath = finding.Position.Start.Filename;
1236
+ const list = findingsByFile.get(filePath) ?? [];
1237
+ list.push(finding);
1238
+ findingsByFile.set(filePath, list);
1239
+ }
1240
+ for (const [filePath, fileFindings] of findingsByFile) {
1241
+ const absoluteFilePath = import_path.default.isAbsolute(filePath) ? filePath : import_path.default.resolve(ctx.repositoryRoot, filePath);
1242
+ const lines = await readFileLines(absoluteFilePath);
1243
+ const relPath = import_path.default.isAbsolute(filePath) ? import_path.default.relative(ctx.repositoryRoot, filePath) : filePath;
1244
+ for (const finding of fileFindings) {
1245
+ const patternId = `${TOOL_ID}_${finding.RuleName}`;
1246
+ if (enabledPatterns.size > 0 && !enabledPatterns.has(patternId)) {
1247
+ continue;
1248
+ }
1249
+ const meta = ruleMetadata(finding.RuleName);
1250
+ const line = Math.max(finding.Position.Start.Line, 1);
1251
+ const column = Math.max(finding.Position.Start.Column, 1);
1252
+ const endLine = finding.Position.End.Line > 0 ? finding.Position.End.Line : void 0;
1253
+ const endColumn = finding.Position.End.Column > 0 ? finding.Position.End.Column : void 0;
1254
+ issues.push({
1255
+ filePath: relPath,
1256
+ patternId,
1257
+ toolId: TOOL_ID,
1258
+ line,
1259
+ column,
1260
+ endLine,
1261
+ endColumn,
1262
+ message: finding.Failure,
1263
+ lineContent: getLineContent(lines, line),
1264
+ multilineContent: (0, import_tooling.getMultilineContent)(lines, line, endLine),
1265
+ category: meta.category,
1266
+ severity: meta.severity
1267
+ });
1268
+ }
1269
+ }
1270
+ if (stderr.trim()) {
1271
+ errors.push({
1272
+ toolId: TOOL_ID,
1273
+ phase: "outputParse",
1274
+ kind: "ParseWarning",
1275
+ message: `revive stderr: ${stderr.trim()}`,
1276
+ level: "warning"
1277
+ });
1278
+ }
1279
+ } catch (err) {
1280
+ errors.push({
1281
+ toolId: TOOL_ID,
1282
+ phase: "toolInvoke",
1283
+ kind: "InvocationError",
1284
+ message: `Failed to run revive: ${err instanceof Error ? err.message : String(err)}`,
1285
+ level: "error"
1286
+ });
1287
+ }
1288
+ const durationMs = Date.now() - startMs;
1289
+ ctx.logger.info("Analysis complete", {
1290
+ toolId: TOOL_ID,
1291
+ issueCount: issues.length,
1292
+ errorCount: errors.length,
1293
+ durationMs
1294
+ });
1295
+ return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
1296
+ }
1297
+ };
1298
+
1299
+ // src/index.ts
1300
+ var index_default = (0, import_tooling2.defineToolAdapter)(adapter);