Skip to content
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

Renaming TabWidth to IndentSize #1425

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Src/CSharpier.Cli/Options/ConfigurationFileOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace CSharpier.Cli.Options;
internal class ConfigurationFileOptions
{
public int PrintWidth { get; init; } = 100;
public int TabWidth { get; init; } = 4;
public int IndentSize { get; init; } = 4;
public bool UseTabs { get; init; }

[JsonConverter(typeof(CaseInsensitiveEnumConverter<EndOfLine>))]
Expand All @@ -22,7 +22,7 @@ internal class ConfigurationFileOptions
{
return new PrinterOptions
{
IndentSize = matchingOverride.TabWidth,
IndentSize = matchingOverride.IndentSize,
UseTabs = matchingOverride.UseTabs,
Width = matchingOverride.PrintWidth,
EndOfLine = matchingOverride.EndOfLine,
Expand All @@ -34,7 +34,7 @@ internal class ConfigurationFileOptions
{
return new PrinterOptions
{
IndentSize = this.TabWidth,
IndentSize = this.IndentSize,
UseTabs = this.UseTabs,
Width = this.PrintWidth,
EndOfLine = this.EndOfLine,
Expand All @@ -59,7 +59,7 @@ internal class Override
private GlobMatcher? matcher;

public int PrintWidth { get; init; } = 100;
public int TabWidth { get; init; } = 4;
public int IndentSize { get; init; } = 4;
public bool UseTabs { get; init; }

[JsonConverter(typeof(CaseInsensitiveEnumConverter<EndOfLine>))]
Expand Down
8 changes: 4 additions & 4 deletions Src/CSharpier.Tests/Cli/Options/ConfigFileParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void Should_Parse_Yaml_With_Overrides()
overrides:
- files: "*.cst"
formatter: "csharp"
tabWidth: 2
indentSize: 2
useTabs: true
printWidth: 10
endOfLine: "LF"
Expand All @@ -25,7 +25,7 @@ public void Should_Parse_Yaml_With_Overrides()
options.Overrides.Should().HaveCount(1);
options.Overrides.First().Files.Should().Be("*.cst");
options.Overrides.First().Formatter.Should().Be("csharp");
options.Overrides.First().TabWidth.Should().Be(2);
options.Overrides.First().IndentSize.Should().Be(2);
options.Overrides.First().UseTabs.Should().Be(true);
options.Overrides.First().PrintWidth.Should().Be(10);
options.Overrides.First().EndOfLine.Should().Be(EndOfLine.LF);
Expand All @@ -41,7 +41,7 @@ public void Should_Parse_Json_With_Overrides()
{
"files": "*.cst",
"formatter": "csharp",
"tabWidth": 2,
"indentSize": 2,
"useTabs": true,
"printWidth": 10,
"endOfLine": "LF"
Expand All @@ -54,7 +54,7 @@ public void Should_Parse_Json_With_Overrides()
options.Overrides.Should().HaveCount(1);
options.Overrides.First().Files.Should().Be("*.cst");
options.Overrides.First().Formatter.Should().Be("csharp");
options.Overrides.First().TabWidth.Should().Be(2);
options.Overrides.First().IndentSize.Should().Be(2);
options.Overrides.First().UseTabs.Should().Be(true);
options.Overrides.First().PrintWidth.Should().Be(10);
options.Overrides.First().EndOfLine.Should().Be(EndOfLine.LF);
Expand Down
20 changes: 10 additions & 10 deletions Src/CSharpier.Tests/OptionsProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ public async Task Should_Return_PrintWidth_With_Json()
}

[Test]
public async Task Should_Return_TabWidth_With_Json()
public async Task Should_Return_IndentSize_With_Json()
{
var context = new TestContext();
context.WhenAFileExists("c:/test/.csharpierrc", "{ \"tabWidth\": 10 }");
context.WhenAFileExists("c:/test/.csharpierrc", "{ \"indentSize\": 10 }");

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

Expand Down Expand Up @@ -181,10 +181,10 @@ public async Task Should_Return_PrintWidth_With_Yaml()
}

[Test]
public async Task Should_Return_TabWidth_With_Yaml()
public async Task Should_Return_IndentSize_With_Yaml()
{
var context = new TestContext();
context.WhenAFileExists("c:/test/.csharpierrc", "tabWidth: 10");
context.WhenAFileExists("c:/test/.csharpierrc", "indentSize: 10");

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

Expand All @@ -203,7 +203,7 @@ public async Task Should_Return_UseTabs_With_Yaml()
}

[Test]
public async Task Should_Return_TabWidth_For_Override()
public async Task Should_Return_IndentSize_For_Override()
{
var context = new TestContext();
context.WhenAFileExists(
Expand All @@ -212,7 +212,7 @@ public async Task Should_Return_TabWidth_For_Override()
overrides:
- files: "*.cst"
formatter: "csharp"
tabWidth: 2
indentSize: 2
"""
);

Expand Down Expand Up @@ -576,7 +576,7 @@ public async Task Should_Prefer_CSharpierrc_In_SameFolder()
indent_size = 2
"
);
context.WhenAFileExists("c:/test/.csharpierrc", "tabWidth: 1");
context.WhenAFileExists("c:/test/.csharpierrc", "indentSize: 1");

var result = await context.CreateProviderAndGetOptionsFor(
"c:/test/subfolder",
Expand All @@ -596,7 +596,7 @@ public async Task Should_Not_Prefer_Closer_EditorConfig()
indent_size = 2
"
);
context.WhenAFileExists("c:/test/.csharpierrc", "tabWidth: 1");
context.WhenAFileExists("c:/test/.csharpierrc", "indentSize: 1");

var result = await context.CreateProviderAndGetOptionsFor(
"c:/test",
Expand Down Expand Up @@ -663,7 +663,7 @@ public async Task Should_Prefer_Closer_CSharpierrc()
indent_size = 2
"
);
context.WhenAFileExists("c:/test/subfolder/.csharpierrc", "tabWidth: 1");
context.WhenAFileExists("c:/test/subfolder/.csharpierrc", "indentSize: 1");

var result = await context.CreateProviderAndGetOptionsFor(
"c:/test",
Expand Down Expand Up @@ -702,7 +702,7 @@ public async Task Should_Not_Look_For_Subfolders_CSharpierRc_When_Limited()
"c:/test/subfolder/.csharpierrc",
@"
[*]
tabWidth: 1
indentSize: 1
"
);

Expand Down
44 changes: 5 additions & 39 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ JSON
{
"printWidth": 100,
"useTabs": false,
"tabWidth": 4,
"indentSize": 4,
"endOfLine": "auto"
}
```
YAML
```yaml
printWidth: 100
useTabs: false
tabWidth: 4
indentSize: 4
endOfLine: auto
```

Expand All @@ -33,20 +33,15 @@ Specify at what point the printer will wrap content. This is not a hard limit. S

Default `100`
#### Use Tabs
_First available in 0.17.0_

Indent lines with tabs instead of spaces.

Default `false`
#### Tab Width
_First available in 0.17.0_

#### Indent Size
Specify the number of spaces used per indentation level.

Default `4`

#### End of Line
_First available in 0.26.0_

Valid options:

Expand All @@ -56,32 +51,7 @@ Valid options:

Default `auto`


#### Preprocessor Symbol Sets
_Removed in 0.25.0_

Currently CSharpier only has basic support for understanding how to format code inside of `#if` directives.
It will attempt to determine which sets of preprocessor symbols are needed for roslyn to parse all the code in each file.

For example in the following code block, the following symbol sets would be needed ["FIRST", "SECOND,THIRD", ""]
```csharp
#if FIRST
// some code
#elif SECOND && THIRD
// some code
#else
// some code
#endif

```

When supplying symbol sets, they will be used for all files being formatted. This will slow down formatting, and determining all symbol sets needed across all files won't be straight forward.

The long term plan is to improve Csharpier's ability to determine the symbol sets itself and to allow specifying them for individual files.

### Configuration Overrides ###
_First available in 0.29.0_

Overrides allows you to specify different configuration options based on glob patterns. This can be used to format non-standard extensions, or to change options based on file path. Top level options will apply to `**/*.{cs,csx}`

```json
Expand All @@ -90,7 +60,7 @@ Overrides allows you to specify different configuration options based on glob pa
{
"files": ["*.cst"],
"formatter": "csharp",
"tabWidth": 2,
"indentSize": 2,
"useTabs": true,
"printWidth": 10,
"endOfLine": "LF"
Expand All @@ -103,15 +73,13 @@ Overrides allows you to specify different configuration options based on glob pa
overrides:
- files: "*.cst"
formatter: "csharp"
tabWidth: 2
indentSize: 2
useTabs: true
printWidth: 10
endOfLine: "LF"
```

### EditorConfig
_First available in 0.26.0_

CSharpier supports configuration via an `.editorconfig` file. A `.csharpierrc*` file in the same directory will take priority.

```ini
Expand All @@ -130,8 +98,6 @@ indent_size = 4
max_line_length = 100
```

_First available in 0.29.2_

Formatting non-standard file extensions using csharpier can be accomplished with the `csharpier_formatter` option
```ini
[*.cst]
Expand Down
Loading