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

Add codestyle to handle unnecessary parentheses. #21316

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
df70a58
Add codestyle to handle unnecessary parentheses
CyrusNajmabadi Mar 12, 2018
3921ce3
Loc files.
CyrusNajmabadi Mar 12, 2018
02e2392
Add test helpers.
CyrusNajmabadi Mar 13, 2018
b77e3f2
Add tests.
CyrusNajmabadi Mar 13, 2018
fe91acc
Remove unused names.
CyrusNajmabadi Mar 13, 2018
b361289
Fix spelling.
CyrusNajmabadi Mar 13, 2018
35fba3c
Add tests.
CyrusNajmabadi Mar 13, 2018
747879a
Fix spelling.
CyrusNajmabadi Mar 13, 2018
594371b
Make static.
CyrusNajmabadi Mar 13, 2018
e628d29
Removed.
CyrusNajmabadi Mar 13, 2018
e26f2fb
Remove unnecessary named param.
CyrusNajmabadi Mar 13, 2018
d48df8d
Directly return.
CyrusNajmabadi Mar 13, 2018
2e243b3
Fix spelling.
CyrusNajmabadi Mar 13, 2018
dab7241
Add named params.
CyrusNajmabadi Mar 13, 2018
3c344ea
Remove blank line.
CyrusNajmabadi Mar 13, 2018
2ee48d1
Simplifier annotation.
CyrusNajmabadi Mar 13, 2018
1fbf8e4
Remove duplication.
CyrusNajmabadi Mar 13, 2018
cbab230
Simplify.
CyrusNajmabadi Mar 13, 2018
0c1149d
Remove unused methods.
CyrusNajmabadi Mar 13, 2018
066eea4
Check all symbols.
CyrusNajmabadi Mar 13, 2018
6b20b14
Remove blank line.
CyrusNajmabadi Mar 13, 2018
e91c1b2
Fix indentation.
CyrusNajmabadi Mar 13, 2018
145dcc4
Merge remote-tracking branch 'upstream/master' into removeUnnecessary…
CyrusNajmabadi Mar 13, 2018
bf83598
Merge remote-tracking branch 'upstream/master' into removeUnnecessary…
CyrusNajmabadi Mar 17, 2018
7b7c615
Add tests.
CyrusNajmabadi Mar 17, 2018
4e8a97c
Fix simple cases.
CyrusNajmabadi Mar 17, 2018
d800c39
Remove parentheses in a few more safe cases.
CyrusNajmabadi Mar 17, 2018
9a5475d
Handle case patterns as well.
CyrusNajmabadi Mar 17, 2018
e20ad3b
Support assignment operators
CyrusNajmabadi Mar 18, 2018
e1e4358
Add tests.
CyrusNajmabadi Mar 18, 2018
109cc12
Fix issue where we might simplify a parenthesized cast innapropriately.
CyrusNajmabadi Mar 19, 2018
1f95742
Spelling.
CyrusNajmabadi Mar 19, 2018
4e6268d
Remove redundant test.
CyrusNajmabadi Mar 19, 2018
f9759ed
Add support for clarifying parentheses for casts.
CyrusNajmabadi Mar 19, 2018
b37bfeb
Fixup resource strings.
CyrusNajmabadi Mar 19, 2018
8bb5826
Add and update tests.
CyrusNajmabadi Mar 19, 2018
56eb0e7
Rename files.
CyrusNajmabadi Mar 19, 2018
dba65f6
Add tests
CyrusNajmabadi Mar 19, 2018
c43df06
Properly generate negative constant literals.
CyrusNajmabadi Mar 19, 2018
18bd156
Merge branch 'removeUnnecessaryParentheses' into castParens2
CyrusNajmabadi Mar 19, 2018
243f8d7
Port changes over to VB.
CyrusNajmabadi Mar 19, 2018
51260e7
Merge branch 'removeUnnecessaryParentheses' into castParens2
CyrusNajmabadi Mar 19, 2018
166fb47
Update resource strings.
CyrusNajmabadi Mar 19, 2018
7f1ff6f
Merge remote-tracking branch 'upstream/master' into removeUnnecessary…
CyrusNajmabadi Mar 19, 2018
1ee1d4d
use utility.
CyrusNajmabadi Mar 19, 2018
48a1ad7
Swap tests.
CyrusNajmabadi Mar 19, 2018
31dd306
restore indentation.
CyrusNajmabadi Mar 19, 2018
8d6c054
Update option name.
CyrusNajmabadi Mar 19, 2018
be6c7aa
Rename file.
CyrusNajmabadi Mar 19, 2018
6b75d79
Add unnecessary constructor.
CyrusNajmabadi Mar 19, 2018
3323460
Remove method.
CyrusNajmabadi Mar 19, 2018
bd59a30
Add serialization for all options.
CyrusNajmabadi Mar 19, 2018
4ce81b3
Fix tests.
CyrusNajmabadi Mar 19, 2018
2bb7f6f
Merge remote-tracking branch 'upstream/master' into removeUnnecessary…
CyrusNajmabadi Mar 26, 2018
7d90d3f
Indent switches.
CyrusNajmabadi Mar 27, 2018
872f891
Merge remote-tracking branch 'upstream/master' into removeUnnecessary…
CyrusNajmabadi Mar 28, 2018
0bf0aa5
Parentheses work.
CyrusNajmabadi Mar 29, 2018
c729c9a
Update UI.
CyrusNajmabadi Mar 29, 2018
b6d7ef7
Design changes.
CyrusNajmabadi Mar 29, 2018
907bc49
Merge remote-tracking branch 'upstream/master' into removeUnnecessary…
CyrusNajmabadi Apr 4, 2018
09ab977
Merge remote-tracking branch 'upstream/master' into removeUnnecessary…
CyrusNajmabadi Apr 5, 2018
629f588
Merge remote-tracking branch 'upstream/master' into removeUnnecessary…
CyrusNajmabadi Apr 7, 2018
f203346
Merge branch 'master' into removeUnnecessaryParentheses
CyrusNajmabadi Apr 17, 2018
98b0b59
Merge branch 'master' into removeUnnecessaryParentheses
CyrusNajmabadi Apr 19, 2018
bed3b30
Merge branch 'master' into removeUnnecessaryParentheses
CyrusNajmabadi Apr 19, 2018
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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.AddRequiredParentheses;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CSharp.AddRequiredParentheses;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Diagnostics;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Test.Utilities;
using Xunit;

namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.AddRequiredParentheses
{
public partial class AddRequiredParenthesesForCastExpressionTests : AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest
{
internal override (DiagnosticAnalyzer, CodeFixProvider) CreateDiagnosticProviderAndFixer(Workspace workspace)
=> (new CSharpAddRequiredParenthesesForCastExpressionDiagnosticAnalyzer(), new AddRequiredParenthesesCodeFixProvider());

private Task TestMissingAsync(string initialMarkup, IDictionary<OptionKey, object> options)
=> TestMissingInRegularAndScriptAsync(initialMarkup, new TestParameters(options: options));

private Task TestAsync(string initialMarkup, string expected, IDictionary<OptionKey, object> options)
=> TestInRegularAndScript1Async(initialMarkup, expected, parameters: new TestParameters(options: options));

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddRequiredParentheses)]
public async Task TestUnclearCast1()
{
await TestAsync(
@"class C
{
void M()
{
int x = (int)$$-y;
}
}",
@"class C
{
void M()
{
int x = (int)(-y);
}
}", RequireAllParenthesesForClarity);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddRequiredParentheses)]
public async Task TestUnclearCast_NotOfferedWithIgnore()
{
await TestMissingAsync(
@"class C
{
void M()
{
int x = (int)$$-y;
}
}", IgnoreAllParentheses);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddRequiredParentheses)]
public async Task TestUnclearCast_NotOfferedWithRemoveForClarity()
{
await TestMissingAsync(
@"class C
{
void M()
{
int x = (int)$$-y;
}
}", RemoveAllUnnecessaryParentheses);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddRequiredParentheses)]
public async Task TestUnclearCast2()
{
await TestAsync(
@"class C
{
void M()
{
int x = (int)$$+y;
}
}",
@"class C
{
void M()
{
int x = (int)(+y);
}
}", RequireAllParenthesesForClarity);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddRequiredParentheses)]
public async Task TestUnclearCast3()
{
await TestAsync(
@"class C
{
void M()
{
int x = (int)$$&y;
}
}",
@"class C
{
void M()
{
int x = (int)(&y);
}
}", RequireAllParenthesesForClarity);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddRequiredParentheses)]
public async Task TestUnclearCast4()
{
await TestAsync(
@"class C
{
void M()
{
int x = (int)$$*y;
}
}",
@"class C
{
void M()
{
int x = (int)(*y);
}
}", RequireAllParenthesesForClarity);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddRequiredParentheses)]
public async Task TestNotForPrimary()
{
await TestMissingAsync(
@"class C
{
void M()
{
int x = (int)$$y;
}
}", RequireAllParenthesesForClarity);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddRequiredParentheses)]
public async Task TestNotForMemberAccess()
{
await TestMissingAsync(
@"class C
{
void M()
{
int x = (int)$$y.z;
}
}", RequireAllParenthesesForClarity);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddRequiredParentheses)]
public async Task TestNotForCastOfCast()
{
await TestMissingAsync(
@"class C
{
void M()
{
int x = (int)$$(y);
}
}", RequireAllParenthesesForClarity);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddRequiredParentheses)]
public async Task TestNotForNonAmbiguousUnary()
{
await TestMissingAsync(
@"class C
{
void M()
{
int x = (int)$$!y;
}
}", RequireAllParenthesesForClarity);
}
}
}
Loading