Skip to content

Commit

Permalink
Use test-icons when matching hashbangs
Browse files Browse the repository at this point in the history
Although one can use their stylesheet to fix incorrect icons, doing this
quickly becomes laborious when too many permutations are involved:

    [data-name*="-spec."][data-name$=".py"]::after,
    [data-name*="-test."][data-name$=".py"]::after,
    [data-name*="-specs."][data-name$=".py"]::after,
    [data-name*="-tests."][data-name$=".py"]::after{
        font: 17px file-icons;
        content: "\ea66";
        top: 3px;
    }

This commit is a stopgap for an oft-encountered scenario where tests are
given inconsistent icons because they contain hashbangs. Of course, this
only solves part of a much larger issue with package's inability to link
multiple icons to a language, as opposed to only one. That's better left
to a future rewrite, however.

Fixes: #812
  • Loading branch information
Alhadis committed Apr 28, 2020
1 parent 762a59f commit daa9906
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Changed `brew-icon` to use Homebrew logo
- `.m2` extension now associated with [Macaulay2][] instead of [Modula-2][]
- `.cpc` extension now associated with [CpcdosC+][] instead of [Cartesian Perceptual Compression][CPC]
- [[`#812`][]]: Hashbang strategy now recognises test-files
- Renamed `Bazel` entry to `Starlark`
- UnrealScript files now coloured grey

[`#812`]: https://github.com/file-icons/atom/issues/812
[CPC]: https://en.wikipedia.org/wiki/Cartesian_Perceptual_Compression
[CpcdosC+]: https://cpcdos.net/
[Macaulay2]: https://en.wikipedia.org/wiki/Macaulay2
Expand Down
25 changes: 25 additions & 0 deletions lib/service/strategies/hashbang-strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ class HashbangStrategy extends HeaderStrategy {
name: "hashbangs",
priority: 5,
});
// HACK: Ad-hoc fix for tests with hashbangs (#812)
this.testIcons = new Map([
["coffee", ".test.coffee"],
["go", ".test.go"],
["haskell", ".test.hs"],
["js", ".test.js"],
["perl", ".t"],
["python", ".test.py"],
["ruby", ".test.rb"],
["rust", ".test.rs"],
["sh", "/t/1a.sh"],
["ts", ".test.ts"],
].map(([name, ext]) => [
IconTables.matchLanguage(name),
"/" === ext[0]
? IconTables.matchPath(ext)
: IconTables.matchName(ext),
]));
}


Expand All @@ -34,6 +52,13 @@ class HashbangStrategy extends HeaderStrategy {

let result = IconTables.matchInterpreter(name);

// HACK: Remap icons of test-files containing hashbangs (#812)
if(result && this.testIcons.has(result)){
const icon = this.testIcons.get(result);
if(icon.match.test(icon.matchPath ? resource.path : resource.name))
return icon;
}

// Valid hashbang, unrecognised interpreter
if(!result){
const {executable} = resource;
Expand Down

0 comments on commit daa9906

Please sign in to comment.