PSA: How to fix GitHub’s syntax highlighting for Solidity

Daniel Que
1 min readApr 17, 2018

--

GitHub doesn’t support detecting .sol files as Solidity for syntax highlighting, and the current best solution is simple but not well known.

Problem

GitHub uses linguist to enable language-related features. According to linguist’s maintainers, the .sol file extension is too generic to assign to Solidity.

Solution

Add a .gitattributes file to your repo’s root with the following contents:

*.sol linguist-language=Solidity

Examples:

You may have to wait a while, or push another commit to .sol files for it to take effect.

Conclusion

Since .sol can’t be assigned to Solidity, there’s some discussion around assigning .solidity to Solidity instead. This “consolation prize” is much less than ideal since the current convention has wide usage and deep roots. Changing the convention just to cater to a private git hosting company doesn’t make sense.

Perhaps when Solidity becomes popular enough, .sol will also be automatically classified by linguist.

More in-depth discussion can be found here.

I’m working on CryptoFin, the creators of Bskt and a smart contract auditing firm. You can follow our progress on Telegram.

--

--

Daniel Que

Engineer @ Coinbase. Previously Co-Founder of CryptoFin (aq by Coinbase), Engineer @ Uber.