Skip to content

Commit d6200d7

Browse files
author
Kapil Borle
authored
Merge branch 'development' into kapilmb/use-should-process-rule
2 parents 489b37f + f45c20b commit d6200d7

36 files changed

+747
-84
lines changed

CHANGELOG.MD

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,26 @@
1-
## [1.11.0](https://github.com/PowerShell/PSScriptAnalyzer/tree/1.11.0) - 2017-03-01
1+
## [unreleased]
2+
3+
## Fixed
4+
- `PSAlignAssignmentStatement` to align assignment statements in DSC configurations that have *Undefined DSC Resource* parse errors.
5+
6+
## [1.12.0](https://github.com/PowerShell/PSScriptAnalyzer/tree/1.11.1) - 2017-05-09
7+
8+
### Added
9+
- [PSAlignAssignmentRuleStatement](https://github.com/PowerShell/PSScriptAnalyzer/blob/cca9a2d7ee35be7322f8c5a09b6c500a0a8bd101/RuleDocumentation/AlignAssignmentStatement.md) rule to align assignment statements in property value pairs (#753).
10+
11+
### Fixed
12+
- `PSAvoidGlobalVars` rule to ignore `$global:lastexitcode` (#752).
13+
- `PSUseConsistentIndentation` to account for backtick on preceding line (#749).
14+
- `PSPlaceCloseBrace` to ignore one-line blocks when `NewLineAfter` switch is on (#748).
15+
16+
## [1.11.1](https://github.com/PowerShell/PSScriptAnalyzer/tree/1.11.1) - 2017-04-04
17+
### Fixed
18+
- CodeFormatting settings file (#727, #728).
19+
- Whitelisted aliases comparison in AvoidUsingCmdletAliases rule (#739).
20+
- PlaceCloseBrace rule behavior for NewLineAfter option (#741).
21+
- UseConsistentIndentation rule to ignore open brace in magic methods (#744).
22+
23+
## [1.11.0](https://github.com/PowerShell/PSScriptAnalyzer/tree/1.11.0) - 2017-03-01
224
### Added
325
- Built-in settings presets to specify settings from command line (#717). Currently, PSSA ships with `PSGallery`, `CodeFormatting`, `DSC`, and other settings presets. All of them can be found in the `Settings/` directory in the module. To use them just pass them as an argument to the `Settings` parameter. For example, if you want to run rules that *powershellgallery* runs, then use the following command.
426
```powershell

Engine/Commands/InvokeScriptAnalyzerCommand.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,16 @@ public SwitchParameter SaveDscDependency
206206
}
207207
private bool saveDscDependency;
208208
#endif // !PSV3
209+
210+
#if DEBUG
211+
[Parameter(Mandatory = false)]
212+
public SwitchParameter AttachAndDebug
213+
{
214+
get { return attachAndDebug; }
215+
set { attachAndDebug = value; }
216+
}
217+
private bool attachAndDebug = false;
218+
#endif
209219
#endregion Parameters
210220

211221
#region Overrides
@@ -216,6 +226,19 @@ public SwitchParameter SaveDscDependency
216226
protected override void BeginProcessing()
217227
{
218228
// Initialize helper
229+
#if DEBUG
230+
if (attachAndDebug)
231+
{
232+
if (System.Diagnostics.Debugger.IsAttached)
233+
{
234+
System.Diagnostics.Debugger.Break();
235+
}
236+
else
237+
{
238+
System.Diagnostics.Debugger.Launch();
239+
}
240+
}
241+
#endif
219242
Helper.Instance = new Helper(
220243
SessionState.InvokeCommand,
221244
this);

Engine/PSScriptAnalyzer.psd1

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Author = 'Microsoft Corporation'
1111
RootModule = 'PSScriptAnalyzer.psm1'
1212

1313
# Version number of this module.
14-
ModuleVersion = '1.11.0'
14+
ModuleVersion = '1.12.0'
1515

1616
# ID used to uniquely identify this module
1717
GUID = 'd6245802-193d-4068-a631-8863a4342a18'
@@ -88,23 +88,12 @@ PrivateData = @{
8888
IconUri = ''
8989
ReleaseNotes = @'
9090
### Added
91-
- Built-in settings presets to specify settings from command line (#717). Currently, PSSA ships with `PSGallery`, `CodeFormatting`, `DSC`, and other settings presets. All of them can be found in the `Settings/` directory in the module. To use them just pass them as an argument to the `Settings` parameter. For example, if you want to run rules that *powershellgallery* runs, then use the following command.
92-
```powershell
93-
PS> Invoke-ScriptAnalyzer -Path /path/to/your/module -Settings PSGallery
94-
```
95-
- Argument completion for built-in settings presets (#717).
96-
- Argument completion for `IncludeRule` and `ExcludeRule` parameters (#717).
97-
- Option to `PSCloseBrace` rule to add new line after the brace (#713).
98-
- Option to `PSCloseBrace` rule to ignore expressions that have open and close braces on the same line (#706).
99-
- New rule, PSUseConsistentWhitespace, to check for whitespace style around operators and separators (#702).
91+
- PSAlignAssignmentRuleStatement rule to align assignment statements in property value pairs (#753).
10092
10193
### Fixed
102-
- Indentation when pipes precede new lines in a multi-line command expression in `PSUseConsistentIdentation` rule (#705).
103-
- Handling of SubExpressionAsts (`$(...)`) in `PSUseConsistentIdentation` rule (#700).
104-
- Performance issues caused by `get-command` cmdlet (#695).
105-
106-
### Changed
107-
- Settings implementation to decouple it from engine (#717).
94+
- `PSAvoidGlobalVars` rule to ignore `$global:lastexitcode` (#752).
95+
- `PSUseConsistentIndentation` to account for backtick on preceding line (#749).
96+
- `PSPlaceCloseBrace` to ignore one-line blocks when `NewLineAfter` switch is on (#748).
10897
'@
10998
}
11099
}
@@ -121,3 +110,5 @@ PS> Invoke-ScriptAnalyzer -Path /path/to/your/module -Settings PSGallery
121110

122111

123112

113+
114+

Engine/Settings/CodeFormatting.psd1

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
IncludeRules = @(
33
'PSPlaceOpenBrace',
44
'PSPlaceCloseBrace',
5+
'PSUseConsistentWhitespace',
56
'PSUseConsistentIndentation',
6-
'PSUseConsistentWhitespace'
7+
'PSAlignAssignmentStatement'
78
)
89

910
Rules = @{
@@ -30,5 +31,10 @@
3031
CheckSeparator = $true
3132
}
3233

34+
PSAlignAssignmentStatement = @{
35+
Enable = $true
36+
CheckHashtable = $true
37+
CheckDSCConfiguration = $true
38+
}
3339
}
3440
}

Engine/SpecialVars.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ internal enum PreferenceVariable
164164
internal const string Null = "null";
165165
internal const string True = "true";
166166
internal const string False = "false";
167+
internal const string LastExitCode = "LastExitCode";
167168

168169
internal static readonly string[] OtherInitializedVariables = new string[]
169170
{
@@ -184,7 +185,8 @@ internal enum PreferenceVariable
184185
pwd,
185186
Null,
186187
True,
187-
False
188+
False,
189+
LastExitCode
188190
};
189191

190192
}

Engine/TokenOperations.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,11 @@ public IEnumerable<Tuple<Token, int>> GetOpenParensWithWhiteSpacesBefore()
297297
return GetTokenAndPrecedingWhitespace(TokenKind.LParen);
298298
}
299299

300+
public static int GetExtentWidth(IScriptExtent extent)
301+
{
302+
return extent.EndOffset - extent.StartOffset;
303+
}
304+
300305
private bool OnSameLine(Token token1, Token token2)
301306
{
302307
return token1.Extent.StartLineNumber == token2.Extent.EndLineNumber;

Engine/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Microsoft.Windows.PowerShell.ScriptAnalyzer",
3-
"version": "1.11.0",
3+
"version": "1.12.0",
44
"dependencies": {
55
"System.Management.Automation": "1.0.0-alpha12"
66
},
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# AlignAssignmentStatement
2+
3+
**Severity Level: Warning**
4+
5+
## Description
6+
7+
Consecutive assignment statements are more readable if they are aligned. By aligned, we imply that the `equal` sign for all the assignment statements should be in the same column.
8+
9+
The rule looks for key (property) value pairs in a hashtable (DSC configuration) to check if they are aligned or not. Consider the following example in which the key value pairs are not aligned.
10+
11+
```powershell
12+
$hashtable = @{
13+
property1 = "value"
14+
anotherProperty = "another value"
15+
}
16+
```
17+
18+
Alignment in this case would look like the following.
19+
20+
```powershell
21+
$hashtable = @{
22+
property1 = "value"
23+
anotherProperty = "another value"
24+
}
25+
```
26+
27+
The rule will ignore hashtables in which the assignment statements are on the same line. For example, the rule will ignore `$h = {a = 1; b = 2}`.
28+
29+
## Configuration
30+
31+
```powershell
32+
Rules = @{
33+
PSAlignAssignmentStatement = @{
34+
Enable = $true
35+
CheckHashtable = $true
36+
}
37+
}
38+
```
39+
40+
### Parameters
41+
42+
#### Enable: bool (Default value is `$false`)
43+
44+
Enable or disable the rule during ScriptAnalyzer invocation.
45+
46+
#### CheckHashtable: bool (Default value is `$false`)
47+
48+
Enforce alignment of assignment statements in a hashtable and in a DSC Configuration. There is only one switch for hasthable and DSC configuration because the property value pairs in a DSC configuration are parsed as key value pairs of a hashtable.

RuleDocumentation/ProvideDefaultParameterValue.md renamed to RuleDocumentation/AvoidDefaultValueForMandatoryParameter.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ProvideDefaultParameterValue
1+
# AvoidDefaultValueForMandatoryParameter
22

33
**Severity Level: Warning**
44

RuleDocumentation/AvoidDefaultTrueValueSwitchParameter.md renamed to RuleDocumentation/AvoidDefaultValueSwitchParameter.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# AvoidDefaultTrueValueSwitchParameter
1+
# AvoidDefaultValueSwitchParameter
22

33
**Severity Level: Warning**
44

RuleDocumentation/AvoidAlias.md renamed to RuleDocumentation/AvoidUsingCmdletAliases.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# AvoidAlias
1+
# AvoidUsingCmdletAliases
22

33
**Severity Level: Warning**
44

RuleDocumentation/AvoidEmptyCatchBlock.md renamed to RuleDocumentation/AvoidUsingEmptyCatchBlock.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# AvoidEmptyCatchBlock
1+
# AvoidUsingEmptyCatchBlock
22

33
**Severity Level: Warning**
44

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# MisleadingBacktick
2+
3+
**Severity Level: Warning**
4+
5+
## Description
6+
7+
Checks that lines don't end with a backtick followed by whitespace.

RuleDocumentation/AvoidReservedCharInCmdlet.md renamed to RuleDocumentation/ReservedCmdletChar.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# AvoidReservedCharInCmdlet
1+
# ReservedCmdletChar
22

33
**Severity Level: Error**
44

RuleDocumentation/AvoidReservedParams.md renamed to RuleDocumentation/ReservedParams.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# AvoidReservedParams
1+
# ReservedParams
22

33
**Severity Level: Error**
44

RuleDocumentation/ReturnCorrectTypeDSCFunctions.md renamed to RuleDocumentation/ReturnCorrectTypesForDSCFunctions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ReturnCorrectTypeDSCFunctions
1+
# ReturnCorrectTypesForDSCFunctions
22

33
**Severity Level: Information**
44

RuleDocumentation/UseShouldProcessCorrectly.md renamed to RuleDocumentation/ShouldProcess.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# UseShouldProcessCorrectly
1+
# ShouldProcess
22

33
**Severity Level: Warning**
44

RuleDocumentation/UseStandardDSCFunctionsInResource.md renamed to RuleDocumentation/StandardDSCFunctionsInResource.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# UseStandardDSCFunctionsInResource
1+
# StandardDSCFunctionsInResource
22

33
**Severity Level: Error**
44

RuleDocumentation/UseIdenticalMandatoryParametersDSC.md renamed to RuleDocumentation/UseIdenticalMandatoryParametersForDSC.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# UseIdenticalMandatoryParametersDSC
1+
# UseIdenticalMandatoryParametersForDSC
22

33
**Severity Level: Error**
44

RuleDocumentation/UseIdenticalParametersDSC.md renamed to RuleDocumentation/UseIdenticalParametersForDSC.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# UseIdenticalParametersDSC
1+
# UseIdenticalParametersForDSC
22

33
**Severity Level: Error**
44

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# UseUTF8EncodingForHelpFile
2+
3+
**Severity Level: Warning**
4+
5+
## Description
6+
7+
Check if help file uses utf8 encoding

RuleDocumentation/ProvideVerboseMessage.md renamed to RuleDocumentation/UseVerboseMessageInDSCResource.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ProvideVerboseMessage
1+
# UseVerboseMessageInDSCResource
22

33
**Severity Level: Information**
44

0 commit comments

Comments
 (0)