]> khamidou — GitHub mirrors - arcanist.git/commit
Add a lint check for clobbering locals with iterators
authorepriestley <git@epriestley.com>
Thu, 29 Mar 2012 20:21:18 +0000 (13:21 -0700)
committerepriestley <git@epriestley.com>
Thu, 29 Mar 2012 20:21:18 +0000 (13:21 -0700)
commit3ae1bf1a8ce2fb562912e3402374d08371ce09bd
treee61a53b9c6ea01c3afa3c85b5842f7267f9f6ace
parentff94d699feda745c482ca3792f65e8d42cf5e318
Add a lint check for clobbering locals with iterators

Summary:
See D2049, D2050. Identify reuses of locals as iterator variables. Before raising an error, we require:

  - Variable is declared before the loop.
  - Variable is used after the loop, ignoring uses as an iterator variable.

I think this identifies all problems with a very low false positive rate (the false positives are suspicious/unconventional code, but not necessarily errors).

Also fix an issue identified by the linter.

Test Plan:
  - Verified this identified the bugs in D2049 and D2050.
  - Ran linter against libphutil/, arcanist/ and phabricator/ (see D2051, this, and next diff).
  - Ran unit tests.

Reviewers: vrana, btrahan

Reviewed By: vrana

CC: aran, epriestley, jungejason
Differential Revision: https://secure.phabricator.com/D2052
src/lint/linter/base/test/ArcanistLinterTestCase.php
src/lint/linter/xhpast/ArcanistXHPASTLinter.php
src/lint/linter/xhpast/__tests__/data/reused-local.lint-test [new file with mode: 0644]
src/workflow/svn-hook-pre-commit/ArcanistSvnHookPreCommitWorkflow.php