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

Update SA1010 to not trigger on list patterns #3507

Merged
merged 1 commit into from
Apr 25, 2023

Conversation

bjornhellander
Copy link
Contributor

Fixes #3503

@codecov
Copy link

codecov bot commented May 14, 2022

Codecov Report

Merging #3507 (e852d1f) into master (ccaac20) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head e852d1f differs from pull request most recent head 94243e6. Consider uploading reports for the commit 94243e6 to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3507   +/-   ##
=======================================
  Coverage   93.26%   93.26%           
=======================================
  Files        1079     1080    +1     
  Lines      113737   113762   +25     
  Branches     4027     4028    +1     
=======================================
+ Hits       106072   106097   +25     
  Misses       6630     6630           
  Partials     1035     1035           

Comment on lines 32 to 38
_ = x is [1];
_ = x is not [1];
_ = x is ([1] or [2]);
_ = x is ([1] or not [2]);
_ = x is ([1] and [1]);
_ = x is ([1] and not [2]);
Copy link
Member

Choose a reason for hiding this comment

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

💡 This should be converted to a code fix test, which includes examples of various incorrect formatting that is then corrected (there is no need to separately test valid syntax, since all code fix tests automatically verify that the fixed code contains no undeclared diagnostics).

Copy link
Contributor Author

@bjornhellander bjornhellander May 16, 2022

Choose a reason for hiding this comment

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

This specific analyzer only suggests to remove spaces now, never to add them. I filed #3508 a couple of days ago to update SA1000/SA1003 to get a diagnostic where a space is missing, but that might be a mistake. Not sure.

Copy link
Member

@sharwell sharwell May 19, 2022

Choose a reason for hiding this comment

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

