8000 Enable IDE0044: MakeFieldReadonly by xtqqczze · Pull Request #13880 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@xtqqczze
Copy link
Contributor
@xtqqczze xtqqczze commented Oct 26, 2020

Enable IDE0044: MakeFieldReadonly as warning.

  • Add suppression for ComInterop via GlobalSuppressions.cs
  • Convert a few static readonly fields to const.

@iSazonov
Copy link
Collaborator
iSazonov commented Nov 2, 2020

@xtqqczze Please resolve merge conflicts and rebase.

@xtqqczze xtqqczze changed the title Enable IDE0044: MakeFieldReadonly Enable IDE0044: MakeFieldReadonly part 11 Nov 2, 2020
@xtqqczze
Copy link
Contributor Author
xtqqczze commented Nov 2, 2020

@iSazonov We can reuse this PR for src\Microsoft.Management.Automation changes?

@iSazonov
Copy link
Collaborator
iSazonov commented Nov 2, 2020

The PR is still huge.

@xtqqczze
Copy link
Contributor Author

@iSazonov ComInterop is frozen, but the code is not structured in separate project from System.Management.Automation, so we cannot currently disable analyzers for only ComInterop :(

D:\a\1\s\src\System.Management.Automation\engine\ComInterop\ExcepInfo.cs(18,23): error IDE0044: Make field readonly [D:\a\1\s\src\System.Management.Automation\System.Management.Automation.csproj]
D:\a\1\s\src\System.Management.Automation\engine\ComInterop\ExcepInfo.cs(19,23): error IDE0044: Make field readonly [D:\a\1\s\src\System.Management.Automation\System.Management.Automation.csproj]
D:\a\1\s\src\System.Management.Automation\engine\ComInterop\ExcepInfo.cs(23,21): error IDE0044: Make field readonly [D:\a\1\s\src\System.Management.Automation\System.Management.Automation.csproj]
D:\a\1\s\src\System.Management.Automation\engine\ComInterop\ExcepInfo.cs(24,24): error IDE0044: Make field readonly [D:\a\1\s\src\System.Management.Automation\System.Management.Automation.csproj]
D:\a\1\s\src\System.Management.Automation\engine\ComInterop\ExcepInfo.cs(25,24): error IDE0044: Make field readonly [D:\a\1\s\src\System.Management.Automation\System.Management.Automation.csproj]
D:\a\1\s\src\System.Management.Automation\engine\ComInterop\ExcepInfo.cs(26,21): error IDE0044: Make field readonly [D:\a\1\s\src\System.Management.Automation\System.Management.Automation.csproj]
D:\a\1\s\src\System.Management.Automation\engine\ComInterop\ComInvokeBinder.cs(26,37): error IDE0044: Make field readonly [D:\a\1\s\src\System.Management.Automation\System.Management.Automation.csproj]

@iSazonov
Copy link
Collaborator
iSazonov commented Jun 28, 2021

@xtqqczze Please look the code in .Net Runtime repository. Perhaps they already fixed the issues. If no we could suppress the warnings on file level:

[ExcepInfo.cs]
dotnet_diagnostic.IDE0044.severity = none

(For generated code https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/configuration-options#exclude-generated-code)

@ghost ghost removed the Review - Needed The PR is being reviewed label Jun 28, 2021
@ghost ghost added Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept and removed Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept labels Jun 28, 2021
@xtqqczze
Copy link
Contributor Author

/home/vsts/work/1/s/src/System.Management.Automation/engine/interpreter/InstructionList.cs(99,49): error CS0649: Field 'InstructionList._debugCookies' is never assigned to, and will always have its default value null [/home/vsts/work/1/s/src/System.Management.Automation/System.Management.Automation.csproj]

@iSazonov
Copy link
Collaborator
iSazonov commented Jun 29, 2021

@xtqqczze Please look the code in .Net Runtime repository. Perhaps they already fixed the issues. If no we could suppress the warnings on file level:

[ExcepInfo.cs]
dotnet_diagnostic.IDE0044.severity = none

(For generated code https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/configuration-options#exclude-generated-code)

Doesn't this work?

Learn how to configure code analysis rules in an analyzer configuration file.

@xtqqczze
Copy link
Contributor Author
xtqqczze commented Jun 30, 2021

@xtqqczze Please look the code in .Net Runtime repository. Perhaps they already fixed the issues. If no we could suppress the warnings on file level:

[ExcepInfo.cs]
dotnet_diagnostic.IDE0044.severity = none

(For generated code https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/configuration-options#exclude-generated-code)

Doesn't this work?

@iSazonov Unless I specify the absolute path, I see warning InvalidGlobalSectionName, so probably this approach doesn't work in a GlobalConfig file. In any case, suppression in a GlobalSuppressions.cs file works for this PR. Ideally, the ComInterop code would be split to separate project and we set RunAnalyzers to false in the csproj. We could open an issue to discuss the best approach.

@xtqqczze
Copy link
Contributor Author
xtqqczze commented Jul 1, 2021

Depends on #15704.

@iSazonov
Copy link
Collaborator
iSazonov commented Jul 1, 2021

@iSazonov Unless I specify the absolute path, I see warning InvalidGlobalSectionName, so probably this approach doesn't work in a GlobalConfig file. In any case, suppression in a GlobalSuppressions.cs file works for this PR. Ideally, the ComInterop code would be split to separate project and we set RunAnalyzers to false in the csproj. We could open an issue to discuss the best approach.

absolute path? What about relative?

I don't like the assembly level suppression and I'd consider it as only last resort.

I believe we don't want ComInterop in separate project because we don't want new additional dll.

@xtqqczze
Copy link
Contributor Author
xtqqczze commented Jul 3, 2021

@iSazonov Unless I specify the absolute path, I see warning InvalidGlobalSectionName, so probably this approach doesn't work in a GlobalConfig file. In any case, suppression in a GlobalSuppressions.cs file works for this PR. Ideally, the ComInterop code would be split to separate project and we set RunAnalyzers to false in the csproj. We could open an issue to discuss the best approach.

absolute path? What about relative?

I don't like the assembly level suppression and I'd consider it as only last resort.

It seems that section headers for global AnalyzerConfig files must specify an absolute file path. A relative file path produces a compil 6855 er warning and is ignored.

Copy link
@Prosper-web Prosper-web left a comment

Choose a reason for hiding this comment

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

Good

@iSazonov iSazonov added the CL-CodeCleanup Indicates that a PR should be marked as a Code Cleanup change in the Change Log label Jul 4, 2021
@iSazonov iSazonov merged commit 03b07a0 into PowerShell:master Jul 7, 2021
@iSazonov iSazonov assigned iSazonov and unassigned anmenaga Jul 7, 2021
@iSazonov iSazonov added this to the 7.2.0-preview.8 milestone Jul 7, 2021
@xtqqczze xtqqczze deleted the IDE0044 branch July 7, 2021 06:36
@ghost
Copy link
ghost commented Jul 22, 2021

🎉v7.2.0-preview.8 has been released which incorporates this pull request.:tada:

Handy links:

@xtqqczze xtqqczze mentioned this pull request Sep 27, 2022
22 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-CodeCleanup Indicates that a PR should be marked as a Code Cleanup change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

0