2020using System . Globalization ;
2121using System . Text . RegularExpressions ;
2222using System . Diagnostics ;
23+ using System . Text ;
2324
2425namespace Microsoft . Windows . PowerShell . ScriptAnalyzer . BuiltinRules
2526{
@@ -33,7 +34,6 @@ public class UseToExportFieldsInManifest : IScriptRule
3334
3435 private const string functionsToExport = "FunctionsToExport" ;
3536 private const string cmdletsToExport = "CmdletsToExport" ;
36- private const string variablesToExport = "VariablesToExport" ;
3737 private const string aliasesToExport = "AliasesToExport" ;
3838
3939 /// <summary>
@@ -70,7 +70,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
7070 yield break ;
7171 }
7272
73- string [ ] manifestFields = { functionsToExport , cmdletsToExport , variablesToExport , aliasesToExport } ;
73+ string [ ] manifestFields = { functionsToExport , cmdletsToExport , aliasesToExport } ;
7474
7575 foreach ( string field in manifestFields )
7676 {
@@ -85,19 +85,43 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
8585 fileName ,
8686 suggestedCorrections : GetCorrectionExtent ( field , extent , psModuleInfo ) ) ;
8787 }
88+ else
89+ {
90+
91+ }
8892 }
8993
9094 }
9195
9296 private string GetListLiteral < T > ( Dictionary < string , T > exportedItems )
9397 {
98+ const int lineWidth = 64 ;
9499 if ( exportedItems == null || exportedItems . Keys == null )
95100 {
96101 return null ;
97102 }
98- var sbuilder = new System . Text . StringBuilder ( ) ;
103+ var sbuilder = new StringBuilder ( ) ;
99104 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 ) ;
101125 sbuilder . Append ( ")" ) ;
102126 return sbuilder . ToString ( ) ;
103127 }
@@ -118,16 +142,16 @@ private List<CorrectionExtent> GetCorrectionExtent(string field, IScriptExtent e
118142 case cmdletsToExport :
119143 correctionText = GetListLiteral ( psModuleInfo . ExportedCmdlets ) ;
120144 break ;
121- case variablesToExport :
122- correctionText = GetListLiteral ( psModuleInfo . ExportedVariables ) ;
123- break ;
124145 case aliasesToExport :
125146 correctionText = GetListLiteral ( psModuleInfo . ExportedAliases ) ;
126147 break ;
127148 default :
128149 throw new NotImplementedException ( string . Format ( "{0} not implemented" , field ) ) ;
129150 }
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 ) ;
131155 corrections . Add ( new CorrectionExtent (
132156 extent . StartLineNumber ,
133157 extent . EndLineNumber ,
0 commit comments