Skip to content

Commit 2cc6ad3

Browse files
committed
Merge pull request #334 from PowerShell/development
Merge Branches
2 parents 44949a6 + 24f7858 commit 2cc6ad3

24 files changed

+332
-35
lines changed

Engine/Commands/InvokeScriptAnalyzerCommand.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using System;
1515
using System.ComponentModel;
1616
using System.Collections.Generic;
17+
using System.Collections.ObjectModel;
1718
using System.Diagnostics.CodeAnalysis;
1819
using System.Globalization;
1920
using System.Linq;
@@ -159,9 +160,12 @@ protected override void BeginProcessing()
159160
/// </summary>
160161
protected override void ProcessRecord()
161162
{
162-
// throws Item Not Found Exception
163-
path = this.SessionState.Path.GetResolvedPSPathFromPSPath(path).First().ToString();
164-
ProcessPath(path);
163+
// throws Item Not Found Exception
164+
Collection<PathInfo> paths = this.SessionState.Path.GetResolvedPSPathFromPSPath(path);
165+
foreach (PathInfo p in paths)
166+
{
167+
ProcessPath(this.SessionState.Path.GetUnresolvedProviderPathFromPSPath(p.Path));
168+
}
165169
}
166170

167171
#endregion

Engine/Helper.cs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -934,22 +934,15 @@ public Tuple<List<SuppressedRecord>, List<DiagnosticRecord>> SuppressRule(string
934934
break;
935935
}
936936

937-
if (string.IsNullOrWhiteSpace(ruleSuppression.RuleSuppressionID))
937+
// we suppress if there is no suppression id or if there is suppression id and it matches
938+
if (string.IsNullOrWhiteSpace(ruleSuppression.RuleSuppressionID)
939+
|| (!String.IsNullOrWhiteSpace(record.RuleSuppressionID) &&
940+
string.Equals(ruleSuppression.RuleSuppressionID, record.RuleSuppressionID, StringComparison.OrdinalIgnoreCase)))
938941
{
939942
suppressed[recordIndex] = true;
943+
suppressedRecords.Add(new SuppressedRecord(record, ruleSuppression));
940944
suppressionCount += 1;
941945
}
942-
else
943-
{
944-
//if there is a rule suppression id, we only suppressed if it matches
945-
if (!String.IsNullOrWhiteSpace(record.RuleSuppressionID) &&
946-
string.Equals(ruleSuppression.RuleSuppressionID, record.RuleSuppressionID, StringComparison.OrdinalIgnoreCase))
947-
{
948-
suppressed[recordIndex] = true;
949-
suppressedRecords.Add(new SuppressedRecord(record, ruleSuppression));
950-
suppressionCount += 1;
951-
}
952-
}
953946

954947
recordIndex += 1;
955948
}

