Skip to content

Commit

Permalink
Read values from editorconfig with spaces (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
pisolofin authored Aug 25, 2024
1 parent 1c6b0c9 commit f829880
Show file tree
Hide file tree
Showing 33 changed files with 390 additions and 54 deletions.
3 changes: 1 addition & 2 deletions .github/Github.csproj
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<Project Sdk="Microsoft.Build.NoTargets/3.1.0">
</Project>
<Project Sdk="Microsoft.Build.NoTargets/3.1.0" />
2 changes: 1 addition & 1 deletion Nuget/Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>0.29.1.1</Version>
<Version>0.29.1.2</Version>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/pisolofin/csharpier-editorconfig</RepositoryUrl>
<RepositoryType>git</RepositoryType>
Expand Down
105 changes: 98 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,15 @@

This is as non opinionated version of [csharpier](https://github.com/belav/csharpier) version 0.29.1 tool created to add EditorConfig file style guide, allowing users to define and apply custom styling options.

I started implementing these options in a separate branch called [feature/brackets](https://github.com/pisolofin/csharpier-editorconfig/tree/feature/brackets).

**This is a work in progress project**

In this branch, I will set up the project with new references in the documentation, as well as handle the deployment and naming of the executable program.

All documentation that you find about csharpier is also valid for csharpier-config, you have only to change command like
All documentation you find about `CSharpier` is also valid for `CSharpier-Config`. You only need to adjust the commands accordingly.

- `dotnet csharpier` -> `dotnet csharpier-config`
- `dotnet-csharpier` -> `dotnet-csharpier-config`

**New feature**
## Extra rules than CSharpier

**CSharp formatting**

- Support to all [C# formatting options](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/csharp-formatting-options) into `.editorconfig` file

Expand All @@ -37,3 +33,98 @@ csharp_new_line_between_query_expression_clauses = true
```

For more information, please refer to the [documentation](/docs/Configuration.md)

*From*

```csharp
public class ClassName
{
private int _property = 0;
public int Property {
get
{
// Some logic
return _property;
}
set {
// Some logic
_property = value;
}
}

public void MethodName()
{
var anonymous = delegate(int param)
{
// Do something
return param;
};

int localFunction(int paramB) {
int def = paramB;
return def;
}

var condition = true;
if (condition)
{
// Do something
} else
{
// Do other
}

var localObject = new
{
Property = 1,
};
}
}
```

*To*
```csharp
public class ClassName
{
private int _property = 0;
public int Property
{
get {
// Some logic
return _property;
}
set {
// Some logic
_property = value;
}
}

public void MethodName()
{
var anonymous = delegate(int param) {
// Do something
return param;
};

int localFunction(int paramB) {
int def = paramB;
return def;
}

var condition = true;
if (condition)
{
// Do something
}
else
{
// Do other
}

var localObject = new {
Property = 1,
};
}
}

```
2 changes: 1 addition & 1 deletion Src/CSharpier.Cli/EditorConfig/EditorConfigSections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public static BraceNewLine ConvertToBraceNewLine(string input)
{
// Convert the string to a list of enum values
BraceNewLine result = BraceNewLine.None;
string[] values = input.Split(',');
string[] values = input.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);

foreach (var value in values)
{
Expand Down
11 changes: 11 additions & 0 deletions Src/CSharpier.Cli/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"profiles": {
"CSharpier.Cli": {
"commandName": "Project"
},
"Profile 1": {
"commandName": "Project",
"commandLineArgs": "C:\\Users\\Fabio\\source\\repos\\ConsoleApp1\\ConsoleApp1"
}
}
}
7 changes: 7 additions & 0 deletions Src/CSharpier.Tests/CSharpier.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
<Content Remove="FormattingTests\TestFiles\cs\NewLineBefore_OpenBrace_Methods_KeR.expected.test" />
<Content Remove="FormattingTests\TestFiles\cs\NewLineBefore_OpenBrace_ObjectCollectionArrayInitializers_KeR.expected.test" />
<Content Remove="FormattingTests\TestFiles\cs\NewLineBefore_OpenBrace_ObjectCollectionArrayInitializers_KeR_NoTrailingCommas.expected.test" />
<Content Remove="FormattingTests\TestFiles\cs\NewLineBefore_OpenBrace_Properties_Allman.actual.test" />
<Content Remove="FormattingTests\TestFiles\cs\NewLineBefore_OpenBrace_Properties_Allman.expected.test" />
<Content Remove="FormattingTests\TestFiles\cs\NewLineBefore_OpenBrace_Properties_KeR.expected.test" />
<Content Remove="FormattingTests\TestFiles\cs\NewLineBefore_OpenBrace_Types_KeR.expected.test" />
<Content Remove="FormattingTests\TestFiles\cs\NewLineBetween_QueryExpressionClauses_False.expected.test" />
Expand Down Expand Up @@ -133,6 +135,10 @@
<None Remove="FormattingTests\TestFiles\cs\NewLineBefore_OpenBrace_ObjectCollectionArrayInitializers_KeR_NoTrailingCommas.expected.test" />
<None Remove="FormattingTests\TestFiles\cs\NewLineBefore_OpenBrace_ObjectCollectionArrayInitializers_KeR_NoTrailingCommas.printerOptions.json" />
<None Remove="FormattingTests\TestFiles\cs\NewLineBefore_OpenBrace_ObjectCollectionArrayInitializers_KeR_NoTrailingCommas.test" />
<None Remove="FormattingTests\TestFiles\cs\NewLineBefore_OpenBrace_Properties_Allman.actual.test" />
<None Remove="FormattingTests\TestFiles\cs\NewLineBefore_OpenBrace_Properties_Allman.expected.test" />
<None Remove="FormattingTests\TestFiles\cs\NewLineBefore_OpenBrace_Properties_Allman.printerOptions.json" />
<None Remove="FormattingTests\TestFiles\cs\NewLineBefore_OpenBrace_Properties_Allman.test" />
<None Remove="FormattingTests\TestFiles\cs\NewLineBefore_OpenBrace_Properties_KeR.expected.test" />
<None Remove="FormattingTests\TestFiles\cs\NewLineBefore_OpenBrace_Properties_KeR.printerOptions.json" />
<None Remove="FormattingTests\TestFiles\cs\NewLineBefore_OpenBrace_Properties_KeR.test" />
Expand All @@ -158,6 +164,7 @@
<AdditionalFiles Include="FormattingTests\TestFiles\cs\NewLineBefore_MembersInAnonymousTypes_True.printerOptions.json" />
<AdditionalFiles Include="FormattingTests\TestFiles\cs\NewLineBefore_OpenBrace_AnonymousTypes_KeR_NoTrailingCommas.printerOptions.json" />
<AdditionalFiles Include="FormattingTests\TestFiles\cs\NewLineBefore_OpenBrace_ObjectCollectionArrayInitializers_KeR_NoTrailingCommas.printerOptions.json" />
<AdditionalFiles Include="FormattingTests\TestFiles\cs\NewLineBefore_OpenBrace_Properties_Allman.printerOptions.json" />
<AdditionalFiles Include="FormattingTests\TestFiles\cs\NewLineBetween_QueryExpressionClauses_Null.printerOptions.json" />
<AdditionalFiles Include="FormattingTests\TestFiles\cs\NewLineBetween_QueryExpressionClauses_False.printerOptions.json" />
<AdditionalFiles Include="FormattingTests\TestFiles\cs\NewLineBetween_QueryExpressionClauses_True.printerOptions.json" />
Expand Down
26 changes: 24 additions & 2 deletions Src/CSharpier.Tests/FormattingTests/BaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,31 @@ protected async Task RunTest(string fileName, string fileExtension, bool useTabs
new FileSystem(),
CancellationToken.None
);
printerOptions = System.Text.Json.JsonSerializer.Deserialize<PrinterOptions>(
var options = System.Text.Json.JsonSerializer.Deserialize<CSharpier.Cli.Options.Override>(
printerOptionsReaderResult.FileContents
)!;
);
options ??= new CSharpier.Cli.Options.Override
{
TabWidth = PrinterOptions.WidthUsedByTests,
UseTabs = useTabs,
};
printerOptions = new PrinterOptions
{
UseTabs = options.UseTabs,
IndentSize = options.TabWidth,
EndOfLine = options.EndOfLine,
Formatter = "csharp",

NewLineBeforeOpenBrace = options.NewLineBeforeOpenBrace,
NewLineBeforeElse = options.NewLineBeforeElse,
NewLineBeforeCatch = options.NewLineBeforeCatch,
NewLineBeforeFinally = options.NewLineBeforeFinally,
NewLineBeforeMembersInObjectInitializers =
options.NewLineBeforeMembersInObjectInitializers,
NewLineBeforeMembersInAnonymousTypes = options.NewLineBeforeMembersInAnonymousTypes,
NewLineBetweenQueryExpressionClauses = options.NewLineBetweenQueryExpressionClauses,
UsePrettierStyleTrailingCommas = options.UsePrettierStyleTrailingCommas,
};
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"NewLineBeforeOpenBrace": 65527,
"NewLineBeforeElse": true,
"NewLineBeforeCatch": false,
"NewLineBeforeFinally": true
"NewLineBeforeOpenBrace": "Accessors,AnonymousMethods,AnonymousTypes,Events,Indexers,Lambdas,LocalFunctions,Methods,ObjectCollectionArrayInitializers,Properties,Types",
"NewLineBeforeElse": true,
"NewLineBeforeCatch": false,
"NewLineBeforeFinally": true
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"NewLineBeforeOpenBrace": 65527,
"NewLineBeforeElse": false,
"NewLineBeforeCatch": true,
"NewLineBeforeFinally": true
"NewLineBeforeOpenBrace": "Accessors,AnonymousMethods,AnonymousTypes,Events,Indexers,Lambdas,LocalFunctions,Methods,ObjectCollectionArrayInitializers,Properties,Types",
"NewLineBeforeElse": false,
"NewLineBeforeCatch": true,
"NewLineBeforeFinally": true
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"NewLineBeforeOpenBrace": 65527,
"NewLineBeforeElse": true,
"NewLineBeforeCatch": true,
"NewLineBeforeFinally": false
"NewLineBeforeOpenBrace": "Accessors,AnonymousMethods,AnonymousTypes,Events,Indexers,Lambdas,LocalFunctions,Methods,ObjectCollectionArrayInitializers,Properties,Types",
"NewLineBeforeElse": true,
"NewLineBeforeCatch": true,
"NewLineBeforeFinally": false
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"NewLineBeforeOpenBrace": 65534
"NewLineBeforeOpenBrace": "AnonymousMethods,AnonymousTypes,ControlBlocks,Events,Indexers,Lambdas,LocalFunctions,Methods,ObjectCollectionArrayInitializers,Properties,Types"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"NewLineBeforeOpenBrace": 65533
"NewLineBeforeOpenBrace": "Accessors,AnonymousTypes,ControlBlocks,Events,Indexers,Lambdas,LocalFunctions,Methods,ObjectCollectionArrayInitializers,Properties,Types"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"NewLineBeforeOpenBrace": 65531
"NewLineBeforeOpenBrace": "Accessors,AnonymousMethods,ControlBlocks,Events,Indexers,Lambdas,LocalFunctions,Methods,ObjectCollectionArrayInitializers,Properties,Types"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"NewLineBeforeOpenBrace": 65531,
"NewLineBeforeOpenBrace": "Accessors,AnonymousMethods,ControlBlocks,Events,Indexers,Lambdas,LocalFunctions,Methods,ObjectCollectionArrayInitializers,Properties,Types",
"UsePrettierStyleTrailingCommas": false
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"NewLineBeforeOpenBrace": 65527
"NewLineBeforeOpenBrace": "Accessors,AnonymousMethods,AnonymousTypes,Events,Indexers,Lambdas,LocalFunctions,Methods,ObjectCollectionArrayInitializers,Properties,Types"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"NewLineBeforeOpenBrace": 65519
"NewLineBeforeOpenBrace": "Accessors,AnonymousMethods,AnonymousTypes,ControlBlocks,Indexers,Lambdas,LocalFunctions,Methods,ObjectCollectionArrayInitializers,Properties,Types"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"NewLineBeforeOpenBrace": 65503
"NewLineBeforeOpenBrace": "Accessors,AnonymousMethods,AnonymousTypes,ControlBlocks,Events,Lambdas,LocalFunctions,Methods,ObjectCollectionArrayInitializers,Properties,Types"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"NewLineBeforeOpenBrace": 65471
"NewLineBeforeOpenBrace": "Accessors,AnonymousMethods,AnonymousTypes,ControlBlocks,Events,Indexers,LocalFunctions,Methods,ObjectCollectionArrayInitializers,Properties,Types"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"NewLineBeforeOpenBrace": 65407
"NewLineBeforeOpenBrace": "Accessors,AnonymousMethods,AnonymousTypes,ControlBlocks,Events,Indexers,Lambdas,Methods,ObjectCollectionArrayInitializers,Properties,Types"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"NewLineBeforeOpenBrace": 65279
"NewLineBeforeOpenBrace": "Accessors,AnonymousMethods,AnonymousTypes,ControlBlocks,Events,Indexers,Lambdas,LocalFunctions,ObjectCollectionArrayInitializers,Properties,Types"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"NewLineBeforeOpenBrace": 65023
"NewLineBeforeOpenBrace": "Accessors,AnonymousMethods,AnonymousTypes,ControlBlocks,Events,Indexers,Lambdas,LocalFunctions,Methods,Properties,Types"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"NewLineBeforeOpenBrace": 65023,
"NewLineBeforeOpenBrace": "Accessors,AnonymousMethods,AnonymousTypes,ControlBlocks,Events,Indexers,Lambdas,LocalFunctions,Methods,Properties,Types",
"UsePrettierStyleTrailingCommas": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public class ClassName {
public int Property
{
get {
int abc = 0;
return 0;
}
set {
int abc = value;
int def = 0;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"NewLineBeforeOpenBrace": "Properties"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
public class ClassName
{
public int Property
{
get
{
int abc = 0;
return 0;
}

set {
int abc = value;
int def = 0;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"NewLineBeforeOpenBrace": 64511
"NewLineBeforeOpenBrace": "Accessors,AnonymousMethods,AnonymousTypes,ControlBlocks,Events,Indexers,Lambdas,LocalFunctions,Methods,ObjectCollectionArrayInitializers,Types"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"NewLineBeforeOpenBrace": 63487
"NewLineBeforeOpenBrace": "Accessors,AnonymousMethods,AnonymousTypes,ControlBlocks,Events,Indexers,Lambdas,LocalFunctions,Methods,ObjectCollectionArrayInitializers,Properties"
}
2 changes: 1 addition & 1 deletion Src/CSharpier.Tests/OptionsProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public async Task Should_Return_NewLineBeforeOpenBrace_With_Yaml()
var context = new TestContext();
context.WhenAFileExists(
"c:/test/.csharpierrc",
"newLineBeforeOpenBrace: accessors, AnonymousMethods"
"newLineBeforeOpenBrace: accessors,AnonymousMethods"
);

var result = await context.CreateProviderAndGetOptionsFor("c:/test", "c:/test/test.cs");
Expand Down
Loading

0 comments on commit f829880

Please sign in to comment.