-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dynamically discover/build glob for ECLint (#957)
- Loading branch information
Showing
2 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)." | ||
} | ||
} |