-
Notifications
You must be signed in to change notification settings - Fork 395
Do not increase indentation after LParen if the previous token is a Newline and the next token is not a Newline #1469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8a7847e
20c110a
194022d
bd738a7
607615c
5fd495c
a47555f
5f2201e
b3bf36d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -134,6 +134,13 @@ public override IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string file | |||||||
var onNewLine = true; | ||||||||
var pipelineAsts = ast.FindAll(testAst => testAst is PipelineAst && (testAst as PipelineAst).PipelineElements.Count > 1, true).ToList(); | ||||||||
int minimumPipelineAstIndex = 0; | ||||||||
/* | ||||||||
When an LParen and LBrace are on the same line, it can lead to too much de-indentation. | ||||||||
In order to prevent the RParen code from de-indenting too much, we keep a stack of when we skipped the indentation | ||||||||
caused by tokens that require a closing RParen (which are LParen, AtParen and DollarParen). | ||||||||
*/ | ||||||||
var lParenSkippedIndentation = new Stack<bool>(); | ||||||||
|
||||||||
for (int tokenIndex = 0; tokenIndex < tokens.Length; tokenIndex++) | ||||||||
{ | ||||||||
var token = tokens[tokenIndex]; | ||||||||
|
@@ -146,10 +153,27 @@ public override IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string file | |||||||
switch (token.Kind) | ||||||||
{ | ||||||||
case TokenKind.AtCurly: | ||||||||
case TokenKind.AtParen: | ||||||||
case TokenKind.LParen: | ||||||||
case TokenKind.LCurly: | ||||||||
AddViolation(token, indentationLevel++, diagnosticRecords, ref onNewLine); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would break the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's 3 other places in this file where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm happy with it as is |
||||||||
break; | ||||||||
|
||||||||
case TokenKind.DollarParen: | ||||||||
case TokenKind.AtParen: | ||||||||
lParenSkippedIndentation.Push(false); | ||||||||
AddViolation(token, indentationLevel++, diagnosticRecords, ref onNewLine); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||||||||
break; | ||||||||
|
||||||||
case TokenKind.LParen: | ||||||||
// When a line starts with a parenthesis and it is not the last non-comment token of that line, | ||||||||
// then indentation does not need to be increased. | ||||||||
if ((tokenIndex == 0 || tokens[tokenIndex - 1].Kind == TokenKind.NewLine) && | ||||||||
NextTokenIgnoringComments(tokens, tokenIndex)?.Kind != TokenKind.NewLine) | ||||||||
{ | ||||||||
onNewLine = false; | ||||||||
lParenSkippedIndentation.Push(true); | ||||||||
break; | ||||||||
} | ||||||||
lParenSkippedIndentation.Push(false); | ||||||||
AddViolation(token, indentationLevel++, diagnosticRecords, ref onNewLine); | ||||||||
break; | ||||||||
|
||||||||
|
@@ -181,6 +205,20 @@ public override IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string file | |||||||
break; | ||||||||
|
||||||||
case TokenKind.RParen: | ||||||||
bool matchingLParenIncreasedIndentation = false; | ||||||||
if (lParenSkippedIndentation.Count > 0) | ||||||||
{ | ||||||||
matchingLParenIncreasedIndentation = lParenSkippedIndentation.Pop(); | ||||||||
} | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would make it inconsistent with the existing style where there is one newline only between the many There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well the current PSSA codebase style is such that I won't argue. I think blocks should always be separated by newlines (and would have included another newline below the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not a fan of the PSSA style either TBH (especially the long methods where high level context is needed). I suggest a follow-up style PR to make the whole file consistent with this style or define something like an |
||||||||
if (matchingLParenIncreasedIndentation) | ||||||||
{ | ||||||||
onNewLine = false; | ||||||||
break; | ||||||||
} | ||||||||
indentationLevel = ClipNegative(indentationLevel - 1); | ||||||||
AddViolation(token, indentationLevel, diagnosticRecords, ref onNewLine); | ||||||||
break; | ||||||||
|
||||||||
case TokenKind.RCurly: | ||||||||
indentationLevel = ClipNegative(indentationLevel - 1); | ||||||||
AddViolation(token, indentationLevel, diagnosticRecords, ref onNewLine); | ||||||||
|
@@ -259,6 +297,29 @@ public override IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string file | |||||||
return diagnosticRecords; | ||||||||
} | ||||||||
|
||||||||
private static Token NextTokenIgnoringComments(Token[] tokens, int startIndex) | ||||||||
{ | ||||||||
if (startIndex >= tokens.Length - 1) | ||||||||
{ | ||||||||
return null; | ||||||||
} | ||||||||
|
||||||||
for (int i = startIndex + 1; i < tokens.Length; i++) | ||||||||
{ | ||||||||
switch (tokens[i].Kind) | ||||||||
{ | ||||||||
case TokenKind.Comment: | ||||||||
continue; | ||||||||
|
||||||||
default: | ||||||||
return tokens[i]; | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
// We've run out of tokens | ||||||||
return null; | ||||||||
} | ||||||||
|
||||||||
private static bool PipelineIsFollowedByNewlineOrLineContinuation(Token[] tokens, int startIndex) | ||||||||
{ | ||||||||
if (startIndex >= tokens.Length - 1) | ||||||||
|
Uh oh!
There was an error while loading. Please reload this page.