* origin/master: (104 commits) Added shebang sample for Pike. Added interpreter "pike" for Pike. Add support for FXML files. Add support for Turtle and SPARQL Fixed issues for web ontology to pass tests Added Web Ontology Language Support Simplify blob tests Use the original FileBlob path for filesystem access Sample sagews file, as requested Update languages.yml with *.sagews New grammar for Racket Remove grammar for Racket Modifying BlobHelper and FileBlob to use path Sample file for .cmake.in Restore the .cmake.in extension. More CMake samples. Updating file regex to support unlicense.txt Updating ref to include license Remove pry Start using path with LazyBlob ... Conflicts: CONTRIBUTING.md README.md
5.6 KiB
Contributing
The majority of contributions won't need to touch any Ruby code at all. Linguist defines a list of all languages known to GitHub in lib/linguist/languages.yml.
Most languages are detected by their file extension. For disambiguating between files with common extensions, we first apply some common-sense heuristics to pick out obvious languages. After that, we use a statistical classifier. This process can help us tell the difference between, for example, .h files which could be either C, C++, or Obj-C.
Adding a language
We try only to add languages once they have some usage on GitHub. In most cases we prefer that languages be in use in hundreds of repositories before supporting them in Linguist.
To add support for a new language:
- Add an entry for your language to
languages.yml. - Add a grammar for your language. Please only add grammars that have a license that permits redistribution.
- Add your grammar as a submodule:
git submodule add https://github.com/JaneSmith/MyGrammar vendor/grammars/MyGrammar. - Add your grammar to
grammars.ymlby runningscript/convert-grammars --add vendor/grammars/MyGrammar. - Add samples for your language to the samples directory in the correct subdirectory.
- Open a pull request, linking to a GitHub search result showing in-the-wild usage.
In addition, if your new language defines an extension that's already listed in languages.yml (such as .foo) then sometimes a few more steps will need to be taken:
- Make sure that example
.foofiles are present in the samples directory for each language that uses.foo. - Test the performance of the Bayesian classifier with a relatively large number (1000s) of sample
.foofiles. (ping @arfon or @bkeepers to help with this) to ensure we're not misclassifying files. - If the Bayesian classifier does a bad job with the sample
.foofiles then a heuristic may need to be written to help.
Remember, the goal here is to try and avoid false positives!
Fixing syntax highlighting
Syntax highlighting in GitHub is performed using TextMate-compatible grammars. These are the same grammars that TextMate, Sublime Text and Atom use. Every language in languages.yml is mapped to its corresponding TM scope. This scope will be used when picking up a grammar for highlighting.
Assuming your code is being detected as the right language (see Language Detection above), in most cases this is due to a bug in the language grammar rather than a bug in Linguist. grammars.yml lists all the grammars we use for syntax highlighting on github.com. Find the one corresponding to your code's programming language and submit a bug report upstream. If you can, try to reproduce the highlighting problem in the text editor that the grammar is designed for (TextMate, Sublime Text, or Atom) and include that information in your bug report.
You can also try to fix the bug yourself and submit a Pull Request. TextMate's documentation offers a good introduction on how to work with TextMate-compatible grammars. You can test grammars using Lightshow.
Once the bug has been fixed upstream, please let us know and we'll pick it up for GitHub.
Testing
For development you are going to want to checkout out the source. To get it, clone the repo and run Bundler to install its dependencies.
git clone https://github.com/github/linguist.git
cd linguist/
script/bootstrap
To run the tests:
bundle exec rake test
Sometimes getting the tests running can be too much work, especially if you don't have much Ruby experience. It's okay: be lazy and let our build bot Travis run the tests for you. Just open a pull request and the bot will start cranking away.
Here's our current build status: 
Releasing
If you are the current maintainer of this gem:
- Create a branch for the release:
git checkout -b cut-release-vxx.xx.xx - Make sure your local dependencies are up to date:
script/bootstrap - If grammar submodules have not been updated recently, update them:
git submodule update --remote && git commit -a - Ensure that samples are updated:
bundle exec rake samples - Ensure that tests are green:
bundle exec rake test - Bump gem version in
lib/linguist/version.rb, like this. - Make a PR to github/linguist, like this.
- Build a local gem:
bundle exec rake build_gem - Test the gem:
- Bump the Gemfile and Gemfile.lock versions for an app which relies on this gem
- Install the new gem locally
- Test behavior locally, branch deploy, whatever needs to happen
- Merge github/linguist PR
- Tag and push:
git tag vx.xx.xx; git push --tags - Push to rubygems.org --
gem push github-linguist-3.0.0.gem