Interesting. Based on other analyzers (e.g. { used in property patterns), SA1010 would be the analyzer that wants to add the space here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since this seems to be in line with the current implementation, would it be ok to merge this if I create another issue to investigate the resposibility of this analyzer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you want to do, @sharwell?

Copy link
Member

@sharwell sharwell Dec 5, 2022

Choose a reason for hiding this comment

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

💭 Is this analyzer not responsible for reporting a this?

x is ( [1]);
       ^

In #3511 a very similar scenario does report a diagnostic.

Copy link
Contributor Author

@bjornhellander bjornhellander Dec 8, 2022

Choose a reason for hiding this comment

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

The only diagnostic I would like to see in that example is SA1008. I am thinking that the list pattern's opening bracket itself should not trigger any opinion about preceding space, anymore than a literal value does. It is always something else that is causing the opinion, like a preceding open parenthesis, operator, keyword, etc. Before this PR, your example would trigger both SA1008 and SA1010. Is that a behaviour that you would like to keep? I could very well not be seeing the whole picture here, but I feel that not having an opinion at all is the correct behaviour for this rule in this specific case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually feel the same way about the property pattern changes made in SA1012, now that I think of it. I assume that both these statements will trigger two diagnostics:

_ = x is ( { P: 0 }, { P: 0 }) // SA1008 and SA1012
_ = x is [ { P: 0 }, { P: 0 }] // SA1010 and SA1012

With my thinking, only SA1008 and SA1010 should be triggered.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Returning to SA1010 again, there was already a similar case implemented where this code only triggers SA1012 and not SA1010:
var test = new Dictionary<ulong, string>() {[100] = "100" };

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bjornhellander bjornhellander force-pushed the feature/listpattern branch 2 times, most recently from 76772c8 to 7e25f23 Compare May 16, 2022 18:04
@jnm2
Copy link
Contributor

jnm2 commented May 17, 2022

Would you be interested in fixing #3509 at the same time?

@bjornhellander
Copy link
Contributor Author

I rebased this since it was getting old and turned the test into a theory to make it easier to debug

@sharwell sharwell merged commit 1c7f5f3 into DotNetAnalyzers:master Apr 25, 2023
@sharwell sharwell added this to the 1.2-beta.next milestone Apr 25, 2023
@bjornhellander
Copy link
Contributor Author

Thanks!

@bjornhellander bjornhellander deleted the feature/listpattern branch April 25, 2023 14:48
ThorstenSauter added a commit to ThorstenSauter/NoPlan that referenced this pull request Jun 22, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
|
[StyleCop.Analyzers](https://github.com/DotNetAnalyzers/StyleCopAnalyzers)
| nuget | patch | `1.2.0-beta.435` -> `1.2.0-beta.507` |

---

### Release Notes

<details>
<summary>DotNetAnalyzers/StyleCopAnalyzers</summary>

###
[`v1.2.0-beta.507`](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/releases/tag/1.2.0-beta.507)

[Compare
Source](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/compare/1.2.0-beta.435...1.2.0-beta.507)

#### What's Changed

- Update to StyleCop.Analyzers 1.2.0-beta.435 by
[@&#8203;sharwell](https://github.com/sharwell) in
[DotNetAnalyzers/StyleCopAnalyzers#3499
- Add c# 11 test project to opencover-report.ps1 by
[@&#8203;bjornhellander](https://github.com/bjornhellander) in
[DotNetAnalyzers/StyleCopAnalyzers#3506
- Use GetText instead of ToFullString by
[@&#8203;sharwell](https://github.com/sharwell) in
[DotNetAnalyzers/StyleCopAnalyzers#3514
- Keep tracked nodes in a list by
[@&#8203;sharwell](https://github.com/sharwell) in
[DotNetAnalyzers/StyleCopAnalyzers#3525
- Remove unnecessary nullable directives by
[@&#8203;sharwell](https://github.com/sharwell) in
[DotNetAnalyzers/StyleCopAnalyzers#3530
- Remove hard-coded language versions in test projects for c# 8, 9 and
10 by [@&#8203;bjornhellander](https://github.com/bjornhellander) in
[DotNetAnalyzers/StyleCopAnalyzers#3528
- Update SA1515 to not let one range of trivia affect another by
[@&#8203;bjornhellander](https://github.com/bjornhellander) in
[DotNetAnalyzers/StyleCopAnalyzers#3529
- Mentioned VS 2022 by
[@&#8203;twojnarowski](https://github.com/twojnarowski) in
[DotNetAnalyzers/StyleCopAnalyzers#3549
- Remove byte order mark from schema file by
[@&#8203;martincostello](https://github.com/martincostello) in
[DotNetAnalyzers/StyleCopAnalyzers#3562
- Update SA1012 to expect no space between a property pattern's opening
brace and an enclosing list pattern's opening bracket by
[@&#8203;bjornhellander](https://github.com/bjornhellander) in
[DotNetAnalyzers/StyleCopAnalyzers#3511
- Update Microsoft.CodeAnalysis.CSharp.Workspaces to version 4.4.0 for
the c# 11 test project by
[@&#8203;bjornhellander](https://github.com/bjornhellander) in
[DotNetAnalyzers/StyleCopAnalyzers#3580
- Update SA1008 to handle positional patterns inside property patterns
by [@&#8203;bjornhellander](https://github.com/bjornhellander) in
[DotNetAnalyzers/StyleCopAnalyzers#3579
- Update SA1000 to trigger after keywords is, or, and, not by
[@&#8203;bjornhellander](https://github.com/bjornhellander) in
[DotNetAnalyzers/StyleCopAnalyzers#3585
- Update SA1000.md by
[@&#8203;Youssef1313](https://github.com/Youssef1313) in
[DotNetAnalyzers/StyleCopAnalyzers#3563
- Update SA1313 to also allow incorrect names in explicitly implemented
methods from interfaces by
[@&#8203;bjornhellander](https://github.com/bjornhellander) in
[DotNetAnalyzers/StyleCopAnalyzers#3569
- Update SA1023 to not trigger first in line, inside a foreach without
braces by [@&#8203;bjornhellander](https://github.com/bjornhellander)
in
[DotNetAnalyzers/StyleCopAnalyzers#3543
- Update SA1400 to recognize access modifier "file" by
[@&#8203;bjornhellander](https://github.com/bjornhellander) in
[DotNetAnalyzers/StyleCopAnalyzers#3590
- Update SA1206 to recognize modifier "file" by
[@&#8203;bjornhellander](https://github.com/bjornhellander) in
[DotNetAnalyzers/StyleCopAnalyzers#3591
- Update SA1000 to handle checked operator declarations correctly by
[@&#8203;bjornhellander](https://github.com/bjornhellander) in
[DotNetAnalyzers/StyleCopAnalyzers#3505
- Update SA1402 to handle records and record structs by
[@&#8203;bjornhellander](https://github.com/bjornhellander) in
[DotNetAnalyzers/StyleCopAnalyzers#3570
- Bump Newtonsoft.Json from 12.0.3 to 13.0.2 in
/StyleCop.Analyzers/StyleCop.Analyzers.Status.Generator by
[@&#8203;dependabot](https://github.com/dependabot) in
[DotNetAnalyzers/StyleCopAnalyzers#3584
- Update to the latest version of the testing library by
[@&#8203;sharwell](https://github.com/sharwell) in
[DotNetAnalyzers/StyleCopAnalyzers#3601
- Update so that SA1600 tests will be run with the expected language
version in test projects for c# 8 and above by
[@&#8203;bjornhellander](https://github.com/bjornhellander) in
[DotNetAnalyzers/StyleCopAnalyzers#3614
- Update reading of file_header_template and
stylecop.documentation.copyrightText to allow multiple lines by
[@&#8203;bjornhellander](https://github.com/bjornhellander) in
[DotNetAnalyzers/StyleCopAnalyzers#3617
- Update SA1015 to require trailing space after an explicit generic
return type in a lambda expression by
[@&#8203;bjornhellander](https://github.com/bjornhellander) in
[DotNetAnalyzers/StyleCopAnalyzers#3625
- Update to Microsoft.CodeAnalysis.Analyzers 3.3.5-beta1.23205.2 by
[@&#8203;sharwell](https://github.com/sharwell) in
[DotNetAnalyzers/StyleCopAnalyzers#3628
- Update SA1206 to handle c# 11 modifier "required" by
[@&#8203;bjornhellander](https://github.com/bjornhellander) in
[DotNetAnalyzers/StyleCopAnalyzers#3535
- Preparations for SettingsHelper optimizations by
[@&#8203;bjornhellander](https://github.com/bjornhellander) in
[DotNetAnalyzers/StyleCopAnalyzers#3635
- Correct SA1515 to not fire on the second line of a file header by
[@&#8203;bjornhellander](https://github.com/bjornhellander) in
[DotNetAnalyzers/StyleCopAnalyzers#3633
- Update AnalyzersExtensions and SettingsHelper to use cached JsonValue
objects where possible by
[@&#8203;bjornhellander](https://github.com/bjornhellander) in
[DotNetAnalyzers/StyleCopAnalyzers#3642
- Update SA1010 to not trigger on list patterns by
[@&#8203;bjornhellander](https://github.com/bjornhellander) in
[DotNetAnalyzers/StyleCopAnalyzers#3507
- Update NamingSettings and DocumentationSettings to keep one Regex
instance instead of calling Regex.IsMatch by
[@&#8203;bjornhellander](https://github.com/bjornhellander) in
[DotNetAnalyzers/StyleCopAnalyzers#3639
- Use ResxSourceGenerator for resource generation by
[@&#8203;sharwell](https://github.com/sharwell) in
[DotNetAnalyzers/StyleCopAnalyzers#3343
- Make XmlCommentHelper faster by
[@&#8203;ninedan](https://github.com/ninedan) in
[DotNetAnalyzers/StyleCopAnalyzers#3651
- Update RenameToUpperCaseCodeFixProvider to not offer a code fix if the
identifier only consists of underscores by
[@&#8203;bjornhellander](https://github.com/bjornhellander) in
[DotNetAnalyzers/StyleCopAnalyzers#3637
- Don't emit SA1414 for interface implementations by
[@&#8203;CollinAlpert](https://github.com/CollinAlpert) in
[DotNetAnalyzers/StyleCopAnalyzers#3644
- Support file-scoped namespaces in SA1516 by
[@&#8203;JakubLinhart](https://github.com/JakubLinhart) in
[DotNetAnalyzers/StyleCopAnalyzers#3513
- Update SA1137 to also consider init accessors by
[@&#8203;bjornhellander](https://github.com/bjornhellander) in
[DotNetAnalyzers/StyleCopAnalyzers#3669
- Update SA1500 to also consider init accessors by
[@&#8203;bjornhellander](https://github.com/bjornhellander) in
[DotNetAnalyzers/StyleCopAnalyzers#3670
- Update SA1513 to not trigger before an init accessor by
[@&#8203;bjornhellander](https://github.com/bjornhellander) in
[DotNetAnalyzers/StyleCopAnalyzers#3666
- Update SA1212 to also trigger for an init accessor before a getter by
[@&#8203;bjornhellander](https://github.com/bjornhellander) in
[DotNetAnalyzers/StyleCopAnalyzers#3661
- Update SA1513 codefix to use the existing newline character sequence
by [@&#8203;bjornhellander](https://github.com/bjornhellander) in
[DotNetAnalyzers/StyleCopAnalyzers#3607
- Correct code fix for SA1130 when delegate expression is part of a cast
expression by
[@&#8203;bjornhellander](https://github.com/bjornhellander) in
[DotNetAnalyzers/StyleCopAnalyzers#3516
- Update so that c# 7 tests will be run with the expected language
version in test projects for c# 8 and above by
[@&#8203;bjornhellander](https://github.com/bjornhellander) in
[DotNetAnalyzers/StyleCopAnalyzers#3616
- SA1629 should allow full-sentence links instead of forcing the period
to glow white by [@&#8203;jnm2](https://github.com/jnm2) in
[DotNetAnalyzers/StyleCopAnalyzers#3371

#### New Contributors

- [@&#8203;twojnarowski](https://github.com/twojnarowski) made their
first contribution in
[DotNetAnalyzers/StyleCopAnalyzers#3549
- [@&#8203;ninedan](https://github.com/ninedan) made their first
contribution in
[DotNetAnalyzers/StyleCopAnalyzers#3651
- [@&#8203;CollinAlpert](https://github.com/CollinAlpert) made their
first contribution in
[DotNetAnalyzers/StyleCopAnalyzers#3644
- [@&#8203;JakubLinhart](https://github.com/JakubLinhart) made their
first contribution in
[DotNetAnalyzers/StyleCopAnalyzers#3513

**Full Changelog**:
DotNetAnalyzers/StyleCopAnalyzers@1.2.0-beta.435...1.2.0-beta.507

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "before 4am" (UTC), Automerge - At any
time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/ThorstenSauter/NoPlan).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS4xMzEuMCIsInVwZGF0ZWRJblZlciI6IjM1LjEzMS4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Thorsten Sauter <Thorsten.Sauter@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SA1010 incorrectly reported on opening bracket in C# 11 list pattern
3 participants