Skip to content

Commit 4baf971

Browse files
committed
Update ignore parser to not include *) from block comments
1 parent 6450c35 commit 4baf971

File tree

2 files changed

+118
-5
lines changed

2 files changed

+118
-5
lines changed

samples/OptionAnalyzer.Test/UnitTests.fs

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,119 @@ module IgnoreRangeTests =
425425
Assert.That(ctx.AnalyzerIgnoreRanges, Is.Empty)
426426
}
427427

428+
[<Test>]
429+
let ``block comment ignore-line-next does not include trailing asterisk parenthesis`` () =
430+
async {
431+
let source =
432+
"""
433+
module M
434+
(* fsharpanalyzer: ignore-line-next IONIDE-001 *)
435+
let x = 1
436+
"""
437+
438+
let ctx = getContext projectOptions source
439+
440+
ctx.AnalyzerIgnoreRanges
441+
|> tryCompareRanges "IONIDE-001" [ NextLine 3 ]
442+
}
443+
444+
[<Test>]
445+
let ``block comment ignore-line does not include trailing asterisk parenthesis`` () =
446+
async {
447+
let source =
448+
"""
449+
module M
450+
let x = 1 (* fsharpanalyzer: ignore-line IONIDE-001 *)
451+
"""
452+
453+
let ctx = getContext projectOptions source
454+
455+
ctx.AnalyzerIgnoreRanges
456+
|> tryCompareRanges "IONIDE-001" [ CurrentLine 3 ]
457+
}
458+
459+
[<Test>]
460+
let ``block comment ignore-file does not include trailing asterisk parenthesis`` () =
461+
async {
462+
let source =
463+
"""
464+
(* fsharpanalyzer: ignore-file IONIDE-001 *)
465+
module M
466+
let x = 1
467+
"""
468+
469+
let ctx = getContext projectOptions source
470+
471+
ctx.AnalyzerIgnoreRanges
472+
|> tryCompareRanges "IONIDE-001" [ File ]
473+
}
474+
475+
[<Test>]
476+
let ``block comment ignore-region-start does not include trailing asterisk parenthesis`` () =
477+
async {
478+
let source =
479+
"""
480+
module M
481+
(* fsharpanalyzer: ignore-region-start IONIDE-001 *)
482+
let x = 1
483+
(* fsharpanalyzer: ignore-region-end *)
484+
"""
485+
486+
let ctx = getContext projectOptions source
487+
488+
ctx.AnalyzerIgnoreRanges
489+
|> tryCompareRanges "IONIDE-001" [ Range(3, 5) ]
490+
}
491+
492+
[<Test>]
493+
let ``block comment with multiple codes does not include trailing asterisk parenthesis`` () =
494+
async {
495+
let source =
496+
"""
497+
module M
498+
(* fsharpanalyzer: ignore-line-next IONIDE-001, IONIDE-002, IONIDE-003 *)
499+
let x = 1
500+
"""
501+
502+
let ctx = getContext projectOptions source
503+
504+
ctx.AnalyzerIgnoreRanges
505+
|> tryCompareRanges "IONIDE-001" [ NextLine 3 ]
506+
507+
ctx.AnalyzerIgnoreRanges
508+
|> tryCompareRanges "IONIDE-002" [ NextLine 3 ]
509+
510+
ctx.AnalyzerIgnoreRanges
511+
|> tryCompareRanges "IONIDE-003" [ NextLine 3 ]
512+
}
513+
514+
[<Test>]
515+
let ``mixed line and block comments work correctly`` () =
516+
async {
517+
let source =
518+
"""
519+
module M
520+
// fsharpanalyzer: ignore-line-next IONIDE-001
521+
(* fsharpanalyzer: ignore-line-next IONIDE-002 *)
522+
let x = 1 // fsharpanalyzer: ignore-line IONIDE-003
523+
let y = 2 (* fsharpanalyzer: ignore-line IONIDE-004 *)
524+
"""
525+
526+
let ctx = getContext projectOptions source
527+
528+
ctx.AnalyzerIgnoreRanges
529+
|> tryCompareRanges "IONIDE-001" [ NextLine 3 ]
530+
531+
ctx.AnalyzerIgnoreRanges
532+
|> tryCompareRanges "IONIDE-002" [ NextLine 4 ]
533+
534+
ctx.AnalyzerIgnoreRanges
535+
|> tryCompareRanges "IONIDE-003" [ CurrentLine 5 ]
536+
537+
ctx.AnalyzerIgnoreRanges
538+
|> tryCompareRanges "IONIDE-004" [ CurrentLine 6 ]
539+
}
540+
428541
module ClientTests =
429542

430543
module RunAnalyzersSafelyTests =

src/FSharp.Analyzers.SDK/FSharp.Analyzers.SDK.fs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,19 @@ module Ignore =
6969
- 1
7070
)
7171
with
72-
| ParseRegexCompiled @"fsharpanalyzer:\signore-line-next\s(.*)$" [ SplitBy splitBy codes ] ->
72+
| ParseRegexCompiled @"fsharpanalyzer:\signore-line-next\s(.*?)(?:\*\)|$)" [ SplitBy splitBy codes ] ->
7373
Some
7474
<| IgnoreComment.NextLine(r.StartLine, trimCodes codes)
75-
| ParseRegexCompiled @"fsharpanalyzer:\signore-line\s(.*)$" [ SplitBy splitBy codes ] ->
75+
| ParseRegexCompiled @"fsharpanalyzer:\signore-line\s(.*?)(?:\*\)|$)" [ SplitBy splitBy codes ] ->
7676
Some
7777
<| IgnoreComment.CurrentLine(r.StartLine, trimCodes codes)
78-
| ParseRegexCompiled @"fsharpanalyzer:\signore-file\s(.*)$" [ SplitBy splitBy codes ] ->
78+
| ParseRegexCompiled @"fsharpanalyzer:\signore-file\s(.*?)(?:\*\)|$)" [ SplitBy splitBy codes ] ->
7979
Some
8080
<| IgnoreComment.File(trimCodes codes)
81-
| ParseRegexCompiled @"fsharpanalyzer:\signore-region-start\s(.*)$" [ SplitBy splitBy codes ] ->
81+
| ParseRegexCompiled @"fsharpanalyzer:\signore-region-start\s(.*?)(?:\*\)|$)" [ SplitBy splitBy codes ] ->
8282
Some
8383
<| IgnoreComment.RegionStart(r.StartLine, trimCodes codes)
84-
| ParseRegexCompiled @"fsharpanalyzer:\signore-region-end.*$" _ ->
84+
| ParseRegexCompiled @"fsharpanalyzer:\signore-region-end(?:.*?)(?:\*\)|$)" _ ->
8585
Some
8686
<| IgnoreComment.RegionEnd r.StartLine
8787
| _ -> None

0 commit comments

Comments
 (0)