Skip to content

Add 'Make anonymous function static' feature#73012

Merged
CyrusNajmabadi merged 15 commits intodotnet:mainfrom
DoctorKrolic:make-anonymous-function-static
Apr 15, 2024
Merged

Add 'Make anonymous function static' feature#73012
CyrusNajmabadi merged 15 commits intodotnet:mainfrom
DoctorKrolic:make-anonymous-function-static

Conversation

@DoctorKrolic
Copy link
Copy Markdown
Contributor

Closes: #45832

@DoctorKrolic DoctorKrolic requested a review from a team as a code owner April 13, 2024 12:10
@ghost ghost added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 13, 2024
@dotnet-policy-service dotnet-policy-service Bot added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Apr 13, 2024
Comment thread src/Analyzers/Core/Analyzers/EnforceOnBuildValues.cs Outdated
Comment thread src/VisualStudio/CSharp/Impl/Options/Formatting/StyleViewModel.cs Outdated
@DoctorKrolic
Copy link
Copy Markdown
Contributor Author

@CyrusNajmabadi PTAL

Copy link
Copy Markdown
Contributor

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

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

LGTM. Let me know if you want to fixup the tests or not. I'm ok with them going in in the current state.

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

Thanks!

@DoctorKrolic
Copy link
Copy Markdown
Contributor Author

Need failed pipelines restart here

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

CI failure is legit:

Missing entry in 'D:\a\_work\1\s\src\Features\RulesMissingDocumentation.md'. Please add the below entry to this file to fix the build:
  IDE0320 | <[https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0320>](https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0320%3E) | Make anonymous function static |
D:\a\_work\1\s\src\Features\Core\Portable\Microsoft.CodeAnalysis.Features.csproj(170,5): error MSB3073: The command ""D:\a\_work\1\s\.dotnet\dotnet.exe" --roll-forward major "D:\a\_work\1\s\artifacts\bin\GenerateRulesMissingDocumentation\Release\net8.0\GenerateRulesMissingDocumentation.dll" "-validateOnly:True" "D:\a\_work\1\s\src\Features" "D:\a\_work\1\s\artifacts\bin\\" "Release"" exited with code 1.

Build FAILED.

Sorry the UI is unclear here.

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

you just need to add a line to that file. our docs team will then doc this in the future.

auto-merge was automatically disabled April 15, 2024 17:46

Head branch was pushed to by a user without write access

@DoctorKrolic
Copy link
Copy Markdown
Contributor Author

CI failed again... This time doesn't seem to be a legit failure

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

Thanks. Have notified the test owner of hte flakeyness issue.

@CyrusNajmabadi CyrusNajmabadi merged commit 6b961f3 into dotnet:main Apr 15, 2024
@dotnet-policy-service dotnet-policy-service Bot added this to the Next milestone Apr 15, 2024
@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

Thanks!

@DoctorKrolic DoctorKrolic deleted the make-anonymous-function-static branch April 16, 2024 04:08
@dibarbet dibarbet modified the milestones: Next, 17.11 P1 Apr 29, 2024
MattKotsenas added a commit to rjmurillo/moq.analyzers that referenced this pull request Aug 1, 2024
Update .NET SDK to the latest released version and disable
`rollForward`.

Updates to the .NET SDK feature band can introduce new / updated
analyzers (for instance, 8.0.400 adds
[IDE0320](dotnet/roslyn#73012)). As a result,
updating the feature band isn't "safe" to do from a build
reproducibility perspective. It will also conflict with #166.

That means the roll forward options available to us are:

- `patch`
- `latestPatch`
- `disable`

However, GitHub Actions don't support these options (tracked by
actions/setup-dotnet#448). Thus, the only
`rollForward` strategy that currently does the same thing locally and in
CI is `disabled`.

Once 448 is fixed, we can / should probably switch to `latestPatch`
(tracked by #171).

This 'gotcha' is also added to the SquiggleCop documentation
[here](https://github.com/MattKotsenas/SquiggleCop?tab=readme-ov-file#common-sources-of-baseline-mismatches).
@cremor
Copy link
Copy Markdown

cremor commented Oct 7, 2024

Did this feature make it into 17.11 (as suggested by the assigned milestone)? Because I'm currently running 17.11.4 and SDK 8.0.400 and I can't get the analyzer to show up with the "before" examples in #45832

@DoctorKrolic
Copy link
Copy Markdown
Contributor Author

This analyzer is hidden by default so that existing code doesn't get too noisy. If you want this diagnostic to be shown in the diagnostic list, upgrade its severity to 'suggestion' or higher

@cremor
Copy link
Copy Markdown

cremor commented Oct 7, 2024

I did test it with this .editorconfig setting:

csharp_prefer_static_anonymous_function = true:suggestion

Code:

public void M(Func<int, int> func) { }

public void T()
{
    M(x => x + 1); // before
    M(delegate (int x) { return x + 1; }); // before
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee. untriaged Issues and PRs which have not yet been triaged by a lead

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add "make anonymous function static" code fix

4 participants