Skip to content

Commit

Permalink
Dynamically discover/build glob for ECLint (#957)
Browse files Browse the repository at this point in the history
  • Loading branch information
atifaziz authored Jan 29, 2023
1 parent 53b1217 commit 47747ef
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
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 6.0.11 -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)."
}
}

0 comments on commit 47747ef

Please sign in to comment.