Skip to content

Reenable compound assignment preference #17784

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

Merged
merged 4 commits into from
Jul 31, 2022
Merged

Reenable compound assignment preference #17784

merged 4 commits into from
Jul 31, 2022

Conversation

Molkree
Copy link
Contributor

@Molkree Molkree commented Jul 27, 2022

PR Summary

Reenable compound assignment preference in .editorconfig.

PR Context

All violations of the rule should be fixed by now.
Fixes #17631

PR Checklist

@ghost ghost assigned TravisEz13 Jul 27, 2022
@Molkree
Copy link
Contributor Author

Molkree commented Jul 27, 2022

Okay, I already see some missed cases. I wonder what is different between the CI and my local environment?

@Molkree
Copy link
Contributor Author

Molkree commented Jul 27, 2022

Hm, one of them looks like a false positive. In /src/System.Management.Automation/singleshell/config/MshSnapinInfo.cs(1287,25):

                        if (s_defaultMshSnapins == null)
                        {
                            s_defaultMshSnapins = new List<DefaultPSSnapInInformation>()
                            {
#if !UNIX
                                new DefaultPSSnapInInformation("Microsoft.PowerShell.Diagnostics", "Microsoft.PowerShell.Commands.Diagnostics", null,
                                    "GetEventResources,Description", "GetEventResources,Vendor"),
#endif
                                new DefaultPSSnapInInformation("Microsoft.PowerShell.Host", "Microsoft.PowerShell.ConsoleHost", null,
                                    "HostMshSnapInResources,Description", "HostMshSnapInResources,Vendor"),

                                s_coreSnapin,

                                new DefaultPSSnapInInformation("Microsoft.PowerShell.Utility", "Microsoft.PowerShell.Commands.Utility", null,
                                    "UtilityMshSnapInResources,Description", "UtilityMshSnapInResources,Vendor"),

                                new DefaultPSSnapInInformation("Microsoft.PowerShell.Management", "Microsoft.PowerShell.Commands.Management", null,
                                    "ManagementMshSnapInResources,Description", "ManagementMshSnapInResources,Vendor"),

                                new DefaultPSSnapInInformation("Microsoft.PowerShell.Security", "Microsoft.PowerShell.Security", null,
                                    "SecurityMshSnapInResources,Description", "SecurityMshSnapInResources,Vendor")
                            };

#if !UNIX
                            if (!Utils.IsWinPEHost())
                            {
                                s_defaultMshSnapins.Add(new DefaultPSSnapInInformation("Microsoft.WSMan.Management", "Microsoft.WSMan.Management", null,
                                    "WsManResources,Description", "WsManResources,Vendor"));
                            }
#endif
                        }

It's not just an assignment inside the outer if, so analyzer shouldn't trigger here, what do you think?

@Molkree
Copy link
Contributor Author

Molkree commented Jul 27, 2022

I wonder what is different between the CI and my local environment?

The system is different, CI errored on Linux and macOS and I use Windows. 3 cases were inside #if UNIX hence why they didn't trigger for me.

4th one has #if !UNIX clause inside hence why it doesn't trigger on my local machine. But in CI Analyzer thinks there's no extra code inside and suggests this change. I'm not sure if it is correct behaviour.

@Molkree
Copy link
Contributor Author

Molkree commented Jul 27, 2022

It's not just an assignment inside the outer if, so analyzer shouldn't trigger here, what do you think?

We can rewrite the code block into this and it should please Analyzer on both platforms:

#if UNIX
                        s_defaultMshSnapins ??= new List<DefaultPSSnapInInformation>()
                        {
                            new DefaultPSSnapInInformation("Microsoft.PowerShell.Host", "Microsoft.PowerShell.ConsoleHost", null,
                                "HostMshSnapInResources,Description", "HostMshSnapInResources,Vendor"),

                            s_coreSnapin,

                            new DefaultPSSnapInInformation("Microsoft.PowerShell.Utility", "Microsoft.PowerShell.Commands.Utility", null,
                                "UtilityMshSnapInResources,Description", "UtilityMshSnapInResources,Vendor"),

                            new DefaultPSSnapInInformation("Microsoft.PowerShell.Management", "Microsoft.PowerShell.Commands.Management", null,
                                "ManagementMshSnapInResources,Description", "ManagementMshSnapInResources,Vendor"),

                            new DefaultPSSnapInInformation("Microsoft.PowerShell.Security", "Microsoft.PowerShell.Security", null,
                                "SecurityMshSnapInResources,Description", "SecurityMshSnapInResources,Vendor")
                        };
