Hide test files in Golang repos
See original GitHub issueTest URL: https://github.com/andersfylling/disgord/
First of, when I use the word hide I mean removing the table row which contains the test file. Not remove the possibility to access the test file, just reduce the number rows for Go projects.
Go test files and the feature
This feature regards Go only. Go has built-in unit testing such that most devs usually define a test file for several of their source files. Example:
As you can see, there are several _test files. The naming scheme is to simply add _test
to any source file, and it indicates that there are unit tests specifically for that source file. However, when looking at the files on GitHub, there’s no real reason to use another row just for a dedicated test file.
Visually I would want this (before):
To look like this (after). Basically remove the extra rows. Example1 (purple/blue marks the space saved):
This saves a lot of extra rows in github repos with +10 test files. I know I only look at the file names to realize which features a repository holds, and get an idea of the structuring. As such, I’m not interested in seeing the filename duplicate just to show that it has tests.
That said, the visualization I show in example1 is just to showcase the space saved. I don’t think it would be pleasent UX to hide the row and not clearly display the test file. In my example you see the _test.go
word is added, which every Go developer recognizes as a test file. I do want to still access the test files, and I think it should be clearly identified that the file is clickable. I’m just not sure how to design that.
Example2, showcase the file existence better than example1:
This displays that the file exists, has a different background color to make it easier to realize that there’s a new element in the row. The text also has a blue url color to it, to indicate it’s a url/clickable. Note that I also respect the paddings on either side, and that the column width is fixed for all.
I do not want to remove test files that are not designated to a source file however. (I don’t have a example image atm) so this collection:
- a.go
- b.go
- feature_test.go
Should still show the file named feature_test.go
as there are no files named feature.go
.
Psuedo logic for filtering
Since GitHub sorts the files by name. It means that every test file should appear right below the source file it is designated for. With the assumption that all files are always sorted in this order, I can make the filter have a complexity of O(N), N for number of files. If the sorting differs or changes by a plugin or a change in the github UI, the complexity will be O((N-1) + N), yes I’m aware that we remove constants from the BigO, but since we’re not dealing with millions of entries, it seems defensible.
psuedo code for sorted files:
for (i=0; i < len(filenames) - 1; i++)
file = filenames[i]
if (!file.suffix(".go")) {
continue
}
if (file.withoutExtension + "_test" != filenames[i + 1].withoutExtension) {
continue
}
file.addTestLink(filenames[i + 1].url)
filenames[i + 1].hide()
You can even speed this up by going from bottom up:
for (i=len(filenames) - 1; i > 0; i--)
file = filenames[i]
if (!file.suffix("_test.go")) {
continue
}
if (file.withoutSuffix("_test.go") != filenames[i - 1].withoutExtension) {
continue
}
file.hide()
filenames[i - 1].addTestLink(file.url)
Before and after filtering
This looks horrible on phone. But on desktop they stack horizontally.
These images are missing the _test.go
“button” for their respective files. It’s just to show a comparison of space use. This becomes even greater for projects that has a test file for every single source file. Which is not uncommon.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:9 (6 by maintainers)
Top GitHub Comments
I like the counter. We could combine that with indenting the combined files under the main file when they are expanded. Maybe with a collapsible arrow.
That does mean some reordering of files, based on a priority. See example above where
FormAbout.cs
is moved aboveFormAbout.Designer.cs
.At first sight it does look like you’re describing https://github.com/sindresorhus/hide-files-on-github, but you just want to make the list more compact by grouping related files.
If this can be applied to other languages I think it could make sense as part of RGH, otherwise no.
I think I’ve seen a similar practice in JS as well for
.spec.js
and.test.js
files.Maybe
group-sibling-test-files
?