Skip to content

Commit fadf62c

Browse files
authored
Merge branch 'main' into limit-git
2 parents e58bd05 + e664ef2 commit fadf62c

File tree

6 files changed

+106
-15
lines changed

6 files changed

+106
-15
lines changed

.github/workflows/validate_pull_request.yml renamed to .github/workflows/ValidatePullRequest.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ jobs:
3232
rm -r -f ./Tests/CSharpier.MsBuild.Test
3333
dotnet tool restore
3434
dotnet csharpier check .
35+
check_todos:
36+
runs-on: ubuntu-latest
37+
name: Check TODOs
38+
steps:
39+
- uses: actions/checkout@v2
40+
- name: Get branch name (pull request)
41+
if: github.event_name == 'pull_request'
42+
shell: bash
43+
run: echo "BRANCH_NAME=$(echo ${GITHUB_HEAD_REF} | tr / -)" >> $GITHUB_ENV
44+
- shell: pwsh
45+
run: |
46+
./.github/workflows/ValidatePullRequest_CheckTodos.ps1 -BranchName ${{ env.BRANCH_NAME }}
3547
test_msbuild:
3648
strategy:
3749
matrix:
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
param
2+
(
3+
[Parameter(Mandatory = $true)] [String]$BranchName
4+
)
5+
6+
Set-StrictMode -Version 3.0
7+
$ErrorActionPreference = "Stop"
8+
9+
$skippedDirectories = @("node_modules", `
10+
"dist", `
11+
"obj", `
12+
"bin", `
13+
"lib", `
14+
"Libraries", `
15+
"packages", `
16+
"Service References", `
17+
".idea", `
18+
".vscode", `
19+
"BuildArtifacts", `
20+
".sass-cache", `
21+
"Typings", `
22+
".git", `
23+
".sql" `
24+
) `
25+
| ForEach-Object { ([IO.Path]::DirectorySeparatorChar + $_).ToLower() }
26+
27+
Write-Host "::group::Checking for TODOs"
28+
29+
$directoriesToProcess = @()
30+
foreach ($item in Get-ChildItem -Recurse -Directory) {
31+
$add = $true
32+
foreach ($directory in $skippedDirectories) {
33+
if ($item.FullName.ToLower() -like "*$directory*") {
34+
$add = $false
35+
continue
36+
}
37+
}
38+
39+
if ($add) {
40+
$directoriesToProcess += $item.FullName
41+
}
42+
}
43+
44+
Write-Host "Looking for TODO $BranchName"
45+
$regexPattern = "(TODO[\s-\:]*$BranchName)"
46+
47+
function checkForTodoComments {
48+
$directoriesToProcess | ForEach-Object -Parallel {
49+
foreach ($item in Get-ChildItem -Path "$_\*" -File -Exclude "*.exe", "*.dll", "*.pdf") {
50+
if ($item.FullName.EndsWith(".js") -or $item.FullName.EndsWith(".js.map")) {
51+
if (Test-Path $item.FullName.Replace(".js.map", ".ts").Replace(".js", ".ts")) {
52+
continue
53+
}
54+
}
55+
56+
Select-String -Pattern "$using:regexPattern" -Path $item.FullName
57+
}
58+
}
59+
}
60+
61+
$todoMatches = checkForTodoComments
62+
63+
Write-Host "::endgroup::"
64+
if ($null -eq $todoMatches) {
65+
exit 0
66+
}
67+
68+
Write-Host "`nFound TODOs that need to be addressed."
69+
foreach ($todoMatch in $todoMatches) {
70+
$relativePath = $todoMatch.Path.Substring($PWD.ToString().Length + 1)
71+
Write-Host "::error file=$relativePath,line=$( $todoMatch.LineNumber )::This TODO needs to be cleaned up"
72+
Write-Host " $( $relativePath ):$( $todoMatch.LineNumber )"
73+
Write-Host " $( $todoMatch.Line )"
74+
}
75+
76+
exit 1

Src/CSharpier.Core/PrinterOptions.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Globalization;
2+
13
namespace CSharpier.Core;
24

35
internal class PrinterOptions(Formatter formatter)
@@ -36,16 +38,16 @@ internal static string GetLineEnding(string code, PrinterOptions printerOptions)
3638

3739
public static Formatter GetFormatter(string filePath)
3840
{
39-
var formatter =
40-
filePath.EndsWith(".cs", StringComparison.Ordinal) ? Formatter.CSharp
41-
: filePath.EndsWith(".csx", StringComparison.Ordinal) ? Formatter.CSharpScript
42-
: filePath.EndsWith(".csproj", StringComparison.Ordinal)
43-
|| filePath.EndsWith(".props", StringComparison.Ordinal)
44-
|| filePath.EndsWith(".targets", StringComparison.Ordinal)
45-
|| filePath.EndsWith(".xml", StringComparison.Ordinal)
46-
|| filePath.EndsWith(".config", StringComparison.Ordinal)
47-
? Formatter.XML
48-
: Formatter.Unknown;
41+
var extension = Path.GetExtension(filePath)[1..].ToLower(CultureInfo.InvariantCulture);
42+
43+
var formatter = extension switch
44+
{
45+
"cs" => Formatter.CSharp,
46+
"csx" => Formatter.CSharpScript,
47+
"config" or "csproj" or "props" or "slnx" or "targets" or "xaml" or "xml" =>
48+
Formatter.XML,
49+
_ => Formatter.Unknown,
50+
};
4951
return formatter;
5052
}
5153
}

Src/CSharpier.Tests/OptionsProviderTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,13 @@ string extension
4747
ShouldHaveDefaultCSharpOptions(result);
4848
}
4949

50-
[TestCase("xml")]
50+
[TestCase("config")]
5151
[TestCase("csproj")]
5252
[TestCase("props")]
53+
[TestCase("slnx")]
5354
[TestCase("targets")]
54-
[TestCase("config")]
55+
[TestCase("xaml")]
56+
[TestCase("xml")]
5557
public async Task Should_Return_Default_Options_With_No_File_And_Known_Xml_Extension(
5658
string extension
5759
)

docs/Configuration.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ indent_style = space
9898
indent_size = 4
9999
max_line_length = 100
100100
101-
[*.{csproj,props,targets,xml,config}]
102-
# Configurable behaviors
101+
[*.{config,csproj,props,slnx,targets,xaml,xml}]
103102
indent_style = space
104103
indent_size = 2
105104
max_line_length = 100

docs/Pre-commit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Modify the file at `.husky/task-runner.json`. Include any file extensions that y
6666
"name": "Run csharpier",
6767
"command": "dotnet",
6868
"args": [ "csharpier", "format", "${staged}" ],
69-
"include": [ "**/*.{cs,csx,csproj,props,targets,xml,config}" ]
69+
"include": [ "**/*.{cs,csx,config,csproj,props,slnx,targets,xaml,xml}" ]
7070
}]
7171
}
7272
```

0 commit comments

Comments
 (0)