mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-12-29 13:21:01 +00:00
Add BlobHelper#include_in_language_stats?
This just extracts some logic from Repository#compute_stats and makes it testable.
This commit is contained in:
@@ -332,5 +332,15 @@ module Linguist
|
|||||||
def tm_scope
|
def tm_scope
|
||||||
language && language.tm_scope
|
language && language.tm_scope
|
||||||
end
|
end
|
||||||
|
|
||||||
|
DETECTABLE_TYPES = [:programming, :markup].freeze
|
||||||
|
|
||||||
|
# Internal: Should this blob be included in repository language statistics?
|
||||||
|
def include_in_language_stats?
|
||||||
|
!vendored? &&
|
||||||
|
!documentation? &&
|
||||||
|
!generated? &&
|
||||||
|
language && DETECTABLE_TYPES.include?(language.type)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ module Linguist
|
|||||||
# Its primary purpose is for gathering language statistics across
|
# Its primary purpose is for gathering language statistics across
|
||||||
# the entire project.
|
# the entire project.
|
||||||
class Repository
|
class Repository
|
||||||
DETECTABLE_TYPES = [:programming, :markup].freeze
|
|
||||||
|
|
||||||
attr_reader :repository
|
attr_reader :repository
|
||||||
|
|
||||||
# Public: Create a new Repository based on the stats of
|
# Public: Create a new Repository based on the stats of
|
||||||
@@ -158,14 +156,10 @@ module Linguist
|
|||||||
|
|
||||||
blob = Linguist::LazyBlob.new(repository, delta.new_file[:oid], new, mode.to_s(8))
|
blob = Linguist::LazyBlob.new(repository, delta.new_file[:oid], new, mode.to_s(8))
|
||||||
|
|
||||||
# Skip vendored or generated blobs
|
next unless blob.include_in_language_stats?
|
||||||
next if blob.vendored? || blob.documentation? || blob.generated? || blob.language.nil?
|
|
||||||
|
|
||||||
if DETECTABLE_TYPES.include?(blob.language.type)
|
|
||||||
file_map[new] = [blob.language.group.name, blob.size]
|
file_map[new] = [blob.language.group.name, blob.size]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
file_map
|
file_map
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -517,4 +517,29 @@ class TestBlob < Minitest::Test
|
|||||||
refute blob.new(" ").empty?
|
refute blob.new(" ").empty?
|
||||||
refute blob.new("nope").empty?
|
refute blob.new("nope").empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_include_in_language_stats
|
||||||
|
vendored = sample_blob("bower_components/custom/custom.js")
|
||||||
|
assert_predicate vendored, :vendored?
|
||||||
|
refute_predicate vendored, :include_in_language_stats?
|
||||||
|
|
||||||
|
documentation = fixture_blob("README")
|
||||||
|
assert_predicate documentation, :documentation?
|
||||||
|
refute_predicate documentation, :include_in_language_stats?
|
||||||
|
|
||||||
|
generated = sample_blob("CSS/bootstrap.min.css")
|
||||||
|
assert_predicate generated, :generated?
|
||||||
|
refute_predicate generated, :include_in_language_stats?
|
||||||
|
|
||||||
|
data = sample_blob("Ant Build System/filenames/ant.xml")
|
||||||
|
assert_equal :data, data.language.type
|
||||||
|
refute_predicate data, :include_in_language_stats?
|
||||||
|
|
||||||
|
prose = sample_blob("Markdown/tender.md")
|
||||||
|
assert_equal :prose, prose.language.type
|
||||||
|
refute_predicate prose, :include_in_language_stats?
|
||||||
|
|
||||||
|
included = sample_blob("HTML/pages.html")
|
||||||
|
assert_predicate included, :include_in_language_stats?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user