Skip to content

Commit 782fb61

Browse files
committed
Bump version to 1.2.1 and fix CSLINT230 preprocessor directive false positive
🤖 Co-Authored-By: Claude Code <noreply@anthropic.com>
1 parent 9940a51 commit 782fb61

File tree

7 files changed

+62
-2
lines changed

7 files changed

+62
-2
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
## [Unreleased]
44

5+
## [1.2.1] - 2026-03-18
6+
7+
### Added
8+
- Add `--version` CLI option
9+
10+
### Fixed
11+
- Fix CSLINT230 false positive when preprocessor directives appear between a block and the next statement
12+
- Fix test project build when semantic rules are excluded
13+
514
## [1.2.0] - 2026-03-16
615

716
### Added

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ cslint --list-rules
7676
# Show resolved .editorconfig settings for a path
7777
cslint --show-config .
7878
cslint --show-config src/MyFile.cs
79+
80+
# Show version
81+
cslint --version
7982
```
8083

8184
### Exit codes

src/CsLint.Cli/CsLint.Cli.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<!-- NuGet -->
1515
<PackageId>cslint</PackageId>
16-
<Version>1.2.0</Version>
16+
<Version>1.2.1</Version>
1717
<Authors>Lucas Pimentel</Authors>
1818
<Description>A fast C# linter that reads rules from .editorconfig. Uses Roslyn syntax-only parsing for fast single-file linting.</Description>
1919
<Copyright>Copyright (c) Lucas Pimentel 2026</Copyright>

src/CsLint.Cli/Program.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.CommandLine;
2+
using System.Reflection;
23
using System.Text.Json;
34
using System.Text;
45
using Cslint.Core.Config;
@@ -44,6 +45,11 @@
4445
Description = "Enable semantic analysis for advanced rules",
4546
};
4647

48+
var versionOption = new Option<bool>("--version")
49+
{
50+
Description = "Show version information and exit",
51+
};
52+
4753
var rootCommand = new RootCommand("Cslint - Fast C# linter respecting .editorconfig")
4854
{
4955
pathArgument,
@@ -53,10 +59,21 @@
5359
listRulesOption,
5460
showConfigOption,
5561
semanticOption,
62+
versionOption,
5663
};
5764

5865
rootCommand.SetAction(async (parseResult, cancellationToken) =>
5966
{
67+
if (parseResult.GetValue(versionOption))
68+
{
69+
string version = Assembly.GetEntryAssembly()
70+
?.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
71+
?.InformationalVersion ?? "unknown";
72+
73+
Console.WriteLine(version);
74+
return 0;
75+
}
76+
6077
bool listRules = parseResult.GetValue(listRulesOption);
6178

6279
if (listRules)

src/CsLint.Core/Rules/Tier3/NewLineHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static bool HasBlankLineBetween(SyntaxToken first, SyntaxToken second)
2828
return true;
2929
}
3030
}
31-
else if (!trivia.IsKind(SyntaxKind.WhitespaceTrivia))
31+
else if (!trivia.IsKind(SyntaxKind.WhitespaceTrivia) && !trivia.IsDirective)
3232
{
3333
newlineCount = 0;
3434
}

test/CsLint.Core.Tests/CsLint.Core.Tests.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
<IsPackable>false</IsPackable>
55
</PropertyGroup>
66

7+
<!-- Exclude Tier4 test files when semantic rules are not included -->
8+
<ItemGroup Condition="'$(IncludeSemanticRules)' != 'true'">
9+
<Compile Remove="Rules/Tier4/**" />
10+
</ItemGroup>
11+
712
<ItemGroup>
813
<PackageReference Include="coverlet.collector" Version="6.0.2" />
914
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />

test/CsLint.Core.Tests/Rules/Tier3/BlankLineAfterBlockRuleTests.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,32 @@ void M()
185185
Assert.Empty(diagnostics);
186186
}
187187

188+
[Fact]
189+
public void Analyze_BlockFollowedByDirectiveAndBlankLine_ReturnsNoDiagnostics()
190+
{
191+
string source = """
192+
class C
193+
{
194+
void M()
195+
{
196+
#if DEBUG
197+
if (true)
198+
{
199+
return;
200+
}
201+
#endif
202+
203+
int x = 1;
204+
}
205+
}
206+
""";
207+
RuleContext context = TestHelper.CreateContext(source, Enforced);
208+
209+
IReadOnlyList<LintDiagnostic> diagnostics = _rule.Analyze(context);
210+
211+
Assert.Empty(diagnostics);
212+
}
213+
188214
[Theory]
189215
[InlineData("if (x) { p += 2; continue; }")]
190216
[InlineData("if (x) { p += 2; break; }")]

0 commit comments

Comments
 (0)