-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement csharpier-ignore for some node types (#584)
closes #581
- Loading branch information
Showing
6 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
Src/CSharpier.Tests/FormattingTests/TestFiles/CSharpierIgnore.cst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// csharpier-ignore | ||
public class Unformatted { } | ||
|
||
public class ClassName | ||
{ | ||
// csharpier-ignore | ||
private string unformatted; | ||
|
||
public void MethodName() | ||
{ | ||
// csharpier-ignore | ||
var unformatted = true; | ||
|
||
if (true) | ||
{ | ||
// csharpier-ignore | ||
var unformatted = true; | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Src/CSharpier.Tests/FormattingTests/TestFiles/CSharpierIgnore_Dont.cst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
public | ||
// csharpier-ignore | ||
class ClassName { | ||
private void MethodName( | ||
// csharpier-ignore | ||
string one) { | ||
var x | ||
// csharpier-ignore | ||
= someRandomValue; | ||
|
||
this.CallMethod( | ||
// csharpier-ignore | ||
true, false); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Src/CSharpier.Tests/FormattingTests/TestFiles/CSharpierIgnore_Dont.expected.cst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
public | ||
// csharpier-ignore | ||
class ClassName | ||
{ | ||
private void MethodName( | ||
// csharpier-ignore | ||
string one | ||
) | ||
{ | ||
var x | ||
// csharpier-ignore | ||
= someRandomValue; | ||
|
||
this.CallMethod( | ||
// csharpier-ignore | ||
true, | ||
false | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
namespace CSharpier.SyntaxPrinter; | ||
|
||
internal static class CSharpierIgnore | ||
{ | ||
public static bool IsNodeIgnored(SyntaxNode syntaxNode) | ||
{ | ||
if ( | ||
syntaxNode.Parent | ||
is not ( | ||
BaseTypeDeclarationSyntax | ||
or BlockSyntax | ||
or CompilationUnitSyntax | ||
or NamespaceDeclarationSyntax | ||
) | ||
) | ||
{ | ||
return false; | ||
} | ||
|
||
return syntaxNode | ||
.GetLeadingTrivia() | ||
.Any( | ||
o => | ||
o.Kind() is SyntaxKind.SingleLineCommentTrivia | ||
&& o.ToString().Equals("// csharpier-ignore") | ||
); | ||
} | ||
|
||
public static Doc PrintWithoutFormatting(SyntaxNode syntaxNode) | ||
{ | ||
return syntaxNode.GetText().ToString().Trim(); | ||
} | ||
} |