Page MenuHomePhabricator

Add a linter rule for use of `is_a`
ClosedPublic

Authored by joshuaspence on Nov 25 2015, 7:47 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Apr 25, 2:57 AM
Unknown Object (File)
Fri, Apr 19, 3:52 PM
Unknown Object (File)
Thu, Apr 11, 10:29 AM
Unknown Object (File)
Sun, Apr 7, 11:15 PM
Unknown Object (File)
Mar 31 2024, 3:18 PM
Unknown Object (File)
Mar 30 2024, 6:44 PM
Unknown Object (File)
Mar 21 2024, 12:10 PM
Unknown Object (File)
Mar 7 2024, 4:45 AM
Subscribers

Details

Summary

instanceof should be used instead of is_a. I need to do a bit more research here to see if there are any edge cases.

Test Plan

Added unit tests.

Diff Detail

Repository
rARC Arcanist
Branch
master
Lint
Lint Passed
Unit
Test Failures
Build Status
Buildable 9388
Build 11168: Run Core Tests
Build 11167: arc lint + arc unit

Event Timeline

joshuaspence retitled this revision from to Add a linter rule for use of `is_a`.
joshuaspence updated this object.
joshuaspence edited the test plan for this revision. (Show Details)
joshuaspence added a reviewer: epriestley.

I think this is an edge case:

$subclass = 'Subclass';
is_a($subclass, 'Base', $allow_string = true); // true
$subclass instanceof Base; // false, string is not an instance of anything

I'm also not sure offhand what the distinction between is_a() and is_subclass_of() is.

epriestley edited edge metadata.

(Probably an edge case earlier?)

This revision now requires changes to proceed.Dec 1 2015, 12:21 PM
joshuaspence edited edge metadata.

Seems to work now

epriestley edited edge metadata.
epriestley added inline comments.
src/lint/linter/xhpast/rules/ArcanistIsAShouldBeInstanceOfXHPASTLinterRule.php
29–31

We could probably make evalStatic() smarter about this and have the code do something like:

if (!$allow_string->isSomethingWeCanCallEvalStaticOn()) {
  continue;
}

if ($allow_string->evalStatic()) {
  continue;
}

...to catch 0, etc., some day far in the future.

56

Missing text at end of sentence ("which has... what?")

59

Prefer ($replacement === null) for consistency.

This revision is now accepted and ready to land.Dec 22 2015, 1:43 PM
joshuaspence marked 2 inline comments as done.
joshuaspence edited edge metadata.

Fix a few inlines

This revision was automatically updated to reflect the committed changes.