Using gitattributes for linguist examples
Asked Answered
C

2

47

Are there any concrete examples, in order to detect wrong languages in GitHub via Linguist attributes?

Source: https://github.com/github/linguist

  • linguist-documentation
  • linguist-language
  • linguist-vendored
Competence answered 17/11, 2016 at 15:48 Comment(1)
They can be found in the README.md - github.com/github/linguist/tree/… - Although I'd admit it's not very easy to find.Spec
G
77

Examples can be found in Linguist's documentation. Detecting wrong languages (which's what OP asks) can be achieved by setting linguist-language attributes in the .gitattributes file.

linguist-language

With the following attribute, Linguist detects all .rb files as being Java files.

*.rb linguist-language=Java

linguist-vendored

With the following attribute, Linguist detects files in the special-vendored-path directory (notice the mandatory trailing *) as vendored and excludes them from statistics.

special-vendored-path/* linguist-vendored

A double * will also apply the override to all subdirectories:

 special-vendored-path/** linguist-vendored

linguist-documentation

Without the following attribute, Linguist would detect the file docs/formatter.rb as documentation and exclude it from statistics.

docs/formatter.rb linguist-documentation=false

linguist-detectable

With the following attribute, Linguist counts SQL files in statistics. Without this attribute, only programming and markup languages are counted in statistics.

*.sql linguist-detectable=true
Gatian answered 31/3, 2017 at 13:35 Comment(4)
Is it also possible to do * linguist-detectable=true to show every single language?Beghtol
@DaCuteRaccoon Yes, I'd expect that to work.Gatian
It doesn't tho.Koloski
@mqbakamqbaka You may need ** to match into all subdirectories.Gatian
D
0

For correct Markdown identification, following setting is required for .gitignore:

*.md linguist-documentation=false
*.md linguist-detectable
Danitadaniyal answered 12/7 at 23:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.