#else
                        if (s_defaultMshSnapins == null)
                        {
                            s_defaultMshSnapins = new List<DefaultPSSnapInInformation>()
                            {
                                new DefaultPSSnapInInformation("Microsoft.PowerShell.Diagnostics", "Microsoft.PowerShell.Commands.Diagnostics", null,
                                    "GetEventResources,Description", "GetEventResources,Vendor"),
                                new DefaultPSSnapInInformation("Microsoft.PowerShell.Host", "Microsoft.PowerShell.ConsoleHost", null,
                                    "HostMshSnapInResources,Description", "HostMshSnapInResources,Vendor"),

                                s_coreSnapin,

                                new DefaultPSSnapInInformation("Microsoft.PowerShell.Utility", "Microsoft.PowerShell.Commands.Utility", null,
                                    "UtilityMshSnapInResources,Description", "UtilityMshSnapInResources,Vendor"),

                                new DefaultPSSnapInInformation("Microsoft.PowerShell.Management", "Microsoft.PowerShell.Commands.Management", null,
                                    "ManagementMshSnapInResources,Description", "ManagementMshSnapInResources,Vendor"),

                                new DefaultPSSnapInInformation("Microsoft.PowerShell.Security", "Microsoft.PowerShell.Security", null,
                                    "SecurityMshSnapInResources,Description", "SecurityMshSnapInResources,Vendor")
                            };

                            if (!Utils.IsWinPEHost())
                            {
                                s_defaultMshSnapins.Add(new DefaultPSSnapInInformation("Microsoft.WSMan.Management", "Microsoft.WSMan.Management", null,
                                    "WsManResources,Description", "WsManResources,Vendor"));
                            }
                        }
#endif

Or we can ignore this rule locally.

I'll let the maintainers decide.

@iSazonov
Copy link
Collaborator

Hm, one of them looks like a false positive. In /src/System.Management.Automation/singleshell/config/MshSnapinInfo.cs(1287,25):

Please suppress locally.

@iSazonov iSazonov added the CL-CodeCleanup Indicates that a PR should be marked as a Code Cleanup change in the Change Log label Jul 28, 2022
@Molkree
Copy link
Contributor Author

Molkree commented Jul 28, 2022

Please suppress locally.

@iSazonov, done

@iSazonov
Copy link
Collaborator

@Molkree I guess CIs fail because we need to fix compound assignment in test code (weblistener).

@Molkree
Copy link
Contributor Author

Molkree commented Jul 29, 2022

@iSazonov, I am stumped, from failing tests I can only see that the WebListener did not start before the timeout was reached., with no pointers as to why. Any help here?

@iSazonov
Copy link
Collaborator

@Molkree Try compile test\tools\WebListener\ - I guess there are compound assignments we should fix.

@Molkree
Copy link
Contributor Author

Molkree commented Jul 29, 2022

Try compile test\tools\WebListener\

@iSazonov, thank you!

@iSazonov iSazonov assigned iSazonov and unassigned TravisEz13 Jul 31, 2022
@iSazonov iSazonov merged commit 7f69d74 into PowerShell:master Jul 31, 2022
@Molkree Molkree deleted the reenable-compound-assignment branch July 31, 2022 13:56
@ghost
Copy link

ghost commented Aug 11, 2022

🎉v7.3.0-preview.7 has been released which incorporates this pull request.:tada:

Handy links:

adityapatwardhan pushed a commit to adityapatwardhan/PowerShell that referenced this pull request Sep 29, 2022
@TravisEz13 TravisEz13 mentioned this pull request Sep 30, 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.

Fix IDE0074 - 'Use compound assignment' as reported by new style rules
4 participants