Skip to content

Replace == null and != null with is null and is not null #3459

Closed

Description

@RussKie

Expected behavior:

Scrub the codebase to replace all instances:

  1. == null with is null, and done
  2. != null with is not null (when C# 9.0 is generally available)

Expectations:

  1. Scrubs are done on per-project basis, one PR per project
  2. PRs must not contain any other changes

Activity

  1. added
    help wanted
    code cleanup
    on Jun 17, 2020
  2. added this to the Future milestone on Jun 17, 2020
  3. sashatankov commented on Jun 17, 2020

    @sashatankov

    Hey, I'd like to work on this one

  4. RussKie commented on Jun 17, 2020

    @RussKie
    ContributorAuthor

    Awesome! Let's do it gradually, per project, to reduce churn and conflicts.

  5. sashatankov commented on Jun 18, 2020

    @sashatankov

    Do you want me to do any particular project? if not, then I randomly choose one

  6. weltkante commented on Jun 18, 2020

    @weltkante
    Contributor

    You might want to fill out your template in the PR #3469

    Also it would be good to get confirmation that potential precedence changes between == and is operators do not have edge cases that require adding braces.

  7. RussKie commented on Jun 19, 2020

    @RussKie
    ContributorAuthor

    No preference on a project, but == null -> is null for now until C# 9.0 is generally available.

  8. Youssef1313 commented on Sep 2, 2020

    @Youssef1313
    Member

    @RussKie A regex search in the whole repo with ==\s*null shows only 3 results. Two of them are comments, and one is an assertion message string.


    Edit: It seems like the repo is using null == x, not x == null. That's why my Regex failed.

    There are a few occurrences with the following regex: null\s*==. I opened #3825 for some occurrences.

  9. elachlan commented on Oct 23, 2022

    @elachlan
    Contributor

    @Youssef1313 do you know of an analyzer that handles this?

  10. Youssef1313 commented on Oct 24, 2022

    @Youssef1313
    Member
  11. elachlan commented on Oct 24, 2022

    @elachlan
    Contributor
  12. RussKie commented on Oct 24, 2022

    @RussKie
    ContributorAuthor

    Yes, we know where to find him :)
    As a matter of fact we already using another package of his:

    <XUnitStaFactPackageVersion>1.0.33-beta</XUnitStaFactPackageVersion>

  13. elachlan commented on Nov 16, 2022

    @elachlan
    Contributor

    CSharpIsNull has landed in winforms. So anyone wanting to refactor, it should now be a lot easier.

  14. elachlan commented on Nov 22, 2022

    @elachlan
    Contributor

    @AArnott is this a false negative? _priorWindowProcHandle is a void*.

    Also ppRetValOut is an IntPtr* and has an == null

    unsafe HRESULT UiaCore.IAccessibleEx.ConvertReturnedElement(UiaCore.IRawElementProviderSimple pIn, IntPtr* ppRetValOut)
    {
    if (ppRetValOut == null)
    {
    return HRESULT.E_POINTER;
    }

  15. ghost added
    🚧 work in progress
    on Nov 22, 2022
  16. AArnott commented on Nov 22, 2022

    @AArnott
    Contributor

    @elachlan regarding _priorWindowProcHandle, it looks to me like void* can use is null, so the analyzer suggesting using is null syntax doesn't appear to be a mistake. Or are you saying that the analyzer didn't pick up on it and you think it should?

    Same observation/question for the second. I guess the confusion is what you mean by a false negative. If you mean no warning is produced and you think there should be, can you file a bug at https://github.com/AArnott/CSharpIsNull/issues?

  17. elachlan commented on Nov 22, 2022

    @elachlan
    Contributor

    No warning is produced. I'll file a bug. Thanks :)

  18. elachlan commented on Nov 22, 2022

    @elachlan
    Contributor

    The issue I filed: AArnott/CSharpIsNull#30

  19. ghost removed
    🚧 work in progress
    on Nov 23, 2022
  20. ghost removed this from the Future milestone on Nov 23, 2022
  21. ghost locked as resolved and limited conversation to collaborators on Dec 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    code cleanuphelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions