Page MenuHomePhabricator

Split the `ArcanistXHPASTLinter` into modular rules
ClosedPublic

Authored by joshuaspence on Sep 23 2014, 1:56 PM.
Tags
None
Referenced Files
F14057892: D10541.id27725.diff
Sun, Nov 17, 7:39 AM
F14050731: D10541.id27725.diff
Thu, Nov 14, 8:25 PM
F14046737: D10541.id27725.diff
Wed, Nov 13, 11:19 PM
F14046550: D10541.id28147.diff
Wed, Nov 13, 9:51 PM
F14046477: D10541.id28147.diff
Wed, Nov 13, 9:28 PM
F14046296: D10541.id27706.diff
Wed, Nov 13, 8:13 PM
F14046267: D10541.id27705.diff
Wed, Nov 13, 7:52 PM
F14046261: D10541.id27725.diff
Wed, Nov 13, 7:49 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
Branch
master
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 2838
Build 2842: [Placeholder Plan] Wait for 30 Seconds

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.