Engine/ScriptAnalyzer.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ private IEnumerable<DiagnosticRecord> AnalyzeFile(string filePath)
962962
{
963963
ScriptBlockAst scriptAst = null;
964964
Token[] scriptTokens = null;
965-
ParseError[] errors;
965+
ParseError[] errors = null;
966966

967967
this.outputWriter.WriteVerbose(string.Format(CultureInfo.CurrentCulture, Strings.VerboseFileMessage, filePath));
968968

@@ -972,7 +972,15 @@ private IEnumerable<DiagnosticRecord> AnalyzeFile(string filePath)
972972
// processing for non help script
973973
if (!(Path.GetFileName(filePath).StartsWith("about_") && Path.GetFileName(filePath).EndsWith(".help.txt")))
974974
{
975-
scriptAst = Parser.ParseFile(filePath, out scriptTokens, out errors);
975+
try
976+
{
977+
scriptAst = Parser.ParseFile(filePath, out scriptTokens, out errors);
978+
}
979+
catch (Exception e)
980+
{
981+
this.outputWriter.WriteWarning(e.ToString());
982+
return null;
983+
}
976984

977985
if (errors != null && errors.Length > 0)
978986
{
@@ -983,7 +991,7 @@ private IEnumerable<DiagnosticRecord> AnalyzeFile(string filePath)
983991
}
984992
}
985993

986-
if (errors.Length > 10)
994+
if (errors != null && errors.Length > 10)
987995
{
988996
string manyParseErrorMessage = String.Format(CultureInfo.CurrentCulture, Strings.ParserErrorMessage, System.IO.Path.GetFileName(filePath));
989997
this.outputWriter.WriteError(new ErrorRecord(new ParseException(manyParseErrorMessage), manyParseErrorMessage, ErrorCategory.ParserError, filePath));

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1+
Announcements
2+
=============
3+
4+
ScriptAnalyzer community meeting schedule:
5+
6+
- Next Meeting - 10/13/2015 - 11am to 12pm PDT
7+
- [iCalender invite](http://1drv.ms/1VvAaxO)
8+
- [Notes and recordings from earlier meetings](https://github.com/PowerShell/PSScriptAnalyzer/wiki)
9+
10+
11+
=============
12+
113
|Master |BugFixes |Development |
214
|:------:|:------:|:-------:|:-------:|
315
[![Build status](https://ci.appveyor.com/api/projects/status/h5mot3vqtvxw5d7l/branch/master?svg=true)](https://ci.appveyor.com/project/PowerShell/psscriptanalyzer/branch/master)|[![Build status](https://ci.appveyor.com/api/projects/status/h5mot3vqtvxw5d7l/branch/bugfixes?svg=true)](https://ci.appveyor.com/project/PowerShell/psscriptanalyzer/branch/bugfixes)|[![Build status](https://ci.appveyor.com/api/projects/status/h5mot3vqtvxw5d7l/branch/development?svg=true)](https://ci.appveyor.com/project/PowerShell/psscriptanalyzer/branch/development) |
416

17+
=============
518

619

720
Introduction

RuleDocumentation/AvoidInvokingEmptyMembers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
##Description
66

7-
Invoking non-constant members would cause potential bugs. Please double check the syntax to make sure members invoked are non-constant.
7+
Invoking non-constant members would cause potential bugs. Please double check the syntax to make sure that invoked members are constants.
88

99

1010
##How to Fix
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#UseBOMForUnicodeEncodedFile
2+
**Severity Level: Warning**
3+
4+
##Description
5+
6+
For a file encoded with a format other than ASCII, ensure BOM is present to ensure that any application consuming this file can interpret it correctly.

Rules/AvoidInvokingEmptyMembers.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020

2121
namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules
2222
{
23+
// Rule name is inconsistent.
2324
/// <summary>
24-
/// AvoidAlias: Check if cmdlet alias is used.
25-
/// </summary>
25+
/// AvoidInvokingEmptyMembers: Analyzes the script to check if any non-constant members have been invoked.
26+
/// </summary>
2627
[Export(typeof(IScriptRule))]
2728
public class AvoidInvokingEmptyMembers : IScriptRule
2829
{
2930
/// <summary>
30-
/// AnalyzeScript: Analyze the script to check if any empty members has been invoked.
31+
/// AnalyzeScript: Analyzes the script to check if any non-constant members have been invoked.
3132
/// </summary>
3233
public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
3334
{

Rules/ScriptAnalyzerBuiltinRules.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
<Compile Include="AvoidUsingWriteHost.cs" />
7171
<Compile Include="DscTestsPresent.cs" />
7272
<Compile Include="DscExamplesPresent.cs" />
73+
<Compile Include="UseBOMForUnicodeEncodedFile.cs" />
7374
<Compile Include="UseOutputTypeCorrectly.cs" />
7475
<Compile Include="MissingModuleManifestField.cs" />
7576
<Compile Include="PossibleIncorrectComparisonWithNull.cs" />

Rules/Strings.Designer.cs

Lines changed: 39 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Rules/Strings.resx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@
526526
<value>Invoking non-constant members would cause potential bugs. Please double check the syntax to make sure members invoked are non-constant.</value>
527527
</data>
528528
<data name="AvoidInvokingEmptyMembersError" xml:space="preserve">
529-
<value>'{0}' has non-constant members. Invoking empty members may cause bugs in the script.</value>
529+
<value>'{0}' has non-constant members. Invoking non-constant members may cause bugs in the script.</value>
530530
</data>
531531
<data name="AvoidInvokingEmptyMembersName" xml:space="preserve">
532532
<value>AvoidInvokingEmptyMembers</value>
@@ -586,7 +586,7 @@
586586
<value>Using Internal URLs in the scripts may cause security problems.</value>
587587
</data>
588588
<data name="AvoidUsingInternalURLsError" xml:space="preserve">
589-
<value>'{0}' could be an internal URL. Using internal URL directly in the script may cause potential information discloure.</value>
589+
<value>'{0}' could be an internal URL. Using internal URL directly in the script may cause potential information disclosure.</value>
590590
</data>
591591
<data name="AvoidUsingInternalURLsName" xml:space="preserve">
592592
<value>AvoidUsingInternalURLs</value>
@@ -744,4 +744,16 @@
744744
<data name="UseUTF8EncodingForHelpFileName" xml:space="preserve">
745745
<value>UseUTF8EncodingForHelpFile</value>
746746
</data>
747+
<data name="UseBOMForUnicodeEncodedFileCommonName" xml:space="preserve">
748+
<value>Use BOM encoding for non-ASCII files</value>
749+
</data>
750+
<data name="UseBOMForUnicodeEncodedFileDescription" xml:space="preserve">
751+
<value>For a file encoded with a format other than ASCII, ensure BOM is present to ensure that any application consuming this file can interpret it correctly.</value>
752+
</data>
753+
<data name="UseBOMForUnicodeEncodedFileError" xml:space="preserve">
754+
<value>Missing BOM encoding for non-ASCII encoded file '{0}'</value>
755+
</data>
756+
<data name="UseBOMForUnicodeEncodedFileName" xml:space="preserve">
757+
<value>UseBOMForUnicodeEncodedFile</value>
758+
</data>
747759
</root>

0 commit comments

Comments
 (0)