This repository has been archived by the owner on Aug 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 785
/
Copy pathdiagnostics_spec.lua
2180 lines (2075 loc) · 81.5 KB
/
diagnostics_spec.lua
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local mock = require("luassert.mock")
local stub = require("luassert.stub")
local spy = require("luassert.spy")
local diagnostics = require("null-ls.builtins").diagnostics
mock(require("null-ls.logger"), true)
describe("diagnostics", function()
describe("spectral", function()
local linter = diagnostics.spectral
local parser = linter._opts.on_output
it("should create a diagnostic with an Warning severity", function()
local output = vim.json.decode([[
[
{
"code": "oas3-operation-security-defined",
"path": [
"security",
"0",
"bearer"
],
"message": "API \"security\" values must match a scheme defined in the \"components.securitySchemes\" object.",
"severity": 1,
"range": {
"start": {
"line": 659,
"character": 11
},
"end": {
"line": 659,
"character": 14
}
},
"source": "/home/luizcorreia/repos/smiles/OpenApi/openapi.yaml"
}
]
]])
local diagnostic = parser({ output = output })
assert.same({
{
code = "oas3-operation-security-defined",
col = 11,
end_col = 14,
end_row = 660,
message = 'API "security" values must match a scheme defined in the "components.securitySchemes" object.',
path = { "security", "0", "bearer" },
row = 660,
severity = 2,
source = "Spectral",
},
}, diagnostic)
end)
end)
describe("buf", function()
local linter = diagnostics.buf
local parser = linter._opts.on_output
it("should create a diagnostic with an Error severity", function()
local file = {
[[ syntax = "proto3"; package tutorial.v1;]],
}
local output =
[[demo.proto:2:1:Files with package "tutorial.v1" must be within a directory "tutorial/v1" relative to root but were in directory ".".]]
local diagnostic = parser(output, { content = file })
assert.same({
col = "1",
filename = "demo.proto",
message = [[Files with package "tutorial.v1" must be within a directory "tutorial/v1" relative to root but were in directory ".".]],
row = "2",
}, diagnostic)
end)
end)
describe("chktex", function()
local linter = diagnostics.chktex
local parser = linter._opts.on_output
local file = {
[[\documentclass{article}]],
[[\begin{document}]],
[[Lorem ipsum dolor \sit amet]],
[[\end{document}]],
}
it("should create a diagnostic", function()
local output = [[3:23:1:Warning:1:Command terminated with space.]]
local diagnostic = parser(output, { content = file })
assert.same({
code = "1",
row = "3",
col = "23",
end_col = 24,
severity = 2,
message = "Command terminated with space.",
}, diagnostic)
end)
end)
describe("credo", function()
local linter = diagnostics.credo
local parser = linter._opts.on_output
local credo_diagnostics
local done = function(_diagnostics)
credo_diagnostics = _diagnostics
end
after_each(function()
credo_diagnostics = nil
end)
it("should create a diagnostic with error severity", function()
local output = [[
{
"issues": [
{
"category": "consistency",
"check": "Credo.Check.Consistency.SpaceInParentheses",
"column": null,
"column_end": null,
"filename": "lib/todo_web/controllers/page_controller.ex",
"line_no": 4,
"message": "There is no whitespace around parentheses/brackets most of the time, but here there is.",
"priority": 12,
"scope": "TodoWeb.PageController.index",
"trigger": "( c"
}
]
} ]]
parser({ output = output }, done)
assert.same({
{
source = "credo",
message = "There is no whitespace around parentheses/brackets most of the time, but here there is.",
row = 4,
col = nil,
end_col = nil,
severity = 1,
},
}, credo_diagnostics)
end)
it("should create a diagnostic with warning severity", function()
local output = [[
{
"issues": [{
"category": "readability",
"check": "Credo.Check.Readability.ImplTrue",
"column": 3,
"column_end": 13,
"filename": "./foo.ex",
"line_no": 3,
"message": "@impl true should be @impl MyBehaviour",
"priority": 8,
"scope": null,
"trigger": "@impl true"
}]
} ]]
parser({ output = output }, done)
assert.same({
{
source = "credo",
message = "@impl true should be @impl MyBehaviour",
row = 3,
col = 3,
end_col = 13,
severity = 2,
},
}, credo_diagnostics)
end)
it("should create a diagnostic with information severity", function()
local output = [[
{
"issues": [{
"category": "design",
"check": "Credo.Check.Design.TagTODO",
"column": null,
"column_end": null,
"filename": "./foo.ex",
"line_no": 8,
"message": "Found a TODO tag in a comment: \"TODO: implement check\"",
"priority": -5,
"scope": null,
"trigger": "TODO: implement check"
}]
} ]]
parser({ output = output }, done)
assert.same({
{
source = "credo",
message = 'Found a TODO tag in a comment: "TODO: implement check"',
row = 8,
col = nil,
end_col = nil,
severity = 3,
},
}, credo_diagnostics)
end)
it("should create a diagnostic falling back to hint severity", function()
local output = [[
{
"issues": [{
"category": "refactor",
"check": "Credo.Check.Refactor.FilterFilter",
"column": null,
"column_end": null,
"filename": "./foo.ex",
"line_no": 12,
"message": "One `Enum.filter/2` is more efficient than `Enum.filter/2 |> Enum.filter/2`",
"priority": -15,
"scope": null,
"trigger": "|>"
}]
} ]]
parser({ output = output }, done)
assert.same({
{
source = "credo",
message = "One `Enum.filter/2` is more efficient than `Enum.filter/2 |> Enum.filter/2`",
row = 12,
col = nil,
end_col = nil,
severity = 4,
},
}, credo_diagnostics)
end)
it("returns errors as diagnostics", function()
local error =
[[** (Mix) The task "credo" could not be found\nNote no mix.exs was found in the current directory]]
parser({ err = error }, done)
assert.same({
{
source = "credo",
message = error,
row = 1,
},
}, credo_diagnostics)
end)
it("should handle compile warnings preceeding output", function()
local output = [[
00:00:00.000 [warn] IMPORTING DEV.SECRET
{
"issues": [
{
"category": "consistency",
"check": "Credo.Check.Consistency.SpaceInParentheses",
"column": null,
"column_end": null,
"filename": "lib/todo_web/controllers/page_controller.ex",
"line_no": 4,
"message": "There is no whitespace around parentheses/brackets most of the time, but here there is.",
"priority": 12,
"scope": "TodoWeb.PageController.index",
"trigger": "( c"
}
]
} ]]
parser({ output = output }, done)
assert.same({
{
source = "credo",
message = "There is no whitespace around parentheses/brackets most of the time, but here there is.",
row = 4,
col = nil,
end_col = nil,
severity = 1,
},
}, credo_diagnostics)
end)
it("should handle messages with incomplete json", function()
local output = [[Some incomplete message that shouldn't really happen { "issues": ]]
parser({ output = output }, done)
assert.same({
{
source = "credo",
message = output,
row = 1,
},
}, credo_diagnostics)
end)
it("should handle messages without json", function()
local output = [[Another message that shouldn't really happen]]
parser({ output = output }, done)
assert.same({
{
source = "credo",
message = output,
row = 1,
},
}, credo_diagnostics)
end)
it("should return no errors when no output or errors", function()
parser({ output = nil, errors = nil }, done)
assert.same({}, credo_diagnostics)
end)
end)
describe("luacheck", function()
local linter = diagnostics.luacheck
local parser = linter._opts.on_output
local file = {
[[sx = {]],
}
it("should create a diagnostic", function()
local output = [[test.lua:2:1-1: (E011) expected expression near <eof>]]
local diagnostic = parser(output, { content = file })
assert.same({
code = "011",
row = "2",
col = "1",
end_col = 2,
severity = 1,
message = "expected expression near <eof>",
}, diagnostic)
end)
end)
describe("write-good", function()
local linter = diagnostics.write_good
local parser = linter._opts.on_output
local file = {
[[Any rule whose heading is ~~struck through~~ is deprecated, but still provided for backward-compatibility.]],
}
it("should create a diagnostic", function()
local output = [[rules.md:1:46:"is deprecated" may be passive voice]]
local diagnostic = parser(output, { content = file })
assert.same({
row = "1",
col = 47,
end_col = 59,
message = '"is deprecated" may be passive voice',
}, diagnostic)
end)
end)
describe("markdownlint", function()
local linter = diagnostics.markdownlint
local parser = linter._opts.on_output
local file = {
[[<a name="md001"></a>]],
[[]],
}
it("should create a diagnostic with a column", function()
local output = "rules.md:1:1 MD033/no-inline-html Inline HTML [Element: a]"
local diagnostic = parser(output, { content = file })
assert.same({
code = "MD033/no-inline-html",
row = "1",
col = "1",
message = "Inline HTML [Element: a]",
severity = 2,
}, diagnostic)
end)
it("should create a diagnostic without a column", function()
local output =
"rules.md:2 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2]"
local diagnostic = parser(output, { content = file })
assert.same({
row = "2",
code = "MD012/no-multiple-blanks",
message = "Multiple consecutive blank lines [Expected: 1; Actual: 2]",
severity = 2,
}, diagnostic)
end)
end)
describe("mdl", function()
local linter = diagnostics.mdl
local parser = linter._opts.on_output
it("should create a diagnostic", function()
local output = vim.json.decode([[
[
{
"filename": "rules.md",
"line": 1,
"rule": "MD022",
"aliases": [
"blanks-around-headers"
],
"description": "Headers should be surrounded by blank lines"
}
]
]])
local diagnostic = parser({ output = output })
assert.same({
{
code = "MD022",
row = 1,
severity = 2,
message = "Headers should be surrounded by blank lines",
},
}, diagnostic)
end)
end)
describe("tl check", function()
local linter = diagnostics.teal
local parser = linter._opts.on_output
local file = {
[[require("settings").load_options()]],
"vim.cmd [[ ]]",
"local b = 3 + 34",
}
local output = table.concat({
"1 warning:",
"tmp.tl:3:7: unused variable b: integer",
"2 errors:",
"tmp.tl:1:8: module not found: 'settings'",
"tmp.tl:2:1: unknown variable: vim",
}, "\n")
local teal_diagnostics = nil
local function done(_diagnostics)
teal_diagnostics = _diagnostics
end
parser({ content = file, output = output, temp_path = "tmp.tl" }, done)
it("should create a diagnostic with a warning severity (no quote)", function()
assert.same({
row = "3",
col = "7",
message = "unused variable b: integer",
severity = 2,
}, teal_diagnostics[1])
end)
it("should create a diagnostic with an error severity (quote field is between quotes)", function()
assert.same({
row = "1",
col = "8",
end_col = 18,
message = "module not found: 'settings'",
severity = 1,
}, teal_diagnostics[2])
end)
it("should create a diagnostic with an error severity (quote field is not between quotes)", function()
assert.same({
row = "2",
col = "1",
end_col = 4,
message = "unknown variable: vim",
severity = 1,
}, teal_diagnostics[3])
end)
end)
describe("shellcheck", function()
local linter = diagnostics.shellcheck
local parser = linter._opts.on_output
it("should create a diagnostic with info severity", function()
local output = vim.json.decode([[
{
"comments": [{
"file": "./OpenCast.sh",
"line": 21,
"endLine": 21,
"column": 8,
"endColumn": 37,
"level": "info",
"code": 1091,
"message": "Not following: script/cli_builder.sh was not specified as input (see shellcheck -x).",
"fix": null
}]
} ]])
local diagnostic = parser({ output = output })
assert.same({
{
code = 1091,
row = 21,
end_row = 21,
col = 8,
end_col = 37,
severity = 3,
message = "Not following: script/cli_builder.sh was not specified as input (see shellcheck -x).",
},
}, diagnostic)
end)
it("should create a diagnostic with style severity", function()
local output = vim.json.decode([[
{
"comments": [{
"file": "./OpenCast.sh",
"line": 21,
"endLine": 21,
"column": 8,
"endColumn": 37,
"level": "style",
"code": 1091,
"message": "Not following: script/cli_builder.sh was not specified as input (see shellcheck -x).",
"fix": null
}]
} ]])
local diagnostic = parser({ output = output })
assert.same({
{
code = 1091,
row = 21,
end_row = 21,
col = 8,
end_col = 37,
severity = 4,
message = "Not following: script/cli_builder.sh was not specified as input (see shellcheck -x).",
},
}, diagnostic)
end)
end)
describe("selene", function()
local linter = diagnostics.selene
local parser = linter._opts.on_output
local file = {
"vim.cmd [[",
[[CACHE_PATH = vim.fn.stdpath "cache"]],
}
it("should create a diagnostic (quote is between backquotes)", function()
local output = [[init.lua:1:1: error[undefined_variable]: `vim` is not defined]]
local diagnostic = parser(output, { content = file })
assert.same({
row = "1",
col = "1",
end_col = 4,
severity = 1,
code = "undefined_variable",
message = "`vim` is not defined",
}, diagnostic)
end)
it("should create a diagnostic (quote is not between backquotes)", function()
local output =
[[lua/default-config.lua:2:1: warning[unused_variable]: CACHE_PATH is defined, but never used]]
local diagnostic = parser(output, { content = file })
assert.same({
row = "2",
col = "1",
end_col = 11,
severity = 2,
code = "unused_variable",
message = "CACHE_PATH is defined, but never used",
}, diagnostic)
end)
end)
describe("solhint", function()
local linter = diagnostics.solhint
local parser = linter._opts.on_output
it("should create a diagnostic with an Error severity", function()
local file = {
[[ import 'interfaces/IToken.sol'; ]],
}
local output = "contracts/Token.sol:22:8: Use double quotes for string literals [Error/quotes]"
local diagnostic = parser(output, { content = file })
assert.same({
code = "quotes",
col = "8",
filename = "contracts/Token.sol",
message = "Use double quotes for string literals",
row = "22",
severity = 1,
}, diagnostic)
end)
it("should create a diagnostic with a Warning severity", function()
local file = {
[[ function somethingPrivate(uint8 id) returns (bool) {}; ]],
}
local output = "contracts/Token.sol:359:5: Explicitly mark visibility in function [Warning/func-visibility]"
local diagnostic = parser(output, { content = file })
assert.same({
code = "func-visibility",
col = "5",
filename = "contracts/Token.sol",
message = "Explicitly mark visibility in function",
row = "359",
severity = 2,
}, diagnostic)
end)
end)
describe("eslint", function()
local linter = diagnostics.eslint
local parser = linter._opts.on_output
describe("with non fixable diagnostic", function()
it("should create a diagnostic with warning severity", function()
local output = vim.json.decode([[
[{
"filePath": "/home/luc/Projects/Pi-OpenCast/webapp/src/index.js",
"messages": [
{
"ruleId": "quotes",
"severity": 1,
"message": "Strings must use singlequote.",
"line": 1,
"column": 19,
"nodeType": "Literal",
"messageId": "wrongQuotes",
"endLine": 1,
"endColumn": 26
}
]
}] ]])
local diagnostic = parser({ output = output })
assert.same({
{
row = 1,
end_row = 1,
col = 19,
end_col = 26,
severity = 2,
code = "quotes",
message = "Strings must use singlequote.",
user_data = {
fixable = false,
},
},
}, diagnostic)
end)
it("should create a diagnostic with error severity", function()
local output = vim.json.decode([[
[{
"filePath": "/home/luc/Projects/Pi-OpenCast/webapp/src/index.js",
"messages": [
{
"ruleId": "quotes",
"severity": 2,
"message": "Strings must use singlequote.",
"line": 1,
"column": 19,
"nodeType": "Literal",
"messageId": "wrongQuotes",
"endLine": 1,
"endColumn": 26
}
]
}] ]])
local diagnostic = parser({ output = output })
assert.same({
{
row = 1,
end_row = 1,
col = 19,
end_col = 26,
severity = 1,
code = "quotes",
message = "Strings must use singlequote.",
user_data = {
fixable = false,
},
},
}, diagnostic)
end)
end)
describe("with fixable diagnostic", function()
it("should create a diagnostic with warning severity", function()
local output = vim.json.decode([[
[{
"filePath": "/home/luc/Projects/Pi-OpenCast/webapp/src/index.js",
"messages": [
{
"ruleId": "quotes",
"severity": 1,
"message": "Strings must use singlequote.",
"line": 1,
"column": 19,
"nodeType": "Literal",
"messageId": "wrongQuotes",
"endLine": 1,
"endColumn": 26,
"fix": {
"range": [
18,
25
],
"text": "'react'"
}
}
]
}] ]])
local diagnostic = parser({ output = output })
assert.same({
{
row = 1,
end_row = 1,
col = 19,
end_col = 26,
severity = 2,
code = "quotes",
message = "Strings must use singlequote.",
user_data = {
fixable = true,
},
},
}, diagnostic)
end)
it("should create a diagnostic with error severity", function()
local output = vim.json.decode([[
[{
"filePath": "/home/luc/Projects/Pi-OpenCast/webapp/src/index.js",
"messages": [
{
"ruleId": "quotes",
"severity": 2,
"message": "Strings must use singlequote.",
"line": 1,
"column": 19,
"nodeType": "Literal",
"messageId": "wrongQuotes",
"endLine": 1,
"endColumn": 26,
"fix": {
"range": [
18,
25
],
"text": "'react'"
}
}
]
}] ]])
local diagnostic = parser({ output = output })
assert.same({
{
row = 1,
end_row = 1,
col = 19,
end_col = 26,
severity = 1,
code = "quotes",
message = "Strings must use singlequote.",
user_data = {
fixable = true,
},
},
}, diagnostic)
end)
end)
end)
describe("standardjs", function()
local linter = diagnostics.standardjs
local parser = linter._opts.on_output
it("should create a diagnostic with error severity", function()
local file = {
[[export const foo = () => { return 'hello']],
}
local output = [[rules.js:1:2: Parsing error: Unexpected token]]
local diagnostic = parser(output, { content = file })
assert.same({
row = "1",
col = "2",
severity = 1,
message = "Unexpected token",
}, diagnostic)
end)
it("should create a diagnostic with warning severity", function()
local file = {
[[export const foo = () => { return "hello" }]],
}
local output = [[rules.js:1:35: Strings must use singlequote.]]
local diagnostic = parser(output, { content = file })
assert.same({
row = "1",
col = "35",
severity = 2,
message = "Strings must use singlequote.",
}, diagnostic)
end)
end)
describe("hadolint", function()
local linter = diagnostics.hadolint
local parser = linter._opts.on_output
it("should create a diagnostic with warning severity", function()
local output = vim.json.decode([[
[{
"line": 24,
"code": "DL3008",
"message": "Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`",
"column": 1,
"file": "/home/luc/Projects/Test/buildroot/support/docker/Dockerfile",
"level": "warning"
}]
]])
local diagnostic = parser({ output = output })
assert.same({
{
row = 24,
col = 1,
severity = 2,
code = "DL3008",
message = "Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`",
},
}, diagnostic)
end)
it("should create a diagnostic with info severity", function()
local output = vim.json.decode([[
[{
"line": 24,
"code": "DL3059",
"message": "Multiple consecutive `RUN` instructions. Consider consolidation.",
"column": 1,
"file": "/home/luc/Projects/Test/buildroot/support/docker/Dockerfile",
"level": "info"
}]
]])
local diagnostic = parser({ output = output })
assert.same({
{
row = 24,
col = 1,
severity = 3,
code = "DL3059",
message = "Multiple consecutive `RUN` instructions. Consider consolidation.",
},
}, diagnostic)
end)
end)
describe("flake8", function()
local linter = diagnostics.flake8
local parser = linter._opts.on_output
local file = {
[[#===- run-clang-tidy.py - Parallel clang-tidy runner ---------*- python -*--===#]],
}
it("should create a diagnostic", function()
local output = [[run-clang-tidy.py:3:1: E265 block comment should start with '# ']]
local diagnostic = parser(output, { content = file })
assert.same({
row = "3",
col = "1",
severity = 1,
code = "E265",
message = "block comment should start with '# '",
}, diagnostic)
end)
end)
describe("pylint", function()
local linter = diagnostics.pylint
local parser = linter._opts.on_output
local u = require("null-ls.utils")
local params = { bufnr = 4, bufname = "test" }
local root_pattern
local output = vim.json.decode([[
[
{
"type": "convention",
"module": "test",
"obj": "",
"line": 1,
"column": 0,
"endLine": null,
"endColumn": null,
"path": "test.py",
"symbol": "missing-module-docstring",
"message": "Missing module docstring",
"message-id": "C0114"
},
{
"type": "convention",
"module": "test",
"obj": "",
"line": 1,
"column": 0,
"endLine": 1,
"endColumn": 1,
"path": "test.py",
"symbol": "invalid-name",
"message": "Constant name \"s\" doesn't conform to UPPER_CASE naming style",
"message-id": "C0103"
}
]
]])
before_each(function()
root_pattern = stub(u, "root_pattern")
end)
after_each(function()
root_pattern:revert()
end)
it("should set the cwd param", function()
assert.truthy(type(linter._opts.cwd) == "function")
local s = spy.new(function(loc_params)
return loc_params
end)
root_pattern.returns(s)
local cwd = linter._opts.cwd(params)
assert.same(params.bufname, cwd)
assert.stub(root_pattern).was.called_with("pylintrc", ".pylintrc", "pyproject.toml", "setup.cfg", "tox.ini")
assert.spy(s).was.called_with(params.bufname)
end)
it("should create a diagnostic from json output", function()
local diagnostic = parser({ output = output })
assert.same({
{
code = "missing-module-docstring",
col = 1,
message_id = "C0114",
message = "Missing module docstring",
row = 1,
severity = 3,
symbol = "missing-module-docstring",
},
{
row = 1,
col = 1,
severity = 3,
code = "invalid-name",
message_id = "C0103",
message = 'Constant name "s" doesn\'t conform to UPPER_CASE naming style',
symbol = "invalid-name",
end_col = 2,
end_row = 1,
},
}, diagnostic)
end)
end)
describe("pylama", function()
local linter = diagnostics.pylama
local parser = linter._opts.on_output
local exit_func = linter._opts.check_exit_code
it("should create a diagnostic with error severity", function()
local output = vim.json.decode([[
[{
"lnum": 3,
"col": 1,
"etype": "E",
"message": "block comment should start with '# '",
"number": "E265",
"source": "run-clang-tidy.py"
}]
]])
local diagnostic = parser({ output = output })
assert.same({
{
row = 3,
col = 1,
severity = 1,
code = "E265",
message = "block comment should start with '# '",
source = "run-clang-tidy.py",
},
}, diagnostic)
end)
it("should count exit code of 1 as success", function()
assert.is.True(exit_func(1))
assert.is.True(exit_func(0))
assert.is.False(exit_func(255))
end)
end)
describe("misspell", function()
local linter = diagnostics.misspell
local parser = linter._opts.on_output
local file = {
[[Did I misspell langauge ?]],
}
it("should create a diagnostic", function()
local output = [[stdin:1:15: "langauge" is a misspelling of "language"]]
local diagnostic = parser(output, { content = file })
assert.same({
row = "1",
col = 16,
severity = 3,
message = [["langauge" is a misspelling of "language"]],
}, diagnostic)
end)
end)
describe("vint", function()
local linter = diagnostics.vint
local parser = linter._opts.on_output
it("should create a diagnostic with warning severity", function()
local output = vim.json.decode([[
[{
"file_path": "/home/luc/Projects/Test/vim-scriptease/plugin/scriptease.vim",
"line_number": 5,
"column_number": 37,
"severity": "style_problem",
"description": "Use the full option name `compatible` instead of `cp`",
"policy_name": "ProhibitAbbreviationOption",
"reference": ":help option-summary"
}]
]])
local diagnostic = parser({ output = output })