20
20
using System . Globalization ;
21
21
using System . Text . RegularExpressions ;
22
22
using System . Diagnostics ;
23
+ using System . Text ;
23
24
24
25
namespace Microsoft . Windows . PowerShell . ScriptAnalyzer . BuiltinRules
25
26
{
@@ -33,7 +34,6 @@ public class UseToExportFieldsInManifest : IScriptRule
33
34
34
35
private const string functionsToExport = "FunctionsToExport" ;
35
36
private const string cmdletsToExport = "CmdletsToExport" ;
36
- private const string variablesToExport = "VariablesToExport" ;
37
37
private const string aliasesToExport = "AliasesToExport" ;
38
38
39
39
/// <summary>
@@ -70,7 +70,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
70
70
yield break ;
71
71
}
72
72
73
- string [ ] manifestFields = { functionsToExport , cmdletsToExport , variablesToExport , aliasesToExport } ;
73
+ string [ ] manifestFields = { functionsToExport , cmdletsToExport , aliasesToExport } ;
74
74
75
75
foreach ( string field in manifestFields )
76
76
{
@@ -85,19 +85,43 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
85
85
fileName ,
86
86
suggestedCorrections : GetCorrectionExtent ( field , extent , psModuleInfo ) ) ;
87
87
}
88
+ else
89
+ {
90
+
91
+ }
88
92
}
89
93
90
94
}
91
95
92
96
private string GetListLiteral < T > ( Dictionary < string , T > exportedItems )
93
97
{
98
+ const int lineWidth = 64 ;
94
99
if ( exportedItems == null || exportedItems . Keys == null )
95
100
{
96
101
return null ;
97
102
}
98
- var sbuilder = new System . Text . StringBuilder ( ) ;
103
+ var sbuilder = new StringBuilder ( ) ;
99
104
sbuilder . Append ( "@(" ) ;
100
- sbuilder . Append ( string . Join ( ", " , exportedItems . Keys . Select ( key => string . Format ( "'{0}'" , key ) ) ) ) ;
105
+ var sbuilderInner = new StringBuilder ( ) ;
106
+ int charLadder = lineWidth ;
107
+ int keyCount = exportedItems . Keys . Count ;
108
+ foreach ( var key in exportedItems . Keys )
109
+ {
110
+ sbuilderInner . Append ( "'" ) ;
111
+ sbuilderInner . Append ( key ) ;
112
+ sbuilderInner . Append ( "'" ) ;
113
+ if ( -- keyCount > 0 )
114
+ {
115
+ sbuilderInner . Append ( ", " ) ;
116
+ if ( sbuilderInner . Length > charLadder )
117
+ {
118
+ charLadder += lineWidth ;
119
+ sbuilderInner . AppendLine ( ) ;
120
+ sbuilderInner . Append ( '\t ' , 2 ) ;
121
+ }
122
+ }
123
+ }
124
+ sbuilder . Append ( sbuilderInner ) ;
101
125
sbuilder . Append ( ")" ) ;
102
126
return sbuilder . ToString ( ) ;
103
127
}
@@ -118,16 +142,16 @@ private List<CorrectionExtent> GetCorrectionExtent(string field, IScriptExtent e
118
142
case cmdletsToExport :
119
143
correctionText = GetListLiteral ( psModuleInfo . ExportedCmdlets ) ;
120
144
break ;
121
- case variablesToExport :
122
- correctionText = GetListLiteral ( psModuleInfo . ExportedVariables ) ;
123
- break ;
124
145
case aliasesToExport :
125
146
correctionText = GetListLiteral ( psModuleInfo . ExportedAliases ) ;
126
147
break ;
127
148
default :
128
149
throw new NotImplementedException ( string . Format ( "{0} not implemented" , field ) ) ;
129
150
}
130
- string description = string . Format ( "Replace {0} with {1}" , extent . Text , correctionText ) ;
151
+ string description = string . Format (
152
+ Strings . UseToExportFieldsInManifestCorrectionDescription ,
153
+ extent . Text ,
154
+ correctionText ) ;
131
155
corrections . Add ( new CorrectionExtent (
132
156
extent . StartLineNumber ,
133
157
extent . EndLineNumber ,
0 commit comments