Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically discover/build glob for ECLint #957

Merged
merged 3 commits into from
Jan 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ skip_commits:
install:
- npm install -g eclint
- git rm .editorconfig
- eclint check -n "**/*.{cs,tt,cmd,sh,md,txt,yml}"
- eclint check -w "**/*.{cs,tt,cmd,sh,md,txt,yml,json,sln,csproj,shfbproj}"
- pwsh: ./eclint.ps1 -InsertFinalNewline -Verbose
- pwsh: ./eclint.ps1 -TrimTrailingWhitespace -Verbose
- git reset --hard
- ps: if ($isWindows) { tools\dotnet-install.ps1 -JSonFile global.json }
- ps: if ($isWindows) { tools\dotnet-install.ps1 -Runtime dotnet -Version 3.1.10 -SkipNonVersionedFiles }
Expand Down
55 changes: 55 additions & 0 deletions eclint.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[CmdletBinding(DefaultParameterSetName='Default')]
param (
[Parameter(ParameterSetName='Default')]
[switch]$TrimTrailingWhitespace,
[Parameter(ParameterSetName='Default')]
[switch]$InsertFinalNewline,

[Parameter(Mandatory=$true, ParameterSetName='ShowGlob')]
[switch]$ShowGlob
)

$ErrorActionPreference = 'Stop'

$exts =
git ls-files --eol | # get versioned file paths with line endings
? { $_ -notmatch '/-text\b' } | # exclude binary files
% { ($_ -split '\t', 2)[1] } | # get file path
Split-Path -Extension | # get file extension
? { $_.Length -gt 1 } | # exclude those without an extension
Sort-Object | # sort alphabetically
Select-Object -Unique | # remove duplicates
% { $_.Substring(1) } # remove leading dot

$glob = "**/*.{$($exts -join ',')}"

if ($PSCmdlet.ParameterSetName -eq 'ShowGlob') {
Write-Output $glob
return
}

if (-not (Get-Command eclint -ErrorAction SilentlyContinue)) {
throw 'ECLint is not installed. To install, run: npm install -g eclint'
}

$rules = @()

if ($trimTrailingWhitespace) {
$rules += '--trim_trailing_whitespace'
}

if ($insertFinalNewline) {
$rules += '--insert_final_newline'
}

$rules | % {

Write-Verbose "eclint check $rule $glob"

# https://github.com/jednano/eclint
eclint check $_ $glob

if ($LASTEXITCODE) {
throw "eclint terminated with a non-zero exit code ($LASTEXITCODE)."
}
}