GithubHelp home page GithubHelp logo

rjkmurray75 / linguist Goto Github PK

View Code? Open in Web Editor NEW

This project forked from github-linguist/linguist

0.0 1.0 0.0 32.2 MB

Language Savant. If your repository's language is being reported incorrectly, send us a pull request!

License: MIT License

Ruby 99.60% Shell 0.40%

linguist's Introduction

Linguist

This library is used on GitHub.com to detect blob languages, ignore binary or vendored files, suppress generated files in diffs, and generate language breakdown graphs.

See Troubleshooting and CONTRIBUTING.md before filing an issue or creating a pull request.

Troubleshooting

My repository is detected as the wrong language

language stats bar

The Language stats bar displays languages percentages for the files in the repository. The percentages are calculated based on the bytes of code for each language as reported by the List Languages API. If the bar is reporting a language that you don't expect:

  1. Click on the name of the language in the stats bar to see a list of the files that are identified as that language.
  2. If you see files that you didn't write, consider moving the files into one of the paths for vendored code, or use the manual overrides feature to ignore them.
  3. If the files are being misclassified, search for open issues to see if anyone else has already reported the issue. Any information you can add, especially links to public repositories, is helpful.
  4. If there are no reported issues of this misclassification, open an issue and include a link to the repository or a sample of the code that is being misclassified.

There's a problem with the syntax highlighting of a file

Linguist detects the language of a file but the actual syntax-highlighting is powered by a set of language grammars which are included in this project as a set of submodules and may be found here.

If you experience an issue with the syntax-highlighting on GitHub, please report the issue to the upstream grammar repository, not here. Grammars are updated every time we build the Linguist gem and so upstream bug fixes are automatically incorporated as they are fixed.

Overrides

Linguist supports a number of different custom overrides strategies for language definitions and vendored paths.

Using gitattributes

Add a .gitattributes file to your project and use standard git-style path matchers for the files you want to override to set linguist-documentation, linguist-language, and linguist-vendored. .gitattributes will be used to determine language statistics, but will not be used to syntax highlight files. To manually set syntax highlighting, use Vim or Emacs modelines.

$ cat .gitattributes
*.rb linguist-language=Java

Checking code you didn't write, such as JavaScript libraries, into your git repo is a common practice, but this often inflates your project's language stats and may even cause your project to be labeled as another language. By default, Linguist treats all of the paths defined in lib/linguist/vendor.yml as vendored and therefore doesn't include them in the language statistics for a repository.

Use the linguist-vendored attribute to vendor or un-vendor paths.

$ cat .gitattributes
special-vendored-path/* linguist-vendored
jquery.js linguist-vendored=false

Just like vendored files, Linguist excludes documentation files from your project's language stats. lib/linguist/documentation.yml lists common documentation paths and excludes them from the language statistics for your repository.

Use the linguist-documentation attribute to mark or unmark paths as documentation.

$ cat .gitattributes
project-docs/* linguist-documentation
docs/formatter.rb linguist-documentation=false

Generated file detection

Not all plain text files are true source files. Generated files like minified js and compiled CoffeeScript can be detected and excluded from language stats. As an added bonus, unlike vendored and documentation files, these files are suppressed in diffs.

Linguist::FileBlob.new("underscore.min.js").generated? # => true

See Linguist::Generated#generated?.

Using Emacs or Vim modelines

Alternatively, you can use Vim or Emacs style modelines to set the language for a single file. Modelines can be placed anywhere within a file and are respected when determining how to syntax-highlight a file on GitHub.com

Vim
# Some examples of various styles:
vim: syntax=java
vim: set syntax=ruby:
vim: set filetype=prolog:
vim: set ft=cpp:
Emacs
-*- mode: php;-*-

Usage

Install the gem:

$ gem install github-linguist

Then use it in your application:

require 'rugged'
require 'linguist'

repo = Rugged::Repository.new('.')
project = Linguist::Repository.new(repo, repo.head.target_id)
project.language       #=> "Ruby"
project.languages      #=> { "Ruby" => 119387 }

These stats are also printed out by the linguist executable. You can use the --breakdown flag, and the binary will also output the breakdown of files by language.

You can try running linguist on the root directory in this repository itself:

$ bundle exec linguist --breakdown

100.00% Ruby

Ruby:
Gemfile
Rakefile
bin/linguist
github-linguist.gemspec
lib/linguist.rb
…

Contributing

Please check out our contributing guidelines.

License

The language grammars included in this gem are covered by their repositories' respective licenses. grammars.yml specifies the repository for each grammar.

All other files are covered by the MIT license, see LICENSE.

linguist's People

Contributors

alhadis avatar alindeman avatar arfon avatar aroben avatar benbalter avatar bkeepers avatar brianmario avatar draegtun avatar dragonmux avatar edm00se avatar edmundito avatar fingolfin avatar fushnisoft avatar gjtorikian avatar haileys avatar ismailarilik avatar josh avatar larsbrinkhoff avatar mislav avatar pchaigno avatar rick avatar sahildua2305 avatar scottmangiapane avatar sebgod avatar sparkyswidgets avatar stevepiercy avatar tesch1 avatar tnm avatar vmg avatar williamd1k0 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.