@@ -1499,7 +1499,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeAndFixPath(string path, Func<string,
1499
1499
/// </summary>
1500
1500
/// <param name="scriptDefinition">The script to be analyzed</param>
1501
1501
/// <returns></returns>
1502
- public IEnumerable < DiagnosticRecord > AnalyzeScriptDefinition ( string scriptDefinition )
1502
+ public IEnumerable < DiagnosticRecord > AnalyzeScriptDefinition ( string scriptDefinition , bool skipVariableAnalysis = false )
1503
1503
{
1504
1504
ScriptBlockAst scriptAst = null ;
1505
1505
Token [ ] scriptTokens = null ;
@@ -1539,7 +1539,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeScriptDefinition(string scriptDefini
1539
1539
}
1540
1540
1541
1541
// now, analyze the script definition
1542
- return diagnosticRecords . Concat ( this . AnalyzeSyntaxTree ( scriptAst , scriptTokens , String . Empty ) ) ;
1542
+ return diagnosticRecords . Concat ( this . AnalyzeSyntaxTree ( scriptAst , scriptTokens , String . Empty , skipVariableAnalysis ) ) ;
1543
1543
}
1544
1544
1545
1545
/// <summary>
@@ -1566,8 +1566,9 @@ public string Fix(string scriptDefinition, out bool fixesWereApplied)
1566
1566
/// <param name="range">The range in which the fixes are allowed.</param>
1567
1567
/// <param name="updatedRange">The updated range after the fixes have been applied.</param>
1568
1568
/// <param name="updatedRange">Whether any warnings were fixed.</param>
1569
+ /// <param name="skipVariableAnalysis">Whether to skip variable analysis.</param>
1569
1570
/// <returns>The same instance of `EditableText` that was passed to the method, but the instance encapsulates the fixed script text. This helps in chaining the Fix method.</returns>
1570
- public EditableText Fix ( EditableText text , Range range , out Range updatedRange , out bool fixesWereApplied )
1571
+ public EditableText Fix ( EditableText text , Range range , out Range updatedRange , out bool fixesWereApplied , bool skipVariableAnalysis = false )
1571
1572
{
1572
1573
if ( text == null )
1573
1574
{
@@ -1589,7 +1590,7 @@ public EditableText Fix(EditableText text, Range range, out Range updatedRange,
1589
1590
var previousUnusedCorrections = 0 ;
1590
1591
do
1591
1592
{
1592
- var records = AnalyzeScriptDefinition ( text . ToString ( ) ) ;
1593
+ var records = AnalyzeScriptDefinition ( text . ToString ( ) , skipVariableAnalysis ) ;
1593
1594
var corrections = records
1594
1595
. Select ( r => r . SuggestedCorrections )
1595
1596
. Where ( sc => sc != null && sc . Any ( ) )
@@ -2016,13 +2017,15 @@ DiagnosticRecord ruleDiagnosticRecord
2016
2017
/// <param name="scriptAst">The ScriptBlockAst from the parsed script.</param>
2017
2018
/// <param name="scriptTokens">The tokens found in the script.</param>
2018
2019
/// <param name="filePath">The path to the file that was parsed.
2020
+ /// <param name="skipVariableAnalysis">Whether to skip variable analysis.
2019
2021
/// If AnalyzeSyntaxTree is called from an ast that we get from ParseInput, then this field will be String.Empty
2020
2022
/// </param>
2021
2023
/// <returns>An enumeration of DiagnosticRecords that were found by rules.</returns>
2022
2024
public IEnumerable < DiagnosticRecord > AnalyzeSyntaxTree (
2023
2025
ScriptBlockAst scriptAst ,
2024
2026
Token [ ] scriptTokens ,
2025
- string filePath )
2027
+ string filePath ,
2028
+ bool skipVariableAnalysis = false )
2026
2029
{
2027
2030
Dictionary < string , List < RuleSuppression > > ruleSuppressions = new Dictionary < string , List < RuleSuppression > > ( ) ;
2028
2031
ConcurrentBag < DiagnosticRecord > diagnostics = new ConcurrentBag < DiagnosticRecord > ( ) ;
@@ -2053,13 +2056,16 @@ public IEnumerable<DiagnosticRecord> AnalyzeSyntaxTree(
2053
2056
}
2054
2057
}
2055
2058
2056
- #region Run VariableAnalysis
2057
- try
2059
+ if ( ! skipVariableAnalysis )
2058
2060
{
2059
- Helper . Instance . InitializeVariableAnalysis ( scriptAst ) ;
2060
- }
2061
- catch { }
2061
+ #region Run VariableAnalysis
2062
+ try
2063
+ {
2064
+ Helper . Instance . InitializeVariableAnalysis ( scriptAst ) ;
2065
+ }
2066
+ catch { }
2062
2067
#endregion
2068
+ }
2063
2069
2064
2070
Helper . Instance . Tokens = scriptTokens ;
2065
2071
}
0 commit comments