Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[close #20] Simplify large file output #26

Merged
merged 4 commits into from
Dec 7, 2020

Conversation

schneems
Copy link
Collaborator

@schneems schneems commented Dec 7, 2020

This change reduces the output to only the minimal context needed.

This change reduces the output to only the minimal context needed.
Stable sort means that when elements are entered into an array that have the same value, they will be sorted in the same order. For example:

```
MyValue = Struct.new(:value, :name)

[MyValue.new(1, :a), MyValue.new(1, :b), MyValue.new(1, :c)]
  .sort_by {|x| x.value }
  .map(&:name)
```

You would expect this to always produce `[:a, :b, :c]` since that's the original order that they're entered in, however since ruby's sort is not "stable" this is not the case.

This non-determinism causes tests to produce different results on different systems which leads to CI failures. We can mitigate this by sorting by the value we want first, then by some consistent secondary value. In this case I'm using line number for the first code block.
@schneems schneems force-pushed the schneems/better-output-format branch from a4f60c1 to 6717be4 Compare December 7, 2020 18:06
Previously when we were trying to capture the "neighbors" context, we were using the same logic as when trying to "expand" a block. This logic looks for unmatched keyword pairs, so when it looks up it will stop at `def foo` but not at `def foo; end`. For grabbing context we want to stop after the first contextual pair so we cannot use that same method.

Instead a new method that is specialized to finding context is introduced to the AroundBlockScan class.

 When trying to capture code context, we don't want to look for a dangling keyword, we want the first matched pair
@schneems schneems force-pushed the schneems/better-output-format branch from 6717be4 to 9036905 Compare December 7, 2020 18:11
@schneems schneems merged commit 688afa0 into main Dec 7, 2020
@schneems schneems deleted the schneems/better-output-format branch December 7, 2020 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant