Skip to content

Conversation

@iSazonov
Copy link
Collaborator

@iSazonov iSazonov commented May 28, 2018

PR Summary

Please fast review to avoid merge conflicts because of many files changed.

Please review commit by commit - every commit contains only single kind of change so you can do very fast review.

This corrects about 1% of the CodeFactor issues.

The PR replace null != var with var != null and null == var with var == null

All changes is made in VS Code with Regex patterns - one pattern by commit:

'\((null) != (\w+)\)' -> '($2 != $1)'

'\((null) != (\w+.\w+)\)' -> '($2 != $1)'

'\((null) != (\w+) ' -> '($2 != $1 '

'(null) != (\w+),' -> '$2 != $1,'

'if \((null) != (\w+(.\w+)+)\)' -> 'if ($2 != $1)'

'if \((null) != (.+)\)' -> 'if ($2 != $1)'

Manual replacement 1

'if \((null) != (\w+.\w+)' -> 'if ($2 != $1'

'\b(null) != (\w+)\)' -> '$2 != $1)'

'\b(null) != (\w+.\w+)\)' -> '$2 != $1)'

'\b(null) != (\w+.\w+.\w+)\)' -> '$2 != $1)'

'\((null) != (\w+.\w+),' -> '($2 != $1,'

'\((null) != (\w+.\w+) ' -> '($2 != $1 '

'\((null) != (\w+.\w+\[\w+.\w+\])' -> '($2 != $1'

'\b(null) != (\w+.\w+)' -> $2 != $1

------------------------------------------

'\((null) == (\w+)\)' -> '($2 == $1)'

'\((null) == (\w+.\w+)\)' -> '($2 == $1)'

'\((null) == (\w+) ' -> '($2 == $1 '

'if \((null) == (\w+.\w+)' -> 'if ($2 == $1'

'\b(null) == (\w+)\)' -> '$2 == $1)'

'\b(null) == (\w+.\w+)\)' -> '$2 == $1)'

'\((null) == (\w+.\w+\["\w+"].\w+)' -> '($2 == $1'

'\((null) == (\w+.\w+\["\w+"])' -> '($2 == $1'

PR Checklist

Copy link
Contributor

Choose a reason for hiding this comment

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

this one is out of place. it should go after DeserializingTypeConverter.RehydrationFlags.MissingPropertyOk)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is single manual change I did :-)
The commit is replaced.

@lzybkr
Copy link
Contributor

lzybkr commented May 29, 2018

People use if (null != something) out of habit because some languages like C and C++ allow if (something = null) and that's a nasty bug. I'm not a fan of discouraging this style even though it's not a problem in C#.

If this CodeFactor warning didn't find a bug, I'd disable the warning, it doesn't feel like it's worth the risk of so many changes via regex without much higher confidence the tests cover all of these changes.

@iSazonov
Copy link
Collaborator Author

If you remember a year ago, I offered to fix style in tests. Response team was negative - it is better to spend your time on more useful things. It was a convincing position. Then we continued to receive many-many comments on the style of tests each PR. Finally everyone ran out of patience and we fixed our tests.
We have long endured trailing spaces in our code. At one point, our patience ran out and we fixed it.
Now we understand that spend a lot of useless efforts to style and formatting. So @TravisEz13 suggested the use of CodeFactor.
We must configure it before we can effectively use it. This is being discussed in #6930.
We disable obvious rules which we'll never fix like "one type per file" or "ordering elements" and more.
The remaining problems, we have to be correct (partially) to use CodeFactor effectively.
Should we disable current issue? I believe no because we already discussed this and we already require that use the C# style in our code. If we leave bad samples we lose meaning use CodeFactor which reports problems a entire file rather than the latest changes.
About risk see my #6930 (comment)

@lzybkr
Copy link
Contributor

lzybkr commented May 30, 2018

I sampled the report from CodeFactor when it was first enabled and wasn't impressed. Maybe after you refine the rules it will show some value, but I'm still skeptical.

As one data point for my skepticism - you touched 187 files in this PR, but CodeFactor claims there are 119 issues fixed and only 99 of the issues fixed are of the Do not use comparison where value goes first.

So if you found 88 or more places to fix that the tool didn't, humans will continue to find similar nits that the tool won't. Contributors will have one additional barrier to contributing in addition to the human nitpickers.

If the nitpicking isn't adding value, you could try asking those making the comments to try less nitpicking.

@iSazonov
Copy link
Collaborator Author

When I joined the project, the first three months I was amazed each time I got different types of style comments from different people. Why team did it? Obviously to get good code. What changed this time? Nothing. We will not be able to change our behavior if we do not take any steps.
This situation zugzwang. If we do not correct these issues we are doomed to many style comments. Fix all - it's not real. We need to find a compromise by configuring CodeFactor and fixing some issues.
I would be happy not to do this work. But I definitely envy CoreFX code looks like.

As one data point for my skepticism - you touched 187 files in this PR, but CodeFactor claims there are 119 issues fixed and only 99 of the issues fixed are of the Do not use comparison where value goes first.

On CodeFactor site it is mentioned that they use their config and some other analysis methods - so we can get "weird" and "amazing" results. After we merge our config we can investigate problems if we find them.

@lzybkr
Copy link
Contributor

lzybkr commented May 30, 2018

In this specific case - I find it reasonable to adopt the exact opposite of what CodeFactor suggests, but I think it is even more reasonable to disable the warning and move on to more important issues.

Sometimes word order matters, sometimes the order of words doesn't matter. Either way, we understand the message clearly.

If code reviewers are complaining about this exact issue - they too should find more valuable things to complain about.

@lzybkr
Copy link
Contributor

lzybkr commented May 30, 2018

My last comment on this specific issue - CoreFx is roughly as inconsistent as PowerShell, with about 6% of the comparisons using null on the LHS.

With some irony, if you fix this, we'd be less like CoreFx. :)

@iSazonov iSazonov mentioned this pull request May 31, 2018
11 tasks
@iSazonov
Copy link
Collaborator Author

iSazonov commented Jun 1, 2018

As one data point for my skepticism - you touched 187 files in this PR, but CodeFactor claims there are 119 issues fixed and only 99 of the issues fixed

I believe that this difference comes from the fact that some code is under if UNIX (and we have still if !CORECLR).

@dantraMSFT
Copy link
Contributor

@iSazonov, I have to agree with @lzybkr, I see no benefit to making this change and the rule should simply be disabled.

@iSazonov
Copy link
Collaborator Author

iSazonov commented Jun 9, 2018

I think this rule should remain enabled and this change can be closed if the team does not want it. /cc @SteveL-MSFT @daxian-dbw

@SteveL-MSFT
Copy link
Member

I scrolled through the changes and don't see any issues with the change itself. So the risk seems low.

As for whether we want to make this change, I think readability is slightly better with null on the RHS. If we want new code to adopt RHS, then I think we should take this PR so we don't have mixed usage. Otherwise, we should just be ok with null on LHS or RHS (although perhaps at least consistent within the same file).

Since @iSazonov has already done the work, risk seems low, and (personally) readability is better. I would be for taking this change. However, I think it's a decision the @PowerShell/powershell-maintainers should make.

@iSazonov
Copy link
Collaborator Author

Resolve merge conflicts.

@TravisEz13
Copy link
Member

restarted Linux CI, I'll be OOF for a couple of days.

@daxian-dbw
Copy link
Member

@TravisEz13 @adityapatwardhan and I discussed this offline and we agree to take this PR for the same reasons as @SteveL-MSFT mentioned above. But in general, we prefer less changes per PR for style related changes:

  • A PR is better to focus on a single category of style issue.
  • A PR is better to modify less than 10 files (it also depends on how many changes per file)

I will soon go through this PR and merge it.

@daxian-dbw daxian-dbw self-assigned this Jun 21, 2018
@iSazonov
Copy link
Collaborator Author

•A PR is better to modify less than 10 files (it also depends on how many changes per file)

I suggest to apply this rule only to code. We have tons style issues for doc comments - I think we could change more files per PR in the case without risk.

Seems also the rule assumes that we could fix style issues by file, by module, by cmdlet set (ex., web cmdlets), by provider and so on.

Does this conclusion imply that our policy is changed and we want and accept style changes?
I believe we should update our internal contributing docs.

@daxian-dbw
Copy link
Member

@iSazonov Doc comments issues can be an exception, because of the super low risk. It's not a rule, but a flexible guideline for us maintainers to consider (you can read the tone -- prefer, better to :)).

The main reason that we don't want massive changes in a PR is the time cost to review -- it will be easy for the PR to end up with no approval since no one wants to spend the time reviewing all the changes. This will, in turn, hurt the author's feeling and discourage the author's further contribution, because if the author really meant to fix those style issues, he/she must have put a lot effort/time into it. So we want to set some guidelines to help prevent a contributor from getting in that situation.

@daxian-dbw
Copy link
Member

Seems also the rule assumes that we could fix style issues by file, by module, by cmdlet set (ex., web cmdlets), by provider and so on.

Does this conclusion imply that our policy is changed and we want and accept style changes?
I believe we should update our internal contributing docs.

We accept PRs that are purely for style changes (we have to if we want to make CodeFactor useful). Such a PR should be reviewable, and that's why we proposed the flexible guideline. But this should be temporary -- once the existing style issues reported by CodeFactor are fixed, we won't accept PR with pure style changes.

Copy link
Member

@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

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

Went through the changes. LGTM.

@daxian-dbw daxian-dbw dismissed markekraus’s stale review June 25, 2018 21:03

Comment has been addressed.

@daxian-dbw daxian-dbw merged commit 4fc784e into PowerShell:master Jun 25, 2018
@iSazonov iSazonov deleted the cleanup-codefactor-null branch June 26, 2018 06:27
@iSazonov
Copy link
Collaborator Author

@daxian-dbw Thanks for code review and clarifications!

daxian-dbw added a commit that referenced this pull request Jun 26, 2018
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.

8 participants