Page MenuHomePhabricator

Split the `ArcanistXHPASTLinter` into modular rules
ClosedPublic

Authored by joshuaspence on Sep 23 2014, 1:56 PM.
Tags
None
Referenced Files
F13184468: D10541.id27706.diff
Fri, May 10, 7:06 PM
F13181458: D10541.id31269.diff
Thu, May 9, 12:23 PM
F13181248: D10541.id.diff
Thu, May 9, 10:22 AM
F13179920: D10541.id28147.diff
Wed, May 8, 9:32 PM
F13177526: D10541.diff
Wed, May 8, 7:46 PM
Unknown Object (File)
Sat, May 4, 3:21 AM
Unknown Object (File)
Wed, May 1, 7:27 AM
Unknown Object (File)
Tue, Apr 30, 11:26 PM

Details

Summary

The ArcanistXHPASTLinter class is becoming quite bloated. This diff separates the class into one-class-per-rule, which makes everything much more modular. One downside to this decoupling is that code reuse between linter rules is much more difficult, although this only affects a very small number of linter rules.

There is still some further work that could be done here, but I defer this until a later diff:

  • Rewrite ArcanistPhutilXHPASTLinter using ArcanistXHPASTLinterRule.
  • Change the unit tests so that they are truly only testing a single linter rule.
  • Maybe improve the way in which linter configuration options are handled.
  • Make it easier to keep track of the linter rule IDs (see T6859).
Test Plan

arc unit

Diff Detail

Repository
rARC Arcanist
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

joshuaspence retitled this revision from to Split the `ArcanistXHPASTLinter` into modular rules.
joshuaspence updated this object.
joshuaspence edited the test plan for this revision. (Show Details)
joshuaspence added a reviewer: epriestley.
joshuaspence edited edge metadata.

This is now in a somewhat working state

Convert remaining rules to classes

@epriestley, just wanted some initial thoughts before I put more time into this.

joshuaspence edited the test plan for this revision. (Show Details)

Unfortunately, this really seems to slow the unit tests down, I'm not sure why at the moment.

PASS  1m04s   ArcanistXHPASTLinterTestCase::testLinter

@epriestley, are you interested in this upstream? It's really difficult to rebase this diff, so I'd rather abandon it now if it's unlikely to be accepted.

@epriestley, whilst there's no rush on this... is this something that you would consider eventually? (seeing as I didn't file a ticket first)

epriestley edited edge metadata.

Yeah, I'm fine with moving forward on this.

  • ID management is a little unfortunate, but I don't have a cleaner approach at the moment.
  • If this still causes a big performance hit, getting a before/after profile and figuring out what changed would be nice.
This revision is now accepted and ready to land.May 19 2015, 1:33 PM
src/lint/linter/xhpast/ArcanistXHPASTLinterRule.php
107–116

@epriestley, any ideas on a non-hacky way of doing this?

src/lint/linter/xhpast/ArcanistXHPASTLinterRule.php
107–116

Oh, gross. Just make them public? This seems like a good justification, and these feel like reasonable methods at the boundary of the API to me.

One downside to this modularization is that there is no code re-use across linter rules. In the current implementation, it is possible for a single function to raise linter messages of more than one type. This is not very common, however, with only 7 XHPAST linter rules utilizing this code reuse.

Move a class. Set default severity

This still does seem to be significantly slow (the unit tests run in 1.6 seconds compared to 999 ms before), but I defer any performance optimizations to T7892.

This revision was automatically updated to reflect the committed changes.