-
Notifications
You must be signed in to change notification settings - Fork 7
/
Find-ProjectAntiPatterns.ps1
88 lines (68 loc) · 2.08 KB
/
Find-ProjectAntiPatterns.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# This is incomplete, but its supposed to find things that are going to be a problem later
. "$PSScriptRoot\Get-ProjectItems.ps1"
function Find-ProjectAntiPatterns
{
[CmdletBinding()]
Param(
[string] $ProjFilePath
)
$antiPatterns = @()
Add-Type -TypeDefinition (Get-HelperTypes)
#projects with non-content things set to content (packages.config, *.snk, ) and published mistakenly
Find-NonContentContentIncludes $ProjFilePath
$projFolder = Split-Path $ProjFilePath -Parent
Show-NugetDisagreement -ProjectFolder $projFolder
}
function Find-NonContentContentIncludes
{
[CmdletBinding()]
Param(
[string] $ProjFilePath
)
Add-Type -TypeDefinition (Get-HelperTypes)
$badPatterns = [VsUtility.Consts]::GetNonContentFilePatterns()
$items = @(Get-ProjectItems -ProjFilePath $ProjFilePath -ItemType Content)
$returnValue = @()
foreach ($item in $items)
{
$fileName = [IO.Path]::GetFileName($item.FullName)
foreach ($badPattern in $badPatterns)
{
if ($fileName -ilike $badPattern)
{
$locProps = @{'FilePath'= $item.FullName;'Code'="NCC";'Message'="Content file matches non-content pattern '$badPattern'"}
$returnValue += (New-Object -TypeName PSObject -Property $locProps)
continue
}
}
}
return $returnValue
}
#can diagnostic
function Get-HelperTypes
{
return @"
namespace VsUtility
{
using System;
using System.Collections.Generic;
public class Location
{
public string FilePath {get;set;}
public int LineNumber {get;set;}
public string Code {get;set;}
public string Message {get;set;}
}
public static class Consts
{
public static List<string> GetNonContentFilePatterns()
{
var files = new List<string>();
files.Add("*.snk");
files.Add("packages.config");
return files;
}
}
}
"@
}