Skip to content

Commit

Permalink
Using this everywhere (#562)
Browse files Browse the repository at this point in the history
  • Loading branch information
belav authored Jan 22, 2022
1 parent 66369b3 commit ce369b9
Show file tree
Hide file tree
Showing 26 changed files with 166 additions and 153 deletions.
10 changes: 7 additions & 3 deletions Src/CSharpier.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,24 @@ public class Benchmarks
[Benchmark]
public void Default_CodeFormatter()
{
CodeFormatter.Format(largeCode, new PrinterOptions());
CodeFormatter.Format(this.largeCode, new PrinterOptions());
}

[Benchmark]
public void Default_SyntaxNodeComparer()
{
var syntaxNodeComparer = new SyntaxNodeComparer(code, code, CancellationToken.None);
var syntaxNodeComparer = new SyntaxNodeComparer(
this.code,
this.code,
CancellationToken.None
);
syntaxNodeComparer.CompareSource();
}

[Benchmark]
public void IsCodeBasicallyEqual_SyntaxNodeComparer()
{
DisabledTextComparer.IsCodeBasicallyEqual(code, code);
DisabledTextComparer.IsCodeBasicallyEqual(this.code, this.code);
}

private readonly string largeCode = File.ReadAllText(
Expand Down
2 changes: 1 addition & 1 deletion Src/CSharpier.Cli/ConsoleLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void WriteLine(string? value = null)
}
}

if (!IsEnabled(logLevel))
if (!this.IsEnabled(logLevel))
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion Src/CSharpier.Generators/SyntaxNodeComparerGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void Initialize(GeneratorInitializationContext context) { }
// to switch and doesn't really change at this point
public void Execute(GeneratorExecutionContext context)
{
var sourceText = SourceText.From(GenerateSource(), Encoding.UTF8);
var sourceText = SourceText.From(this.GenerateSource(), Encoding.UTF8);

context.AddSource("SyntaxNodeComparer.generated", sourceText);
}
Expand Down
14 changes: 7 additions & 7 deletions Src/CSharpier.Generators/SyntaxNodeJsonWriterGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void Initialize(GeneratorInitializationContext context) { }
// to switch and doesn't really change at this point
public void Execute(GeneratorExecutionContext context)
{
var sourceText = SourceText.From(GenerateSource(), Encoding.UTF8);
var sourceText = SourceText.From(this.GenerateSource(), Encoding.UTF8);

context.AddSource("SyntaxNodeJsonWriter.generated", sourceText);
}
Expand Down Expand Up @@ -63,19 +63,19 @@ private string GenerateSource()

foreach (var syntaxNodeType in syntaxNodeTypes)
{
GenerateMethod(sourceBuilder, syntaxNodeType);
this.GenerateMethod(sourceBuilder, syntaxNodeType);
}

GenerateMethod(sourceBuilder, typeof(SyntaxToken));
GenerateMethod(sourceBuilder, typeof(SyntaxTrivia));
this.GenerateMethod(sourceBuilder, typeof(SyntaxToken));
this.GenerateMethod(sourceBuilder, typeof(SyntaxTrivia));

sourceBuilder.AppendLine(" }");
sourceBuilder.AppendLine("}");

if (missingTypes.Any())
if (this.missingTypes.Any())
{
throw new Exception(
Environment.NewLine + string.Join(Environment.NewLine, missingTypes)
Environment.NewLine + string.Join(Environment.NewLine, this.missingTypes)
);
}

Expand Down Expand Up @@ -224,7 +224,7 @@ private void GenerateMethod(StringBuilder sourceBuilder, Type type)
}
else
{
missingTypes.Add(
this.missingTypes.Add(
PadToSize(type.Name + "." + propertyName + ": ", 40) + propertyType
);
}
Expand Down
8 changes: 4 additions & 4 deletions Src/CSharpier.Generators/TemplatedGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ public void Initialize(GeneratorInitializationContext context) { }

public void Execute(GeneratorExecutionContext context)
{
var template = Template.Parse(GetContent(GetType().Name + ".sbntxt"));
var renderedSource = template.Render(GetModel(context), member => member.Name);
var template = Template.Parse(this.GetContent(this.GetType().Name + ".sbntxt"));
var renderedSource = template.Render(this.GetModel(context), member => member.Name);

var sourceText = SourceText.From(renderedSource, Encoding.UTF8);

context.AddSource(SourceName, sourceText);
context.AddSource(this.SourceName, sourceText);
}

protected abstract object GetModel(GeneratorExecutionContext context);

public string GetContent(string relativePath)
{
var assembly = GetType().Assembly;
var assembly = this.GetType().Assembly;
var baseName = assembly.GetName().Name;
var resourceName = relativePath
.TrimStart('.')
Expand Down
2 changes: 1 addition & 1 deletion Src/CSharpier.Playground/Controllers/FormatController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public FormatResult Post([FromBody] string content)
Code = result.Code,
Json = result.AST,
Doc = result.DocTree,
Errors = result.Errors.Select(ConvertError).ToList(),
Errors = result.Errors.Select(this.ConvertError).ToList(),
};
}

Expand Down
6 changes: 3 additions & 3 deletions Src/CSharpier.Playground/Pages/Error.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ public class ErrorModel : PageModel

public ErrorModel(ILogger<ErrorModel> logger)
{
_logger = logger;
this._logger = logger;
}

public string RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
public bool ShowRequestId => !string.IsNullOrEmpty(this.RequestId);

public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
this.RequestId = Activity.Current?.Id ?? this.HttpContext.TraceIdentifier;
}
}
2 changes: 1 addition & 1 deletion Src/CSharpier.Playground/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
this.Configuration = configuration;
}

public IConfiguration Configuration { get; }
Expand Down
2 changes: 1 addition & 1 deletion Src/CSharpier.Tests/ConfigurationFileOptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private class TestContext
public ConfigurationFileOptions CreateConfigurationOptions(string baseDirectoryPath)
{
this.fileSystem.AddDirectory(baseDirectoryPath);
return ConfigurationFileOptions.Create(baseDirectoryPath, fileSystem);
return ConfigurationFileOptions.Create(baseDirectoryPath, this.fileSystem);
}

public void WhenAFileExists(string path, string contents)
Expand Down
2 changes: 1 addition & 1 deletion Src/CSharpier.Tests/DeepRecursionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class DeepRecursionTests
[Test]
public void Format_Should_Return_Error_For_Deep_Recursion()
{
var code = uglyLongConcatenatedString;
var code = this.uglyLongConcatenatedString;
var result = CodeFormatter.Format(code, new PrinterOptions());

result.FailureMessage.Should().Be("We can't handle this deep of recursion yet.");
Expand Down
8 changes: 5 additions & 3 deletions Src/CSharpier.Tests/DocPrinterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace CSharpier.Tests;
[Parallelizable(ParallelScope.All)]
public class DocPrinterTests
{
private static readonly string NewLine = System.Environment.NewLine;
private static readonly string NewLine = Environment.NewLine;

[Test]
public void Lines_Allowed()
Expand Down Expand Up @@ -203,7 +203,7 @@ public void Long_Statement_With_Line_Should_Not_Break_Unrelated_Group()
{
var doc = Doc.Concat(
"1",
Doc.Group(Doc.Line, ActualConcat("2")),
Doc.Group(Doc.Line, this.ActualConcat("2")),
Doc.HardLine,
Doc.Concat(
"1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
Expand Down Expand Up @@ -457,7 +457,9 @@ public void HardLineIfNoPreviousLine_Does_Not_Blow_Up()
[Test]
public void HardLineIfNoPreviousLine_Should_Not_Insert_After_Indented_HardLine()
{
var doc = ActualConcat(Doc.Indent("1", Doc.HardLine, Doc.HardLineIfNoPreviousLine, "2"));
var doc = this.ActualConcat(
Doc.Indent("1", Doc.HardLine, Doc.HardLineIfNoPreviousLine, "2")
);

PrintedDocShouldBe(doc, $"1{NewLine} 2");
}
Expand Down
26 changes: 13 additions & 13 deletions Src/CSharpier.Tests/DocUtilitiesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void RemoveInitialDoubleHardLine_Should_Remove_Simple_Double_HardLine()
[Test]
public void RemoveInitialDoubleHardLine_Should_Not_Remove_Concated_HardLine()
{
var concat = ActualConcat(Doc.HardLine);
var concat = this.ActualConcat(Doc.HardLine);
var doc = new List<Doc> { concat };

DocUtilities.RemoveInitialDoubleHardLine(doc);
Expand All @@ -54,19 +54,19 @@ public void RemoveInitialDoubleHardLine_Should_Not_Remove_Concated_HardLine()
[Test]
public void RemoveInitialDoubleHardLine_Should_Remove_Concated_HardLine()
{
var concat = ActualConcat(Doc.HardLine, Doc.HardLine);
var concat = this.ActualConcat(Doc.HardLine, Doc.HardLine);
var doc = new List<Doc> { concat };

DocUtilities.RemoveInitialDoubleHardLine(doc);

concat.Should().BeEquivalentTo(ActualConcat(Doc.HardLine, Doc.Null));
concat.Should().BeEquivalentTo(this.ActualConcat(Doc.HardLine, Doc.Null));
}

[Test]
public void RemoveInitialDoubleHardLine_Should_Not_Remove_Deep_Concated_HardLine()
{
var concat = ActualConcat(Doc.HardLine);
var doc = new List<Doc> { ActualConcat(concat) };
var concat = this.ActualConcat(Doc.HardLine);
var doc = new List<Doc> { this.ActualConcat(concat) };

DocUtilities.RemoveInitialDoubleHardLine(doc);

Expand All @@ -76,8 +76,8 @@ public void RemoveInitialDoubleHardLine_Should_Not_Remove_Deep_Concated_HardLine
[Test]
public void RemoveInitialDoubleHardLine_Should_Remove_Deep_Concated_HardLine()
{
var concat = ActualConcat(Doc.HardLine, Doc.HardLine);
var doc = new List<Doc> { ActualConcat(concat) };
var concat = this.ActualConcat(Doc.HardLine, Doc.HardLine);
var doc = new List<Doc> { this.ActualConcat(concat) };

DocUtilities.RemoveInitialDoubleHardLine(doc);

Expand All @@ -87,8 +87,8 @@ public void RemoveInitialDoubleHardLine_Should_Remove_Deep_Concated_HardLine()
[Test]
public void RemoveInitialDoubleHardLine_Should_Remove_Single_HardLine()
{
var concat = ActualConcat(Doc.HardLine, Doc.HardLine, Doc.HardLine);
var doc = new List<Doc> { ActualConcat(concat) };
var concat = this.ActualConcat(Doc.HardLine, Doc.HardLine, Doc.HardLine);
var doc = new List<Doc> { this.ActualConcat(concat) };

DocUtilities.RemoveInitialDoubleHardLine(doc);

Expand Down Expand Up @@ -144,17 +144,17 @@ public void RemoveInitialDoubleHardLine_Should_Remove_Grouped_Double_HardLine()
[Test]
public void RemoveInitialDoubleHardLine_Should_Only_Remove_Initial_HardLines()
{
var doc = ActualConcat("1", Doc.HardLine, Doc.HardLine);
var doc = this.ActualConcat("1", Doc.HardLine, Doc.HardLine);

DocUtilities.RemoveInitialDoubleHardLine(doc);

doc.Should().BeEquivalentTo(ActualConcat("1", Doc.HardLine, Doc.HardLine));
doc.Should().BeEquivalentTo(this.ActualConcat("1", Doc.HardLine, Doc.HardLine));
}

[Test]
public void RemoveInitialDoubleHardLine_Work_With_Doc_Null_Before_String()
{
var doc = ActualConcat(Doc.HardLine, Doc.Null, "1", Doc.HardLine, "2");
var doc = this.ActualConcat(Doc.HardLine, Doc.Null, "1", Doc.HardLine, "2");

DocUtilities.RemoveInitialDoubleHardLine(doc);

Expand All @@ -163,7 +163,7 @@ public void RemoveInitialDoubleHardLine_Work_With_Doc_Null_Before_String()
.Should()
.Be(
DocSerializer.Serialize(
ActualConcat(Doc.HardLine, Doc.Null, "1", Doc.HardLine, "2")
this.ActualConcat(Doc.HardLine, Doc.Null, "1", Doc.HardLine, "2")
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion Src/CSharpier.Tests/MissingTypeChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void Ensure_There_Are_No_Missing_Types()
continue;
}

if (ignored.Contains(nodeType.Name))
if (this.ignored.Contains(nodeType.Name))
{
continue;
}
Expand Down
5 changes: 2 additions & 3 deletions Src/CSharpier.Tests/SyntaxPrinter/PreprocessorSymbolsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ public void AddSymbolSet_For_Basic_Elif_Adds_Symbol()

private static string[] AddSymbolSet(ConditionalDirectiveTriviaSyntax trivia)
{
TestablePreprocessorSymbols.Reset();
PreprocessorSymbols.Reset();

TestablePreprocessorSymbols.AddSymbolSet(trivia);

return TestablePreprocessorSymbols.GetSymbolSets().FirstOrDefault()
?? Array.Empty<string>();
return PreprocessorSymbols.GetSymbolSets().FirstOrDefault() ?? Array.Empty<string>();
}

private static IfDirectiveTriviaSyntax WhenIfDirectiveHasCondition(string condition)
Expand Down
Loading

0 comments on commit ce369b9

Please sign in to comment.