Refined-github: Hide test files in Golang repos

Created on 26 Feb 2019  路  9Comments  路  Source: sindresorhus/refined-github

Test 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.

enhancement help wanted

All 9 comments

@andersfylling You are almost describing another extension of mine: https://github.com/sindresorhus/hide-files-on-github

Interesting. I don't know if I would label them as non-essential. I find myself reading test files to understand behavior and look for benchmark issues. So I wouldn't hide them completely; instead just add a reference to them at their related file, as proposed.

The reason I proposed this feature here, is because I view it as a upgrade to the current github UI. Making it smarter. I'm also not a chrome user, and I would really love to see this feature in a extension I already use and love, if possible.

I apologies if this feature is not a fit for redefined-github.

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?

For JavaScript .js and .min.js files. Or any other language where there is also a minified file. Same goes for .js and .js.map.

For C# with .resx and .designer.cs plus optional .cs (for example: https://github.com/jerone/HostProfiles/tree/master/HostProfiles).

For ASP.NET Global.asax.cs and Global.asax (where Global.asax.cs is primary file).

I fear that it could get noisy, especially if there are more then 1 sibling.

How about a counter that when clicked will expand the sibling?

counter

<span class="float-right Counter">2</span>

Also maybe this should only be applied to long lists of files because it wouldn't be very helpful to hide related files in a folder that has 3 files, for example.

What if it's conditional? such that if it's only one file; we use my concept, otherwise, we can utilize yours?

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.

image

_That does mean some reordering of files, based on a priority. See example above where FormAbout.cs is moved above FormAbout.Designer.cs._

What if instead of grouping them, the lines are faded out?

This way no information will be omitted, no clicks are necessary, and it still de-emphasizes related files. Plus it's easy to implement and maintain.

One of the main benefits was to reduce the number of listed files. As I find myself scrolling just to get to the bottom of the file tree.

Regardless of my proposal, it could be a nice feature to actually "separate" out test files in general.

Was this page helpful?
0 / 5 - 0 ratings