forked from morelinq/MoreLINQ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eclint.ps1
55 lines (42 loc) · 1.47 KB
/
eclint.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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)."
}
}