Skip to content

Conversation

@pbrisbin
Copy link
Contributor

@pbrisbin pbrisbin commented Dec 7, 2015

It's likely the original developer assumed that the pattern given to Node#xpath
is treated relative to the node on which it's called. That doesn't seem to
be the case.

The XPath "//error" finds ALL error nodes across the entire document, even when
invoked as file.xpath("//error"). This causes them all to be reported on every
file analyzed. Besides being extremely non-sensical, this can also be a
performance nightmare.

To correct this, we instead use Node#children to get only the currently
processing file's errors. This required replacing some hash accesses with
methods and the chaining of #value on attributes.

/cc @codeclimate/review

@pbrisbin pbrisbin force-pushed the pb-fix-egregious-bug branch 2 times, most recently from a35a8c0 to c5f3658 Compare December 7, 2015 19:22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be clearer as "only reports issues in the relevant file"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me

@gdiggs
Copy link
Contributor

gdiggs commented Dec 7, 2015

LGTM

It's likely the original developer assumed that the pattern given to
Node#xpath is treated relative to the node on which it's called. That
doesn't seem to be the case.

The XPath "//error" finds ALL error nodes across the entire document,
even when invoked as file.xpath("//error"). This causes them all to be
reported on every file analyzed. Besides being extremely non-sensical,
this can also be a performance nightmare.

To correct this, we instead use Node#children to get only the currently
processing file's errors. This required replacing some hash accesses
with methods and the chaining of #value on attributes.
@pbrisbin pbrisbin force-pushed the pb-fix-egregious-bug branch from c5f3658 to e7aff4f Compare December 7, 2015 19:26
@ABaldwinHunter
Copy link

Nice find!

@wfleming
Copy link
Contributor

wfleming commented Dec 7, 2015

pbrisbin added a commit that referenced this pull request Dec 7, 2015
Don't report all errors on each file analyzed
@pbrisbin pbrisbin merged commit 84a4bc9 into master Dec 7, 2015
@pbrisbin pbrisbin deleted the pb-fix-egregious-bug branch December 7, 2015 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants