Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Enable IDE0044: MakeFieldReadonly#13880

Merged
iSazonov merged 16 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
xtqqczze:IDE0044xtqqczze/PowerShell-PowerShell:IDE0044Copy head branch name to clipboard
Jul 7, 2021
Merged

Enable IDE0044: MakeFieldReadonly#13880
iSazonov merged 16 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
xtqqczze:IDE0044xtqqczze/PowerShell-PowerShell:IDE0044Copy head branch name to clipboard

Conversation

@xtqqczze

@xtqqczze xtqqczze commented Oct 26, 2020

Copy link
Copy Markdown
Contributor

Enable IDE0044: MakeFieldReadonly as warning.

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

@iSazonov

iSazonov commented Nov 2, 2020

Copy link
Copy Markdown
Collaborator

@xtqqczze Please resolve merge conflicts and rebase.

@xtqqczze xtqqczze changed the title Enable IDE0044: MakeFieldReadonly Enable IDE0044: MakeFieldReadonly part 11 Nov 2, 2020
@xtqqczze

xtqqczze commented Nov 2, 2020

Copy link
Copy Markdown
Contributor Author

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

@iSazonov

iSazonov commented Nov 2, 2020

Copy link
Copy Markdown
Collaborator

The PR is still huge.

@xtqqczze

Copy link
Copy Markdown
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

iSazonov commented Jun 28, 2021

Copy link
Copy Markdown
Collaborator

@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
Comment thread src/System.Management.Automation/security/CatalogHelper.cs Outdated
Comment thread src/System.Management.Automation/security/CatalogHelper.cs Outdated
Comment thread src/System.Management.Automation/security/CatalogHelper.cs Outdated
Comment thread src/System.Management.Automation/security/CatalogHelper.cs Outdated
Comment thread src/System.Management.Automation/security/nativeMethods.cs Outdated
@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
Copy Markdown
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

iSazonov commented Jun 29, 2021

Copy link
Copy Markdown
Collaborator

@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

xtqqczze commented Jun 30, 2021

Copy link
Copy Markdown
Contributor Author

@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

xtqqczze commented Jul 1, 2021

Copy link
Copy Markdown
Contributor Author

Depends on #15704.

@iSazonov

iSazonov commented Jul 1, 2021

Copy link
Copy Markdown
Collaborator

@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

xtqqczze commented Jul 3, 2021

Copy link
Copy Markdown
Contributor Author

@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 compiler warning and is ignored.

@Prosper-web Prosper-web left a comment

Copy link
Copy Markdown

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

ghost commented Jul 22, 2021

Copy link
Copy Markdown

🎉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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.