diff --git a/.build.ps1 b/.build.ps1 index a712753bf..b1d94d75f 100644 --- a/.build.ps1 +++ b/.build.ps1 @@ -9,7 +9,6 @@ param( # todo remove aliases # todo make each project have its own build script -$resourceScript = Join-Path $BuildRoot "New-StronglyTypedCsFileForResx.ps1" $outPath = "$BuildRoot/out" $modulePath = "$outPath/PSScriptAnalyzer" @@ -81,8 +80,8 @@ function Get-BuildTaskParams($project) { function Get-RestoreTaskParams($project) { @{ - Inputs = "$BuildRoot/$project/project.json" - Outputs = "$BuildRoot/$project/project.lock.json" + Inputs = "$BuildRoot/$project/$project.csproj" + Outputs = "$BuildRoot/$project/$project.csproj" Jobs = {dotnet restore} } } @@ -109,20 +108,6 @@ function Get-TestTaskParam($project) { } } -function Get-ResourceTaskParam($project) { - @{ - Inputs = "$project/Strings.resx" - Outputs = "$project/Strings.cs" - Data = $project - Jobs = { - Push-Location $BuildRoot - & $resourceScript $Task.Data - Pop-Location - } - Before = "$project/build" - } -} - function Add-ProjectTask([string]$project, [string]$taskName, [hashtable]$taskParams, [string]$pathPrefix = $buildRoot) { $jobs = [scriptblock]::Create(@" pushd $pathPrefix/$project @@ -136,14 +121,12 @@ popd $projects = @("engine", "rules") $projects | ForEach-Object { - Add-ProjectTask $_ buildResource (Get-ResourceTaskParam $_) Add-ProjectTask $_ build (Get-BuildTaskParams $_) Add-ProjectTask $_ restore (Get-RestoreTaskParams $_) Add-ProjectTask $_ clean (Get-CleanTaskParams $_) Add-ProjectTask $_ test (Get-TestTaskParam $_) "$BuildRoot/tests" } -task buildResource -Before build "engine/buildResource", "rules/buildResource" task build "engine/build", "rules/build" task restore "engine/restore", "rules/restore" task clean "engine/clean", "rules/clean" diff --git a/.gitignore b/.gitignore index ae004a34e..329ec9bd5 100644 --- a/.gitignore +++ b/.gitignore @@ -38,7 +38,7 @@ TestResult.xml [Rr]eleasePS/ dlldata.c -# DNX +# .Net Core CLI project.lock.json artifacts/ diff --git a/Engine/Engine.csproj b/Engine/Engine.csproj new file mode 100644 index 000000000..2981cf2f6 --- /dev/null +++ b/Engine/Engine.csproj @@ -0,0 +1,56 @@ + + + + 1.16.1 + netstandard1.6;net451 + Microsoft.Windows.PowerShell.ScriptAnalyzer + Engine + Microsoft.Windows.PowerShell.ScriptAnalyzer + + + + + + + + + + + + + + portable + + + + $(DefineConstants);CORECLR + + + + + + + + + + + + + True + True + Strings.resx + + + + + + ResXFileCodeGenerator + Strings.Designer.cs + + + + + $(DefineConstants);PSV3;PSV5 + + + diff --git a/Engine/Strings.Designer.cs b/Engine/Strings.Designer.cs index 7af798344..1f8db8c92 100644 --- a/Engine/Strings.Designer.cs +++ b/Engine/Strings.Designer.cs @@ -10,6 +10,7 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer { using System; + using System.Reflection; /// @@ -19,7 +20,7 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Strings { @@ -39,7 +40,7 @@ internal Strings() { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.Windows.PowerShell.ScriptAnalyzer.Strings", typeof(Strings).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.Windows.PowerShell.ScriptAnalyzer.Strings", typeof(Strings).GetTypeInfo().Assembly); resourceMan = temp; } return resourceMan; @@ -87,6 +88,33 @@ internal static string CommandInfoNotFound { } } + /// + /// Looks up a localized string similar to "Argument should not be null.".. + /// + internal static string ConfigurableScriptRuleNRE { + get { + return ResourceManager.GetString("ConfigurableScriptRuleNRE", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to "Cannot find a ConfigurableRuleProperty attribute on property {0}".. + /// + internal static string ConfigurableScriptRulePropertyHasNotAttribute { + get { + return ResourceManager.GetString("ConfigurableScriptRulePropertyHasNotAttribute", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to SettingsFileHasInvalidHashtable. + /// + internal static string ConfigurationFileHasInvalidHashtable { + get { + return ResourceManager.GetString("ConfigurationFileHasInvalidHashtable", resourceCulture); + } + } + /// /// Looks up a localized string similar to SettingsFileHasNoHashTable. /// @@ -150,6 +178,51 @@ internal static string DefaultLoggerName { } } + /// + /// Looks up a localized string similar to Edge from {0} to {1} already exists.. + /// + internal static string DigraphEdgeAlreadyExists { + get { + return ResourceManager.GetString("DigraphEdgeAlreadyExists", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Vertex {0} already exists! Cannot add it to the digraph.. + /// + internal static string DigraphVertexAlreadyExists { + get { + return ResourceManager.GetString("DigraphVertexAlreadyExists", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Vertex {0} does not exist in the digraph.. + /// + internal static string DigraphVertexDoesNotExists { + get { + return ResourceManager.GetString("DigraphVertexDoesNotExists", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Cannot determine line endings as the text probably contain mixed line endings.. + /// + internal static string EditableTextInvalidLineEnding { + get { + return ResourceManager.GetString("EditableTextInvalidLineEnding", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to TextEdit extent not completely contained in EditableText.. + /// + internal static string EditableTextRangeIsNotContained { + get { + return ResourceManager.GetString("EditableTextRangeIsNotContained", resourceCulture); + } + } + /// /// Looks up a localized string similar to Cannot find file '{0}'.. /// @@ -204,6 +277,15 @@ internal static string MissingRuleExtension { } } + /// + /// Looks up a localized string similar to Temporary module location: {0}.. + /// + internal static string ModuleDepHandlerTempLocation { + get { + return ResourceManager.GetString("ModuleDepHandlerTempLocation", resourceCulture); + } + } + /// /// Looks up a localized string similar to {0} cannot be set by both positional and named arguments.. /// @@ -267,6 +349,51 @@ internal static string ParserErrorMessageForScriptDefinition { } } + /// + /// Looks up a localized string similar to Column number cannot be less than 1.. + /// + internal static string PositionColumnLessThanOne { + get { + return ResourceManager.GetString("PositionColumnLessThanOne", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Line number cannot be less than 1.. + /// + internal static string PositionLineLessThanOne { + get { + return ResourceManager.GetString("PositionLineLessThanOne", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Input position should be less than that of the invoking object.. + /// + internal static string PositionRefPosLessThanInputPos { + get { + return ResourceManager.GetString("PositionRefPosLessThanInputPos", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Reference Position should begin before start Position of Range.. + /// + internal static string RangeRefPosShouldStartBeforeRangeStartPos { + get { + return ResourceManager.GetString("RangeRefPosShouldStartBeforeRangeStartPos", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Start position cannot be before End position.. + /// + internal static string RangeStartPosGreaterThanEndPos { + get { + return ResourceManager.GetString("RangeStartPosGreaterThanEndPos", resourceCulture); + } + } + /// /// Looks up a localized string similar to RULE_ERROR. /// @@ -321,6 +448,96 @@ internal static string RuleSuppressionRuleNameNotFound { } } + /// + /// Looks up a localized string similar to Found {0}. Will use it to provide settings for this invocation.. + /// + internal static string SettingsAutoDiscovered { + get { + return ResourceManager.GetString("SettingsAutoDiscovered", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Cannot find a settings file.. + /// + internal static string SettingsCannotFindFile { + get { + return ResourceManager.GetString("SettingsCannotFindFile", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Dictionary should be indexable in a case-insensitive manner.. + /// + internal static string SettingsDictionaryShouldBeCaseInsesitive { + get { + return ResourceManager.GetString("SettingsDictionaryShouldBeCaseInsesitive", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Input should be a dictionary type.. + /// + internal static string SettingsInputShouldBeDictionary { + get { + return ResourceManager.GetString("SettingsInputShouldBeDictionary", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Settings should be either a file path, built-in preset or a hashtable.. + /// + internal static string SettingsInvalidType { + get { + return ResourceManager.GetString("SettingsInvalidType", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Cannot parse settings. Will abort the invocation.. + /// + internal static string SettingsNotParsable { + get { + return ResourceManager.GetString("SettingsNotParsable", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Settings not provided. Will look for settings file in the given path {0}.. + /// + internal static string SettingsNotProvided { + get { + return ResourceManager.GetString("SettingsNotProvided", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Using settings file at {0}.. + /// + internal static string SettingsUsingFile { + get { + return ResourceManager.GetString("SettingsUsingFile", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Using settings hashtable.. + /// + internal static string SettingsUsingHashtable { + get { + return ResourceManager.GetString("SettingsUsingHashtable", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0} property must be of type bool.. + /// + internal static string SettingsValueTypeMustBeBool { + get { + return ResourceManager.GetString("SettingsValueTypeMustBeBool", resourceCulture); + } + } + /// /// Looks up a localized string similar to All the arguments of the Suppress Message Attribute should be string constants.. /// @@ -348,6 +565,24 @@ internal static string TargetWithoutScopeSuppressionAttributeError { } } + /// + /// Looks up a localized string similar to Line element cannot be null.. + /// + internal static string TextEditNoNullItem { + get { + return ResourceManager.GetString("TextEditNoNullItem", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Line element cannot be null.. + /// + internal static string TextLinesNoNullItem { + get { + return ResourceManager.GetString("TextLinesNoNullItem", resourceCulture); + } + } + /// /// Looks up a localized string similar to Analyzing file: {0}. /// @@ -430,7 +665,7 @@ internal static string WrongValueFormat { } /// - /// Looks up a localized string similar to Value {0} for key {1} has the wrong data type. Value in the settings hashtable should be a string or an array of strings.. + /// Looks up a localized string similar to Value {0} for key {1} has the wrong data type.. /// internal static string WrongValueHashTable { get { diff --git a/Engine/Strings.resx b/Engine/Strings.resx index f9bb6f8a3..5194830c3 100644 --- a/Engine/Strings.resx +++ b/Engine/Strings.resx @@ -1,17 +1,17 @@  - @@ -321,4 +321,4 @@ Input position should be less than that of the invoking object. - + \ No newline at end of file diff --git a/Engine/project.json b/Engine/project.json deleted file mode 100644 index 620ade237..000000000 --- a/Engine/project.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "name": "Microsoft.Windows.PowerShell.ScriptAnalyzer", - "version": "1.16.1", - "dependencies": { -"System.Management.Automation": "6.0.0-alpha13" - }, - - "configurations": { - "PSV3Release": { - "buildOptions": { - "define": [ "PSV3", "PSV5" ], - "optimize": true - } - }, - "PSV3Debug": { - "buildOptions": { - "define": [ "PSV3", "DEBUG" ] - } - } - }, - - "frameworks": { - "net451": { - "frameworkAssemblies": { - "System.ComponentModel.Composition": "" - }, - "buildOptions": { - "compile": { - "exclude": [ - "Commands/GetScriptAnalyzerLoggerCommand.cs", - "Strings.Designer.Core.cs", - "Strings.Designer.cs" - ] - }, - "debugType": "portable" - } - }, - "netstandard1.6": { - "imports": "dnxcore50", - "buildOptions": { - "define": [ "CORECLR" ], - "compile": { - "exclude": [ - "SafeDirectoryCatalog.cs", - "Strings.Designer.cs", - "Strings.Designer.Core.cs", - "Commands/GetScriptAnalyzerLoggerCommand.cs" - ] - }, - "debugType": "portable" - } - } - } -} diff --git a/New-StronglyTypedCsFileForResx.ps1 b/New-StronglyTypedCsFileForResx.ps1 index c18896f66..5fb0ee9ea 100644 --- a/New-StronglyTypedCsFileForResx.ps1 +++ b/New-StronglyTypedCsFileForResx.ps1 @@ -1,4 +1,8 @@ -param( +<# +# This script can be used to update the *.Designer file if a *.resx ressource file has been updated. +# However, it is recommended to use Visual Studio instead for editing ressources instead since it takes of that automatically and prodcues cleaner diffs. +#> +param( [ValidateSet("Engine","Rules")] [string] $project ) @@ -26,7 +30,7 @@ function Get-StronglyTypeCsFileForResx $banner = @' //------------------------------------------------------------------------------ // -// This code was generated by a New-StronglyTypedCsFileForResx funciton. +// This code was generated by a New-StronglyTypedCsFileForResx function. // To add or remove a member, edit your .ResX file then rerun Start-ResGen. // // Changes to this file may cause incorrect behavior and will be lost if @@ -50,7 +54,7 @@ using System.Reflection; /// /// A strongly-typed resource class, for looking up localized strings, etc. /// -[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] +[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] @@ -132,7 +136,7 @@ if (-not (Test-Path "$projectRoot/global.json")) throw "Not in solution root: $projectRoot" } $inputFilePath = Join-Path $projectRoot "$project/Strings.resx" -$outputFilePath = Join-Path $projectRoot "$project/Strings.cs" +$outputFilePath = Join-Path $projectRoot "$project/Strings.Designer.cs" $className = "Microsoft.Windows.PowerShell.ScriptAnalyzer" if ($project -eq "Rules") { diff --git a/PSScriptAnalyzer.sln b/PSScriptAnalyzer.sln index c8843df1a..6b7e04454 100644 --- a/PSScriptAnalyzer.sln +++ b/PSScriptAnalyzer.sln @@ -1,38 +1,51 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.23107.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScriptAnalyzerEngine", "Engine\ScriptAnalyzerEngine.csproj", "{F4BDE3D0-3EEF-4157-8A3E-722DF7ADEF60}" +# Visual Studio 15 +VisualStudioVersion = 15.0.27004.2010 +MinimumVisualStudioVersion = 15.0.26124.0 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Engine", "Engine\Engine.csproj", "{E3969A29-E511-46A3-ABF7-FA6AD4AAB33B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScriptAnalyzerBuiltinRules", "Rules\ScriptAnalyzerBuiltinRules.csproj", "{C33B6B9D-E61C-45A3-9103-895FD82A5C1E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Rules", "Rules\Rules.csproj", "{D601FAC9-48CD-45B5-B4E8-9A3BD06E1436}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU - PSV3 Debug|Any CPU = PSV3 Debug|Any CPU - PSV3 Release|Any CPU = PSV3 Release|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {F4BDE3D0-3EEF-4157-8A3E-722DF7ADEF60}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F4BDE3D0-3EEF-4157-8A3E-722DF7ADEF60}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F4BDE3D0-3EEF-4157-8A3E-722DF7ADEF60}.PSV3 Debug|Any CPU.ActiveCfg = PSV3 Debug|Any CPU - {F4BDE3D0-3EEF-4157-8A3E-722DF7ADEF60}.PSV3 Debug|Any CPU.Build.0 = PSV3 Debug|Any CPU - {F4BDE3D0-3EEF-4157-8A3E-722DF7ADEF60}.PSV3 Release|Any CPU.ActiveCfg = PSV3 Release|Any CPU - {F4BDE3D0-3EEF-4157-8A3E-722DF7ADEF60}.PSV3 Release|Any CPU.Build.0 = PSV3 Release|Any CPU - {F4BDE3D0-3EEF-4157-8A3E-722DF7ADEF60}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F4BDE3D0-3EEF-4157-8A3E-722DF7ADEF60}.Release|Any CPU.Build.0 = Release|Any CPU - {C33B6B9D-E61C-45A3-9103-895FD82A5C1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C33B6B9D-E61C-45A3-9103-895FD82A5C1E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C33B6B9D-E61C-45A3-9103-895FD82A5C1E}.PSV3 Debug|Any CPU.ActiveCfg = PSV3 Debug|Any CPU - {C33B6B9D-E61C-45A3-9103-895FD82A5C1E}.PSV3 Debug|Any CPU.Build.0 = PSV3 Debug|Any CPU - {C33B6B9D-E61C-45A3-9103-895FD82A5C1E}.PSV3 Release|Any CPU.ActiveCfg = PSV3 Release|Any CPU - {C33B6B9D-E61C-45A3-9103-895FD82A5C1E}.PSV3 Release|Any CPU.Build.0 = PSV3 Release|Any CPU - {C33B6B9D-E61C-45A3-9103-895FD82A5C1E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C33B6B9D-E61C-45A3-9103-895FD82A5C1E}.Release|Any CPU.Build.0 = Release|Any CPU + {E3969A29-E511-46A3-ABF7-FA6AD4AAB33B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E3969A29-E511-46A3-ABF7-FA6AD4AAB33B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E3969A29-E511-46A3-ABF7-FA6AD4AAB33B}.Debug|x64.ActiveCfg = Debug|Any CPU + {E3969A29-E511-46A3-ABF7-FA6AD4AAB33B}.Debug|x64.Build.0 = Debug|Any CPU + {E3969A29-E511-46A3-ABF7-FA6AD4AAB33B}.Debug|x86.ActiveCfg = Debug|Any CPU + {E3969A29-E511-46A3-ABF7-FA6AD4AAB33B}.Debug|x86.Build.0 = Debug|Any CPU + {E3969A29-E511-46A3-ABF7-FA6AD4AAB33B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E3969A29-E511-46A3-ABF7-FA6AD4AAB33B}.Release|Any CPU.Build.0 = Release|Any CPU + {E3969A29-E511-46A3-ABF7-FA6AD4AAB33B}.Release|x64.ActiveCfg = Release|Any CPU + {E3969A29-E511-46A3-ABF7-FA6AD4AAB33B}.Release|x64.Build.0 = Release|Any CPU + {E3969A29-E511-46A3-ABF7-FA6AD4AAB33B}.Release|x86.ActiveCfg = Release|Any CPU + {E3969A29-E511-46A3-ABF7-FA6AD4AAB33B}.Release|x86.Build.0 = Release|Any CPU + {D601FAC9-48CD-45B5-B4E8-9A3BD06E1436}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D601FAC9-48CD-45B5-B4E8-9A3BD06E1436}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D601FAC9-48CD-45B5-B4E8-9A3BD06E1436}.Debug|x64.ActiveCfg = Debug|Any CPU + {D601FAC9-48CD-45B5-B4E8-9A3BD06E1436}.Debug|x64.Build.0 = Debug|Any CPU + {D601FAC9-48CD-45B5-B4E8-9A3BD06E1436}.Debug|x86.ActiveCfg = Debug|Any CPU + {D601FAC9-48CD-45B5-B4E8-9A3BD06E1436}.Debug|x86.Build.0 = Debug|Any CPU + {D601FAC9-48CD-45B5-B4E8-9A3BD06E1436}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D601FAC9-48CD-45B5-B4E8-9A3BD06E1436}.Release|Any CPU.Build.0 = Release|Any CPU + {D601FAC9-48CD-45B5-B4E8-9A3BD06E1436}.Release|x64.ActiveCfg = Release|Any CPU + {D601FAC9-48CD-45B5-B4E8-9A3BD06E1436}.Release|x64.Build.0 = Release|Any CPU + {D601FAC9-48CD-45B5-B4E8-9A3BD06E1436}.Release|x86.ActiveCfg = Release|Any CPU + {D601FAC9-48CD-45B5-B4E8-9A3BD06E1436}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {8354D5F1-95D7-48B3-B4BF-DD7AACDAA5BA} + EndGlobalSection EndGlobal diff --git a/README.md b/README.md index b532a5c7b..d643a3241 100644 --- a/README.md +++ b/README.md @@ -81,12 +81,13 @@ Exit ### From Source #### Requirements -* [.NET Core 1.0 SDK Preview 2](https://github.com/dotnet/core/blob/master/release-notes/download-archives/1.0-preview2-download.md) +* [.NET Core 2.1.4 SDK](https://github.com/dotnet/core/blob/master/release-notes/download-archives/2.0.5-download.md) * [PlatyPS 0.5.0 or greater](https://github.com/PowerShell/platyPS) +* Optionally but recommended for development: [Visual Studio 2017](https://www.visualstudio.com/downloads/) #### Steps * Obtain the source - - Download the latest source code from the release page (https://github.com/PowerShell/PSScriptAnalyzer/releases) OR + - Download the latest source code from the [release page](https://github.com/PowerShell/PSScriptAnalyzer/releases) OR - Clone the repository (needs git) ```powershell git clone https://github.com/PowerShell/PSScriptAnalyzer @@ -95,11 +96,9 @@ Exit ```powershell cd path/to/PSScriptAnalyzer ``` -* Restore packages - ```powershell - dotnet restore - ``` -* Build for your platform +* Building + + You can either build using the `Visual Studio` solution `PSScriptAnalyzer.sln` or build using `PowerShell` specifically for your platform as follows: * Windows PowerShell version 5.0 and greater ```powershell .\buildCoreClr.ps1 -Framework net451 -Configuration Release -Build @@ -118,15 +117,19 @@ Exit ``` * Import the module ```powershell -Import-Module /path/to/PSScriptAnalyzer/out/PSScriptAnalyzer +Import-Module .\out\PSScriptAnalyzer\PSScriptAnalyzer.psd1 ``` To confirm installation: run `Get-ScriptAnalyzerRule` in the PowerShell console to obtain the built-in rules +* Adding/Removing resource strings + +For adding/removing resource strings in the `*.resx` files, it is recommended to use `Visual Studio` since it automatically updates the strongly typed `*.Designer.cs` files. The `Visual Studio 2017 Community Edition` is free to use but should you not have/want to use `Visual Studio` then you can either manually adapt the `*.Designer.cs` files or use the `New-StronglyTypedCsFileForResx.ps1` script although the latter is discouraged since it leads to a bad diff of the `*.Designer.cs` files. + #### Tests Pester-based ScriptAnalyzer Tests are located in `path/to/PSScriptAnalyzer/Tests` folder. -* Ensure Pester is installed on the machine +* Ensure Pester 3.4 is installed on the machine * Copy `path/to/PSScriptAnalyzer/out/PSScriptAnalyzer` to a folder in `PSModulePath` * Go the Tests folder in your local repository * Run Engine Tests: diff --git a/Rules/Rules.csproj b/Rules/Rules.csproj new file mode 100644 index 000000000..40a21d218 --- /dev/null +++ b/Rules/Rules.csproj @@ -0,0 +1,60 @@ + + + + 1.16.1 + netstandard1.6;net451 + Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules + Rules + $(PackageTargetFallback);dnxcore50 + 1.0.4 + Microsoft.Windows.PowerShell.ScriptAnalyzer + + + + + + + + + + + + + + + + + + + + portable + + + + $(DefineConstants);CORECLR + + + + + + + + + True + True + Strings.resx + + + + + + ResXFileCodeGenerator + Strings.Designer.cs + + + + + $(DefineConstants);PSV3;PSV5 + + + diff --git a/Rules/Strings.Designer.cs b/Rules/Strings.Designer.cs index 6dae783ce..fb6532d29 100644 --- a/Rules/Strings.Designer.cs +++ b/Rules/Strings.Designer.cs @@ -8,10 +8,11 @@ // //------------------------------------------------------------------------------ -namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules { +namespace Microsoft.Windows.PowerShell.ScriptAnalyzer { using System; - - + using System.Reflection; + + /// /// A strongly-typed resource class, for looking up localized strings, etc. /// @@ -19,7 +20,7 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Strings { @@ -39,7 +40,7 @@ internal Strings() { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.Strings", typeof(Strings).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.Windows.PowerShell.ScriptAnalyzer.Strings", typeof(Strings).GetTypeInfo().Assembly); resourceMan = temp; } return resourceMan; @@ -60,6 +61,42 @@ internal Strings() { } } + /// + /// Looks up a localized string similar to Align assignment statement. + /// + internal static string AlignAssignmentStatementCommonName { + get { + return ResourceManager.GetString("AlignAssignmentStatementCommonName", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Line up assignment statements such that the assignment operator are aligned.. + /// + internal static string AlignAssignmentStatementDescription { + get { + return ResourceManager.GetString("AlignAssignmentStatementDescription", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Assignment statements are not aligned. + /// + internal static string AlignAssignmentStatementError { + get { + return ResourceManager.GetString("AlignAssignmentStatementError", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to AlignAssignmentStatement. + /// + internal static string AlignAssignmentStatementName { + get { + return ResourceManager.GetString("AlignAssignmentStatementName", resourceCulture); + } + } + /// /// Looks up a localized string similar to Avoid Using ComputerName Hardcoded. /// @@ -411,6 +448,42 @@ internal static string AvoidShouldContinueWithoutForceName { } } + /// + /// Looks up a localized string similar to Avoid trailing whitespace. + /// + internal static string AvoidTrailingWhitespaceCommonName { + get { + return ResourceManager.GetString("AvoidTrailingWhitespaceCommonName", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Each line should have no trailing whitespace.. + /// + internal static string AvoidTrailingWhitespaceDescription { + get { + return ResourceManager.GetString("AvoidTrailingWhitespaceDescription", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Line has trailing whitespace. + /// + internal static string AvoidTrailingWhitespaceError { + get { + return ResourceManager.GetString("AvoidTrailingWhitespaceError", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to AvoidTrailingWhitespace. + /// + internal static string AvoidTrailingWhitespaceName { + get { + return ResourceManager.GetString("AvoidTrailingWhitespaceName", resourceCulture); + } + } + /// /// Looks up a localized string similar to No traps in the script.. /// @@ -1311,6 +1384,123 @@ internal static string OneCharName { } } + /// + /// Looks up a localized string similar to Place close braces. + /// + internal static string PlaceCloseBraceCommonName { + get { + return ResourceManager.GetString("PlaceCloseBraceCommonName", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Close brace should be on a new line by itself.. + /// + internal static string PlaceCloseBraceDescription { + get { + return ResourceManager.GetString("PlaceCloseBraceDescription", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Close brace is not on a new line.. + /// + internal static string PlaceCloseBraceErrorShouldBeOnNewLine { + get { + return ResourceManager.GetString("PlaceCloseBraceErrorShouldBeOnNewLine", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Close brace before a branch statement is followed by a new line.. + /// + internal static string PlaceCloseBraceErrorShouldCuddleBranchStatement { + get { + return ResourceManager.GetString("PlaceCloseBraceErrorShouldCuddleBranchStatement", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Close brace does not follow a new line.. + /// + internal static string PlaceCloseBraceErrorShouldFollowNewLine { + get { + return ResourceManager.GetString("PlaceCloseBraceErrorShouldFollowNewLine", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Close brace does not follow a non-empty line.. + /// + internal static string PlaceCloseBraceErrorShouldNotFollowEmptyLine { + get { + return ResourceManager.GetString("PlaceCloseBraceErrorShouldNotFollowEmptyLine", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to PlaceCloseBrace. + /// + internal static string PlaceCloseBraceName { + get { + return ResourceManager.GetString("PlaceCloseBraceName", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Place open braces consistently. + /// + internal static string PlaceOpenBraceCommonName { + get { + return ResourceManager.GetString("PlaceOpenBraceCommonName", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Place open braces either on the same line as the preceding expression or on a new line.. + /// + internal static string PlaceOpenBraceDescription { + get { + return ResourceManager.GetString("PlaceOpenBraceDescription", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to There is no new line after open brace.. + /// + internal static string PlaceOpenBraceErrorNoNewLineAfterBrace { + get { + return ResourceManager.GetString("PlaceOpenBraceErrorNoNewLineAfterBrace", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Open brace not on same line as preceding keyword. It should be on the same line.. + /// + internal static string PlaceOpenBraceErrorShouldBeOnSameLine { + get { + return ResourceManager.GetString("PlaceOpenBraceErrorShouldBeOnSameLine", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Open brace is not on a new line.. + /// + internal static string PlaceOpenBraceErrorShouldNotBeOnSameLine { + get { + return ResourceManager.GetString("PlaceOpenBraceErrorShouldNotBeOnSameLine", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to PlaceOpenBrace. + /// + internal static string PlaceOpenBraceName { + get { + return ResourceManager.GetString("PlaceOpenBraceName", resourceCulture); + } + } + /// /// Looks up a localized string similar to Null Comparison. /// @@ -1824,6 +2014,114 @@ internal static string UseCompatibleCmdletsName { } } + /// + /// Looks up a localized string similar to Use consistent indentation. + /// + internal static string UseConsistentIndentationCommonName { + get { + return ResourceManager.GetString("UseConsistentIndentationCommonName", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Each statement block should have a consistent indenation.. + /// + internal static string UseConsistentIndentationDescription { + get { + return ResourceManager.GetString("UseConsistentIndentationDescription", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Indentation not consistent. + /// + internal static string UseConsistentIndentationError { + get { + return ResourceManager.GetString("UseConsistentIndentationError", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to UseConsistentIndentation. + /// + internal static string UseConsistentIndentationName { + get { + return ResourceManager.GetString("UseConsistentIndentationName", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Use whitespaces. + /// + internal static string UseConsistentWhitespaceCommonName { + get { + return ResourceManager.GetString("UseConsistentWhitespaceCommonName", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Check for whitespace between keyword and open paren/curly, around assigment operator ('='), around arithmetic operators and after separators (',' and ';'). + /// + internal static string UseConsistentWhitespaceDescription { + get { + return ResourceManager.GetString("UseConsistentWhitespaceDescription", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Use space before open brace.. + /// + internal static string UseConsistentWhitespaceErrorBeforeBrace { + get { + return ResourceManager.GetString("UseConsistentWhitespaceErrorBeforeBrace", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Use space before open parenthesis.. + /// + internal static string UseConsistentWhitespaceErrorBeforeParen { + get { + return ResourceManager.GetString("UseConsistentWhitespaceErrorBeforeParen", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Use space before and after binary and assignment operators.. + /// + internal static string UseConsistentWhitespaceErrorOperator { + get { + return ResourceManager.GetString("UseConsistentWhitespaceErrorOperator", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Use space after a comma.. + /// + internal static string UseConsistentWhitespaceErrorSeparatorComma { + get { + return ResourceManager.GetString("UseConsistentWhitespaceErrorSeparatorComma", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Use space after a semicolon.. + /// + internal static string UseConsistentWhitespaceErrorSeparatorSemi { + get { + return ResourceManager.GetString("UseConsistentWhitespaceErrorSeparatorSemi", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to UseConsistentWhitespace. + /// + internal static string UseConsistentWhitespaceName { + get { + return ResourceManager.GetString("UseConsistentWhitespaceName", resourceCulture); + } + } + /// /// Looks up a localized string similar to Extra Variables. /// @@ -1879,7 +2177,7 @@ internal static string UseIdenticalMandatoryParametersDSCDescription { } /// - /// Looks up a localized string similar to The mandatory parameter '{0}' is not present in '{1}' DSC resource function(s).. + /// Looks up a localized string similar to The '{0}' parameter '{1}' is not present in '{2}' DSC resource function(s).. /// internal static string UseIdenticalMandatoryParametersDSCError { get { @@ -2166,6 +2464,42 @@ internal static string UseStandardDSCFunctionsInResourceName { } } + /// + /// Looks up a localized string similar to Use SupportsShouldProcess. + /// + internal static string UseSupportsShouldProcessCommonName { + get { + return ResourceManager.GetString("UseSupportsShouldProcessCommonName", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Commands typically provide Confirm and Whatif parameters to give more control on its execution in an interactive environment. In PowerShell, a command can use a SupportsShouldProcess attribute to provide this capability. Hence, manual addition of these parameters to a command is discouraged. If a commands need Confirm and Whatif parameters, then it should support ShouldProcess.. + /// + internal static string UseSupportsShouldProcessDescription { + get { + return ResourceManager.GetString("UseSupportsShouldProcessDescription", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Whatif and/or Confirm manually defined in function {0}. Instead, please use SupportsShouldProcess attribute.. + /// + internal static string UseSupportsShouldProcessError { + get { + return ResourceManager.GetString("UseSupportsShouldProcessError", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to UseSupportsShouldProcess. + /// + internal static string UseSupportsShouldProcessName { + get { + return ResourceManager.GetString("UseSupportsShouldProcessName", resourceCulture); + } + } + /// /// Looks up a localized string similar to Use the *ToExport module manifest fields.. /// diff --git a/Rules/project.json b/Rules/project.json deleted file mode 100644 index 6a37f6f04..000000000 --- a/Rules/project.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "name": "Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules", - "version": "1.16.1", - "dependencies": { - "System.Management.Automation": "6.0.0-alpha13", - "Engine": "1.16.1", - "Newtonsoft.Json": "9.0.1" - }, - - "configurations": { - "PSV3Release": { - "buildOptions": { - "define": [ "PSV3", "PSV5" ], - "optimize": true - } - }, - "PSV3Debug": { - "buildOptions": { - "define": [ "PSV3", "DEBUG" ] - } - } - }, - - "frameworks": { - "net451": { - "frameworkAssemblies": { - "System.ComponentModel.Composition": "", - "System.Data.Entity.Design": "" - }, - "buildOptions": { - "compile": { - "exclude": [ - "Strings.Designer.Core.cs", - "Strings.Designer.cs" - ] - }, - "debugType": "portable" - } - }, - "netstandard1.6": { - "imports": "dnxcore50", - "buildOptions": { - "define": [ "CORECLR" ], - "compile": { - "exclude": [ - "Strings.Designer.cs", - "Strings.Designer.Core.cs", - "UseSingularNouns.cs" - ] - }, - "debugType": "portable" - }, - "dependencies": { - "Microsoft.NETCore.App": { - "type": "platform", - "version": "1.0.0-rc2-3002702" - } - } - } - } -} diff --git a/Utils/ReleaseMaker.psm1 b/Utils/ReleaseMaker.psm1 index 9d2dffcb9..da33bfac9 100644 --- a/Utils/ReleaseMaker.psm1 +++ b/Utils/ReleaseMaker.psm1 @@ -171,8 +171,8 @@ function Update-Version [string] $solutionPath ) - $ruleJson = Combine-Path $solutionPath 'Rules' 'project.json' - $engineJson = Combine-Path $solutionPath 'Engine' 'project.json' + $ruleJson = Combine-Path $solutionPath 'Rules' 'Rules.csproj' + $engineJson = Combine-Path $solutionPath 'Engine' 'Engine.csproj' $pssaManifest = Combine-Path $solutionPath 'Engine' 'PSScriptAnalyzer.psd1' Update-PatternInFile $ruleJson '"version": "{0}"' $oldVer $newVer diff --git a/Utils/RuleMaker.psm1 b/Utils/RuleMaker.psm1 index fe01740c8..cea6af750 100644 --- a/Utils/RuleMaker.psm1 +++ b/Utils/RuleMaker.psm1 @@ -22,7 +22,7 @@ Function Get-SolutionRoot $PSModule = $ExecutionContext.SessionState.Module $path = $PSModule.ModuleBase $root = Split-Path -Path $path -Parent - $solutionFilename = 'psscriptanalyzer.sln' + $solutionFilename = 'PSScriptAnalyzer.sln' if (-not (Test-Path (Join-Path $root $solutionFilename))) { return $null diff --git a/appveyor.yml b/appveyor.yml index 1e24d0dea..6243fdc67 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,6 +1,6 @@ environment: matrix: - - APPVEYOR_BUILD_WORKER_IMAGE: WMF 5 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 PowerShellEdition: Desktop BuildConfiguration: Release - APPVEYOR_BUILD_WORKER_IMAGE: WMF 4 @@ -10,20 +10,35 @@ environment: # clone directory clone_folder: c:\projects\psscriptanalyzer -# cache nuget packages +# cache Nuget packages and dotnet CLI cache cache: - - '%USERPROFILE%\.nuget\packages -> **\project.json' + - '%USERPROFILE%\.nuget\packages -> appveyor.yml' + - '%LocalAppData%\Microsoft\dotnet -> appveyor.yml' # Install Pester install: - - cinst -y pester --version 3.4.0 - ps: nuget install platyPS -Version 0.5.0 -source https://www.powershellgallery.com/api/v2 -outputDirectory "$Env:ProgramFiles\WindowsPowerShell\Modules\." -ExcludeVersion + - ps: | + $requiredPesterVersion = '3.4.0' + $pester = Get-Module Pester -ListAvailable | Where-Object { $_.Version -eq $requiredPesterVersion } + $pester + if ($null -eq $pester) # WMF 4 build does not have pester + { + cinst -y pester --version $requiredPesterVersion + } + - ps: | + # the legacy WMF4 image only has the old preview SDKs of dotnet + if (-not ((dotnet --version).StartsWith('2.1.4'))) + { + Invoke-WebRequest 'https://dot.net/v1/dotnet-install.ps1' -OutFile dotnet-install.ps1 + .\dotnet-install.ps1 -Version 2.1.4 + } build_script: - ps: | $PSVersionTable Push-Location C:\projects\psscriptanalyzer - dotnet restore + dotnet --version C:\projects\psscriptanalyzer\buildCoreClr.ps1 -Framework net451 -Configuration $env:BuildConfiguration -Build C:\projects\psscriptanalyzer\build.ps1 -BuildDocs Pop-Location diff --git a/buildCoreClr.ps1 b/buildCoreClr.ps1 index f3111380f..86a28a1c5 100644 --- a/buildCoreClr.ps1 +++ b/buildCoreClr.ps1 @@ -1,5 +1,8 @@ param( + # Automatically performs a 'dotnet restore' when being run the first time [switch]$Build, + # Restore Projects in case NuGet packages have changed + [switch]$Restore, [switch]$Uninstall, [switch]$Install, @@ -20,7 +23,12 @@ Function Test-DotNetRestore param( [string] $projectPath ) - Test-Path (Join-Path $projectPath 'project.lock.json') + Test-Path ([System.IO.Path]::Combine($projectPath, 'obj', 'project.assets.json')) +} + +function Invoke-RestoreSolution +{ + dotnet restore (Join-Path $PSScriptRoot .\PSScriptAnalyzer.sln) } $solutionDir = Split-Path $MyInvocation.InvocationName @@ -47,27 +55,29 @@ elseif ($Configuration -match 'PSv3') { $destinationDirBinaries = "$destinationDir\PSv3" } +if ($Restore.IsPresent) +{ + Invoke-RestoreSolution +} if ($build) { if (-not (Test-DotNetRestore((Join-Path $solutionDir Engine)))) { - throw "Please restore project Engine" + Invoke-RestoreSolution } - .\New-StronglyTypedCsFileForResx.ps1 Engine Push-Location Engine\ - dotnet build --framework $Framework --configuration $Configuration + dotnet build Engine.csproj --framework $Framework --configuration $Configuration Pop-Location if (-not (Test-DotNetRestore((Join-Path $solutionDir Rules)))) { - throw "Please restore project Rules" + Invoke-RestoreSolution } - .\New-StronglyTypedCsFileForResx.ps1 Rules Push-Location Rules\ - dotnet build --framework $Framework --configuration $Configuration + dotnet build Rules.csproj --framework $Framework --configuration $Configuration Pop-Location Function CopyToDestinationDir($itemsToCopy, $destination) diff --git a/global.json b/global.json index 023d5575d..0b0ba35ab 100644 --- a/global.json +++ b/global.json @@ -4,6 +4,6 @@ "Rules" ], "sdk": { - "version": "1.0.0-preview2-1-003177" + "version": "2.1.4" } }