githubgithub-linguist

How to set a custom extension-to-language mapping on GitHub without adding a new language to Linguist


My repo has several *.sb files containing smartBASIC source code. The files do not show up in language bar of the repo (because smartBASIC and its associated filename extension are not part of default Linguist definitions).

Mapping sb extension to smartBASIC in .gitattributes file:

**/*.sb linguist-language=smartBASIC

and ensuring the mapping is not "ignored":

**/*.sb linguist-vendored=false
**/*.sb linguist-generated=false
**/*.sb linguist-documentation=false
**/*.sb linguist-detectable=true 

does not have the desired effect. The sb files are processed as expected but smartBASIC is not a predefined langauge so the custom mapping does not produce any language stats info. (I verified this by mapping the files to another language (C++) and having them then show up in the language bar stats (as C++).

From other questions (Add custom language to a GitHub repository, Custom language in github repository) it seems that to get a new extension mapped to a new language requires their addition to Linguist (more specifically, at least the language must be added). From Linguist documentation it is clear that new languages/extensions are added only once they have sufficient presence in GitHub repos. This makes complete sense. However, it also means that there is no apparent way to map sb extension to smartBASIC language and have this appear in the language bar (e.g. repo stats as 60% smartBASIC, 30% Python, 10% other).

QUESTION: Is it possible to map a filename extension to a new language on GitHub using Linguist overrides without adding the new language to Linguist itself?

Is it possible using any other means?

(This question is about language stats of the repo. Syntax higlighting and other customizations are secondary at this stage.)


Solution

  • The current latest lib/linguist/languages.yml does not include smartBasic indeed.

    Is it possible to map a filename extension to a new language on GitHub using Linguist overrides without adding the new language to Linguist itself

    No, it is not supported.
    You have issues like 3665: "lingust-language=xyz appears to be ignored on github if 'xyz' is not a known language. Proposal: make it appear as unknown language"

    But even that is not accepted.

    Adding support for custom names in the language bar requires a lot more than a few tweaks in Linguist as the GitHub-side changes are far from trivial and would require an internally commissioned project to implement it.