GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Enable IDE0048: AddRequiredParentheses by xtqqczze · Pull Request #13936 · PowerShell/PowerShell

Conversation

@xtqqczze

@xtqqczze xtqqczze commented Oct 29, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0047-ide0048

Follow-up to #13896, after EnforceCodeStyleInBuild was enabled in #13957.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ghost ghost assigned Andrew (anmenaga) Oct 29, 2020
@xtqqczze xtqqczze mentioned this pull request Oct 29, 2020
Enable IDE0048: AddRequiredParentheses #13896
Merged
@xtqqczze
xtqqczze force-pushed the IDE0048-p2 branch from b921a72 to 3d4461b Compare October 29, 2020 23:02
@xtqqczze
xtqqczze marked this pull request as ready for review October 30, 2020 01:13
@xtqqczze
xtqqczze requested review from Steve Lee (SteveL-MSFT), Travis Plunk (TravisEz13), Aditya Patwardhan (adityapatwardhan), Andrew (anmenaga) and Dongbo Wang (daxian-dbw) as code owners October 30, 2020 01:13
@xtqqczze xtqqczze mentioned this pull request Oct 31, 2020
Enforce code style in build #13957
Merged
@xtqqczze
xtqqczze force-pushed the IDE0048-p2 branch from 3d4461b to c6e6100 Compare October 31, 2020 17:46
@xtqqczze xtqqczze changed the title Apply IDE0048: AddRequiredParentheses WIP: Enable IDE0048: AddRequiredParentheses p2 Oct 31, 2020
@xtqqczze
xtqqczze marked this pull request as draft October 31, 2020 17:47
@xtqqczze
xtqqczze force-pushed the IDE0048-p2 branch from c6e6100 to bc0aa52 Compare November 1, 2020 18:08
@xtqqczze xtqqczze changed the title WIP: Enable IDE0048: AddRequiredParentheses p2 Enable IDE0048: AddRequiredParentheses p2 Nov 1, 2020
@xtqqczze
xtqqczze marked this pull request as ready for review November 1, 2020 19:51
@xtqqczze xtqqczze changed the title Enable IDE0048: AddRequiredParentheses p2 Enable IDE0048: AddRequiredParentheses Nov 2, 2020
iSazonov
Ilya (iSazonov) reviewed Nov 2, 2020
View reviewed changes
Comment thread src/System.Management.Automation/engine/hostifaces/LocalConnection.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

iSazonov
Ilya (iSazonov) reviewed Nov 2, 2020
View reviewed changes

@iSazonov Ilya (iSazonov) left a comment

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rule is contradictory: parentheses are good for complex expressions to eliminate errors, but no doubt they are superfluous for simple expressions where they worsen readability.

I think it is better to set "suggestion" for the rule.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@xtqqczze

xtqqczze commented Nov 2, 2020

Copy link
Copy Markdown
Contributor Author

Ilya (@iSazonov) Could you leave more review comments to give examples of where readability has been worsened?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

iSazonov
Ilya (iSazonov) reviewed Nov 2, 2020
View reviewed changes
Comment thread src/Microsoft.PowerShell.Commands.Management/commands/management/GetComputerInfoCommand.cs Outdated
Comment on lines 1162 to 1165

@iSazonov Ilya (iSazonov) Nov 2, 2020

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Less readability.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@xtqqczze xtqqczze Nov 2, 2020

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For most people it is obvious that multiplication has a higher precedence than addition, so the parenthesis are probably not necessary. However while readability might not be any better, it is not really any worse.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@xtqqczze xtqqczze Nov 2, 2020

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiplicative > Additive

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs Outdated

@iSazonov Ilya (iSazonov) Nov 2, 2020

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Less readability.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@xtqqczze xtqqczze Nov 2, 2020

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiplicative > Additive

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs Outdated

@iSazonov Ilya (iSazonov) Nov 2, 2020

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Less readability.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@xtqqczze xtqqczze Nov 2, 2020

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiplicative > Additive

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetRandomCommand.cs Outdated

@iSazonov Ilya (iSazonov) Nov 2, 2020

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Less readability.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@xtqqczze xtqqczze Nov 2, 2020

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiplicative > Additive

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/Microsoft.PowerShell.Commands.Utility/commands/utility/Set-PSBreakpoint.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs Outdated
Comment on lines 2009 to 2010

@iSazonov Ilya (iSazonov) Nov 2, 2020

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Less readability.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@xtqqczze xtqqczze Nov 2, 2020

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiplicative > Additive

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs Outdated

@iSazonov Ilya (iSazonov) Nov 2, 2020

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd wonder if anybody wanted parentheses in such expressions.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@xtqqczze xtqqczze Nov 2, 2020

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiplicative > Additive

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/System.Management.Automation/FormatAndOutput/common/OutputQueue.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@xtqqczze

xtqqczze commented Nov 2, 2020

Copy link
Copy Markdown
Contributor Author

Ilya (@iSazonov) It seems all your examples of worsened readability are for the higher precedence of multiplicative vs additive operators.

Unfortunately the analyzer does not provide configuration at this level, the closest option is dotnet_style_parentheses_in_arithmetic_binary_operators covering *, /, %, +, -, <<, >>, &, ^, |

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov

Ilya (iSazonov) commented Nov 2, 2020

Copy link
Copy Markdown
Collaborator

This is a controversial rule that depends on context. For simple expressions, no additional parentheses are needed. For complex expressions, good formatting and descriptive names are more important. I suppose we can turn this off at all.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@xtqqczze

xtqqczze commented Nov 2, 2020

Copy link
Copy Markdown
Contributor Author

I suppose we can turn this off at all.

OK so we use a lesser severity, suggestion or hidden?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

xtqqczze added 3 commits November 2, 2020 10:52
@xtqqczze
Enable IDE0048: AddRequiredParentheses
a779b1c
https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0047-ide0048
@xtqqczze
fixup! Enable IDE0048: AddRequiredParentheses
a3f49ea
@xtqqczze
Reduce severity to suggestion
c3dd439
@xtqqczze
xtqqczze force-pushed the IDE0048-p2 branch from 1a6853d to c3dd439 Compare November 2, 2020 10:55
@iSazonov

Ilya (iSazonov) commented Nov 2, 2020

Copy link
Copy Markdown
Collaborator

OK so we use a lesser severity, suggestion or hidden?

Is there Quick fix in VS Code? If yes, I agree with "suggestion", otherwise it is better to hide.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov

Ilya (iSazonov) commented Nov 5, 2020

Copy link
Copy Markdown
Collaborator

xtqqczze I close the PR since it is controversial. I suggest these rules to "suggestion" in new PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov Ilya (iSazonov) closed this Nov 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@iSazonov Ilya (iSazonov) iSazonov left review comments
@adityapatwardhan Aditya Patwardhan (adityapatwardhan) Awaiting requested review from adityapatwardhan
@anmenaga Andrew (anmenaga) Awaiting requested review from anmenaga
@daxian-dbw Dongbo Wang (daxian-dbw) Awaiting requested review from daxian-dbw daxian-dbw is a code owner
@SteveL-MSFT Steve Lee (SteveL-MSFT) Awaiting requested review from SteveL-MSFT
@TravisEz13 Travis Plunk (TravisEz13) Awaiting requested review from TravisEz13 TravisEz13 is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@anmenaga Andrew (anmenaga)

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@xtqqczze @iSazonov @anmenaga
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.