Class: Linguist::Generated
- Inherits:
-
Object
- Object
- Linguist::Generated
- Defined in:
- lib/linguist/generated.rb
Constant Summary collapse
- PROTOBUF_EXTENSIONS =
['.py', '.java', '.h', '.cc', '.cpp', '.m', '.rb', '.php']
- APACHE_THRIFT_EXTENSIONS =
['.rb', '.py', '.go', '.js', '.m', '.java', '.h', '.cc', '.cpp', '.php']
- HAXE_EXTENSIONS =
['.js', '.py', '.lua', '.cpp', '.h', '.java', '.cs', '.php']
Instance Attribute Summary collapse
-
#extname ⇒ Object
readonly
Returns the value of attribute extname.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.generated?(name, data) ⇒ Boolean
Public: Is the blob a generated file?.
Instance Method Summary collapse
-
#bazel_lock? ⇒ Boolean
Internal: Is the blob a Bazel generated bzlmod lockfile?.
-
#cargo_lock? ⇒ Boolean
Internal: Is the blob a generated Rust Cargo lock file?.
-
#cargo_orig? ⇒ Boolean
Internal: Is the blob a generated Rust Cargo original file?.
-
#carthage_build? ⇒ Boolean
Internal: Is the blob part of Carthage/Build/, which contains dependencies not meant for humans in pull requests.
-
#cocoapods? ⇒ Boolean
Internal: Is the blob part of Pods/, which contains dependencies not meant for humans in pull requests.
-
#compiled_coffeescript? ⇒ Boolean
Internal: Is the blob of JS generated by CoffeeScript?.
-
#compiled_cython_file? ⇒ Boolean
Internal: Is this a compiled C/C++ file from Cython?.
-
#composer_lock? ⇒ Boolean
Internal: Is the blob a generated php composer lock file?.
-
#data ⇒ Object
Lazy load blob data if block was passed in.
-
#esy_lock? ⇒ Boolean
Internal: Is the blob a generated esy lock file?.
-
#extract_html_meta(match) ⇒ Object
Internal: Extract a Hash of name/content pairs from an HTML <meta> tag.
-
#flake_lock? ⇒ Boolean
Internal: Is the blob a generated Nix flakes lock file?.
-
#generated? ⇒ Boolean
Internal: Is the blob a generated file?.
-
#generated_antlr? ⇒ Boolean
Is this a generated ANTLR file?.
-
#generated_apache_thrift? ⇒ Boolean
Internal: Is the blob generated by Apache Thrift compiler?.
-
#generated_by_zephir? ⇒ Boolean
Internal: Is the blob generated by Zephir?.
-
#generated_dart? ⇒ Boolean
Internal: Is this a generated Dart file?.
-
#generated_gamemakerstudio? ⇒ Boolean
Internal: Is this a generated Game Maker Studio (2) metadata file?.
-
#generated_gimp? ⇒ Boolean
Internal: Is this a generated GIMP C image file?.
- #generated_go? ⇒ Boolean
-
#generated_grammarkit? ⇒ Boolean
Internal: Is this a GrammarKit-generated file?.
-
#generated_graphql_relay? ⇒ Boolean
Internal: Is this a relay-compiler generated graphql file?.
-
#generated_grpc_cpp? ⇒ Boolean
Internal: Is this a protobuf/grpc-generated C++ file?.
-
#generated_haxe? ⇒ Boolean
Internal: Is this a generated Haxe-generated source file?.
-
#generated_html? ⇒ Boolean
Internal: Is this a generated HTML file?.
-
#generated_javascript_protocol_buffer? ⇒ Boolean
Internal: Is the blob a Javascript source file generated by the Protocol Buffer compiler?.
-
#generated_jflex? ⇒ Boolean
Internal: Is this a JFlex-generated file?.
-
#generated_jison? ⇒ Boolean
Internal: Is this a Jison-generated file?.
-
#generated_jni_header? ⇒ Boolean
Internal: Is the blob a C/C++ header generated by the Java JNI tool javah?.
-
#generated_jooq? ⇒ Boolean
Internal: Is this a generated jOOQ file?.
-
#generated_module? ⇒ Boolean
Internal: Is it a KiCAD or GFortran module file?.
-
#generated_net_designer_file? ⇒ Boolean
Internal: Is this a codegen file for a .NET project?.
-
#generated_net_docfile? ⇒ Boolean
Internal: Is this a generated documentation file for a .NET assembly?.
-
#generated_net_specflow_feature_file? ⇒ Boolean
Internal: Is this a codegen file for Specflow feature file?.
-
#generated_parser? ⇒ Boolean
Internal: Is the blob of JS a parser generated by PEG.js?.
-
#generated_pascal_tlb? ⇒ Boolean
Internal: Is this a generated Delphi Interface file for a type library?.
-
#generated_perl_ppport_header? ⇒ Boolean
Internal: Is the file a generated Perl/Pollution/Portability header file?.
-
#generated_postscript? ⇒ Boolean
Internal: Is the blob of PostScript generated?.
-
#generated_protocol_buffer? ⇒ Boolean
Internal: Is the blob a C++, Java or Python source file generated by the Protocol Buffer compiler?.
-
#generated_protocol_buffer_from_go? ⇒ Boolean
Internal: Is the blob a protocol buffer file generated by the go-to-protobuf tool?.
-
#generated_racc? ⇒ Boolean
Internal: Is this a Racc-generated file?.
-
#generated_roxygen2? ⇒ Boolean
Internal: Is this a roxygen2-generated file?.
-
#generated_sorbet_rbi? ⇒ Boolean
Internal: Is this a Sorbet RBI file generated by Tapioca?.
-
#generated_sqlx_query? ⇒ Boolean
Internal: Is this a generated SQLx query file?.
-
#generated_unity3d_meta? ⇒ Boolean
Internal: Is this a metadata file from Unity3D?.
-
#generated_visualstudio6? ⇒ Boolean
Internal: Is this a generated Microsoft Visual Studio 6.0 build file?.
-
#generated_yarn_plugnplay? ⇒ Boolean
Internal: Is the blob a generated Yarn Plug’n’Play?.
-
#go_lock? ⇒ Boolean
Internal: Is the blob a generated Go dep or glide lock file?.
-
#go_vendor? ⇒ Boolean
Internal: Is the blob part of the Go vendor/ tree, not meant for humans in pull requests.
-
#godeps? ⇒ Boolean
Internal: Is the blob part of Godeps/, which are not meant for humans in pull requests.
-
#has_source_map? ⇒ Boolean
Internal: Does the blob contain a source-map reference?.
-
#htmlcov? ⇒ Boolean
Internal: Is this an HTML coverage report?.
-
#initialize(name, data) ⇒ Generated
constructor
Internal: Initialize Generated instance.
-
#intellij_file? ⇒ Boolean
Internal: Is the blob an IntelliJ IDEA project file?.
-
#lines ⇒ Object
Public: Get each line of data.
-
#maybe_minified? ⇒ Boolean
Internal: Does extname indicate a filetype which is commonly minified?.
-
#minified_files? ⇒ Boolean
Internal: Is the blob a minified file?.
-
#node_modules? ⇒ Boolean
Internal: Is the blob part of node_modules/, which are not meant for humans in pull requests.
-
#npm_shrinkwrap_or_package_lock? ⇒ Boolean
Internal: Is the blob a generated npm shrinkwrap or package lock file?.
-
#pdm_lock? ⇒ Boolean
Internal: Is the blob a generated pdm.lock?.
-
#pipenv_lock? ⇒ Boolean
Internal: Is this a Pipenv lock file?.
-
#pnpm_lock? ⇒ Boolean
Internal: Is the blob a generated pnpm lockfile?.
-
#poetry_lock? ⇒ Boolean
Internal: Is the blob a generated poetry.lock?.
-
#source_map? ⇒ Boolean
Internal: Is the blob a generated source-map?.
-
#terraform_lock? ⇒ Boolean
Internal: Is this a Terraform lock file?.
-
#vcr_cassette? ⇒ Boolean
Is the blob a VCR Cassette file?.
-
#xcode_file? ⇒ Boolean
Internal: Is the blob an Xcode file?.
Constructor Details
#initialize(name, data) ⇒ Generated
Internal: Initialize Generated instance
name - String filename data - String blob data
19 20 21 22 23 |
# File 'lib/linguist/generated.rb', line 19 def initialize(name, data) @name = name @extname = File.extname(name) @_data = data end |
Instance Attribute Details
#extname ⇒ Object (readonly)
Returns the value of attribute extname.
25 26 27 |
# File 'lib/linguist/generated.rb', line 25 def extname @extname end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
25 26 27 |
# File 'lib/linguist/generated.rb', line 25 def name @name end |
Class Method Details
.generated?(name, data) ⇒ Boolean
Public: Is the blob a generated file?
name - String filename data - String blob data. A block also may be passed in for lazy
loading. This behavior is deprecated and you should always
pass in a String.
Return true or false
11 12 13 |
# File 'lib/linguist/generated.rb', line 11 def self.generated?(name, data) new(name, data).generated? end |
Instance Method Details
#bazel_lock? ⇒ Boolean
Internal: Is the blob a Bazel generated bzlmod lockfile?
Returns true or false
499 500 501 |
# File 'lib/linguist/generated.rb', line 499 def bazel_lock? !!name.match(/(^|\/)MODULE\.bazel\.lock$/) end |
#cargo_lock? ⇒ Boolean
Internal: Is the blob a generated Rust Cargo lock file?
Returns true or false.
478 479 480 |
# File 'lib/linguist/generated.rb', line 478 def cargo_lock? !!name.match(/Cargo\.lock/) end |
#cargo_orig? ⇒ Boolean
Internal: Is the blob a generated Rust Cargo original file?
Returns true or false.
485 486 487 |
# File 'lib/linguist/generated.rb', line 485 def cargo_orig? !!name.match(/Cargo\.toml\.orig/) end |
#carthage_build? ⇒ Boolean
Internal: Is the blob part of Carthage/Build/, which contains dependencies not meant for humans in pull requests.
Returns true or false.
147 148 149 |
# File 'lib/linguist/generated.rb', line 147 def carthage_build? !!name.match(/(^|\/)Carthage\/Build\//) end |
#cocoapods? ⇒ Boolean
Internal: Is the blob part of Pods/, which contains dependencies not meant for humans in pull requests.
Returns true or false.
140 141 142 |
# File 'lib/linguist/generated.rb', line 140 def cocoapods? !!name.match(/(^Pods|\/Pods)\//) end |
#compiled_coffeescript? ⇒ Boolean
Internal: Is the blob of JS generated by CoffeeScript?
CoffeeScript is meant to output JS that would be difficult to tell if it was generated or not. Look for a number of patterns output by the CS compiler.
Return true or false
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/linguist/generated.rb', line 208 def compiled_coffeescript? return false unless extname == '.js' # CoffeeScript generated by > 1.2 include a comment on the first line if lines[0] =~ /^\/\/ Generated by / return true end if lines[0] == '(function() {' && # First line is module closure opening lines[-2] == '}).call(this);' && # Second to last line closes module closure lines[-1] == '' # Last line is blank score = 0 lines.each do |line| if line =~ /var / # Underscored temp vars are likely to be Coffee score += 1 * line.gsub(/(_fn|_i|_len|_ref|_results)/).count # bind and extend functions are very Coffee specific score += 3 * line.gsub(/(__bind|__extends|__hasProp|__indexOf|__slice)/).count end end # Require a score of 3. This is fairly arbitrary. Consider # tweaking later. score >= 3 else false end end |
#compiled_cython_file? ⇒ Boolean
Internal: Is this a compiled C/C++ file from Cython?
Cython-compiled C/C++ files typically contain: /* Generated by Cython x.x.x on … */ on the first line.
Return true or false
529 530 531 532 533 |
# File 'lib/linguist/generated.rb', line 529 def compiled_cython_file? return false unless ['.c', '.cpp'].include? extname return false unless lines.count > 1 return lines[0].include?("Generated by Cython") end |
#composer_lock? ⇒ Boolean
Internal: Is the blob a generated php composer lock file?
Returns true or false.
464 465 466 |
# File 'lib/linguist/generated.rb', line 464 def composer_lock? !!name.match(/composer\.lock/) end |
#data ⇒ Object
Lazy load blob data if block was passed in.
Awful, awful stuff happening here.
Returns String data.
32 33 34 |
# File 'lib/linguist/generated.rb', line 32 def data @data ||= @_data.respond_to?(:call) ? @_data.call() : @_data end |
#esy_lock? ⇒ Boolean
Internal: Is the blob a generated esy lock file?
Returns true or false.
428 429 430 |
# File 'lib/linguist/generated.rb', line 428 def esy_lock? !!name.match(/(^|\/)(\w+\.)?esy.lock$/) end |
#extract_html_meta(match) ⇒ Object
Internal: Extract a Hash of name/content pairs from an HTML <meta> tag
836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 |
# File 'lib/linguist/generated.rb', line 836 def (match) (match.last.sub(/\/\Z/, "").strip.scan(/ (?<=^|\s) # Check for preceding whitespace (name|content|value) # Attribute names we're interested in \s* = \s* # Key-value separator # Attribute value ( "[^"]+" # name="value" | '[^']+' # name='value' | [^\s"']+ # name=value ) /ix)).map do |match| key = match[0].downcase val = match[1].gsub(/\A["']|["']\Z/, '') [key, val] end.select { |x| x.length == 2 }.to_h end |
#flake_lock? ⇒ Boolean
Internal: Is the blob a generated Nix flakes lock file?
Returns true or false
492 493 494 |
# File 'lib/linguist/generated.rb', line 492 def flake_lock? !!name.match(/(^|\/)flake\.lock$/) end |
#generated? ⇒ Boolean
Internal: Is the blob a generated file?
Generated source code is suppressed in diffs and is ignored by language statistics.
Please add additional test coverage to ‘test/test_blob.rb#test_generated` if you make any changes.
Return true or false
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/linguist/generated.rb', line 53 def generated? xcode_file? || intellij_file? || cocoapods? || carthage_build? || generated_graphql_relay? || generated_net_designer_file? || generated_net_specflow_feature_file? || composer_lock? || cargo_lock? || cargo_orig? || flake_lock? || bazel_lock? || node_modules? || go_vendor? || go_lock? || poetry_lock? || pdm_lock? || esy_lock? || npm_shrinkwrap_or_package_lock? || pnpm_lock? || terraform_lock? || generated_yarn_plugnplay? || godeps? || generated_by_zephir? || htmlcov? || minified_files? || has_source_map? || source_map? || compiled_coffeescript? || generated_parser? || generated_net_docfile? || generated_postscript? || compiled_cython_file? || pipenv_lock? || generated_go? || generated_protocol_buffer_from_go? || generated_protocol_buffer? || generated_javascript_protocol_buffer? || generated_apache_thrift? || generated_jni_header? || vcr_cassette? || generated_antlr? || generated_module? || || generated_racc? || generated_jflex? || generated_grammarkit? || generated_roxygen2? || generated_html? || generated_jison? || generated_grpc_cpp? || generated_dart? || generated_perl_ppport_header? || generated_gamemakerstudio? || generated_gimp? || generated_visualstudio6? || generated_haxe? || generated_jooq? || generated_pascal_tlb? || generated_sorbet_rbi? || generated_sqlx_query? end |
#generated_antlr? ⇒ Boolean
Is this a generated ANTLR file?
Returns true or false
516 517 518 519 520 |
# File 'lib/linguist/generated.rb', line 516 def generated_antlr? return false unless extname == '.g' return false unless lines.count > 2 return lines[1].include?("generated by Xtest") end |
#generated_apache_thrift? ⇒ Boolean
Internal: Is the blob generated by Apache Thrift compiler?
Returns true or false
373 374 375 376 |
# File 'lib/linguist/generated.rb', line 373 def generated_apache_thrift? return false unless APACHE_THRIFT_EXTENSIONS.include?(extname) return lines.first(6).any? { |l| l.include?("Autogenerated by Thrift Compiler") } end |
#generated_by_zephir? ⇒ Boolean
Internal: Is the blob generated by Zephir?
Returns true or false.
471 472 473 |
# File 'lib/linguist/generated.rb', line 471 def generated_by_zephir? !!name.match(/.\.zep\.(?:c|h|php)$/) end |
#generated_dart? ⇒ Boolean
Internal: Is this a generated Dart file?
A dart-lang/appengine generated file contains: // Generated code. Do not modify. on the first line.
An owl generated file contains: // GENERATED CODE - DO NOT MODIFY on the first line.
Return true or false
676 677 678 679 680 |
# File 'lib/linguist/generated.rb', line 676 def generated_dart? return false unless extname == '.dart' return false unless lines.count > 1 return lines.first.downcase =~ /generated code\W{2,3}do not modify/ end |
#generated_gamemakerstudio? ⇒ Boolean
Internal: Is this a generated Game Maker Studio (2) metadata file?
All Game Maker Studio 2 generated files will be JSON, .yy or .yyp, and have a part that looks like “modelName: GMname” on the 3rd line
Return true or false
704 705 706 707 708 709 |
# File 'lib/linguist/generated.rb', line 704 def generated_gamemakerstudio? return false unless ['.yy', '.yyp'].include? extname return false unless lines.count > 3 return lines[2].match(/\"modelName\"\:\s*\"GM/) || lines[0] =~ /^\d\.\d\.\d.+\|\{/ end |
#generated_gimp? ⇒ Boolean
Internal: Is this a generated GIMP C image file?
GIMP saves C sources with one of two comment forms:
-
‘/* GIMP RGB C-Source image dump (<filename>.c) */` (C source export)
-
‘/* GIMP header image file format (RGB): <filename>.h */` (Header export)
Return true or false
718 719 720 721 722 723 |
# File 'lib/linguist/generated.rb', line 718 def generated_gimp? return false unless ['.c', '.h'].include? extname return false unless lines.count > 0 return lines[0].match(/^\/\* GIMP [a-zA-Z0-9\- ]+ C\-Source image dump \(.+?\.c\) \*\//) || lines[0].match(/^\/\* GIMP header image file format \([a-zA-Z0-9\- ]+\)\: .+?\.h \*\//) end |
#generated_go? ⇒ Boolean
326 327 328 329 330 331 |
# File 'lib/linguist/generated.rb', line 326 def generated_go? return false unless extname == '.go' return false unless lines.count > 1 return lines.first(40).any? { |l| l =~ %r{^// Code generated .*} } end |
#generated_grammarkit? ⇒ Boolean
Internal: Is this a GrammarKit-generated file?
A GrammarKit-generated file typically contain: // This is a generated file. Not intended for manual editing. on the first line. This is not always the case, as it’s possible to customize the class header.
Return true or false
614 615 616 617 618 |
# File 'lib/linguist/generated.rb', line 614 def generated_grammarkit? return false unless extname == '.java' return false unless lines.count > 1 return lines[0].start_with?("// This is a generated file. Not intended for manual editing.") end |
#generated_graphql_relay? ⇒ Boolean
Internal: Is this a relay-compiler generated graphql file?
Return true or false
694 695 696 |
# File 'lib/linguist/generated.rb', line 694 def generated_graphql_relay? !!name.match(/__generated__\//) end |
#generated_grpc_cpp? ⇒ Boolean
Internal: Is this a protobuf/grpc-generated C++ file?
A generated file contains: // Generated by the gRPC C++ plugin. on the first line.
Return true or false
659 660 661 662 663 |
# File 'lib/linguist/generated.rb', line 659 def generated_grpc_cpp? return false unless %w{.cpp .hpp .h .cc}.include? extname return false unless lines.count > 1 return lines[0].start_with?("// Generated by the gRPC") end |
#generated_haxe? ⇒ Boolean
Internal: Is this a generated Haxe-generated source file?
Return true or false
738 739 740 741 |
# File 'lib/linguist/generated.rb', line 738 def generated_haxe? return false unless HAXE_EXTENSIONS.include?(extname) return lines.first(3).any? { |l| l.include?("Generated by Haxe") } end |
#generated_html? ⇒ Boolean
Internal: Is this a generated HTML file?
HTML documents generated by authoring tools often include a a <meta> tag in the header of the form:
<meta name="generator" content="DocGen v5.0.1" />
Return true or false
751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 |
# File 'lib/linguist/generated.rb', line 751 def generated_html? return false unless ['.html', '.htm', '.xhtml'].include? extname.downcase return false unless lines.count > 1 # Pkgdown return true if lines[0..1].any? do |line| line.match(/<!-- Generated by pkgdown: do not edit by hand -->/) end # Mandoc return true if lines.count > 2 && lines[2].start_with?('<!-- This is an automatically generated file.') # Doxygen return true if lines[0..30].any? do |line| line.match(/<!--\s+Generated by Doxygen\s+[.0-9]+\s*-->/i) end # HTML tag: <meta name="generator" content="…" /> matches = lines[0..30].join(' ').scan(/<meta(\s+[^>]++)>/i) return false if matches.empty? return matches.map {|x| (x) }.any? do |attr| attr["name"].to_s.downcase == 'generator' && [attr["content"], attr["value"]].any? do |cv| !cv.nil? && cv.match(/^ ( org \s+ mode | j?latex2html | groff | makeinfo | texi2html | ronn ) \b /ix) end end end |
#generated_javascript_protocol_buffer? ⇒ Boolean
Internal: Is the blob a Javascript source file generated by the Protocol Buffer compiler?
Returns true or false.
361 362 363 364 365 366 |
# File 'lib/linguist/generated.rb', line 361 def generated_javascript_protocol_buffer? return false unless extname == ".js" return false unless lines.count > 6 return lines[5].include?("GENERATED CODE -- DO NOT EDIT!") end |
#generated_jflex? ⇒ Boolean
Internal: Is this a JFlex-generated file?
A JFlex-generated file contains: /* The following code was generated by JFlex x.y.z on d/at/e ti:me */ on the first line.
Return true or false
600 601 602 603 604 |
# File 'lib/linguist/generated.rb', line 600 def generated_jflex? return false unless extname == '.java' return false unless lines.count > 1 return lines[0].start_with?("/* The following code was generated by JFlex ") end |
#generated_jison? ⇒ Boolean
Internal: Is this a Jison-generated file?
Jison-generated parsers typically contain: /* parser generated by jison on the first line.
Jison-generated lexers typically contain: /* generated by jison-lex on the first line.
Return true or false
645 646 647 648 649 650 |
# File 'lib/linguist/generated.rb', line 645 def generated_jison? return false unless extname == '.js' return false unless lines.count > 1 return lines[0].start_with?("/* parser generated by jison ") || lines[0].start_with?("/* generated by jison-lex ") end |
#generated_jni_header? ⇒ Boolean
Internal: Is the blob a C/C++ header generated by the Java JNI tool javah?
Returns true or false.
381 382 383 384 385 386 387 |
# File 'lib/linguist/generated.rb', line 381 def generated_jni_header? return false unless extname == '.h' return false unless lines.count > 2 return lines[0].include?("/* DO NOT EDIT THIS FILE - it is machine generated */") && lines[1].include?("#include <jni.h>") end |
#generated_jooq? ⇒ Boolean
Internal: Is this a generated jOOQ file?
Return true or false
791 792 793 794 |
# File 'lib/linguist/generated.rb', line 791 def generated_jooq? return false unless extname.downcase == '.java' lines.first(2).any? { |l| l.include? 'This file is generated by jOOQ.' } end |
#generated_module? ⇒ Boolean
Internal: Is it a KiCAD or GFortran module file?
KiCAD module files contain: PCBNEW-LibModule-V1 yyyy-mm-dd h:mm:ss XM on the first line.
GFortran module files contain: GFORTRAN module version ‘x’ created from on the first line.
Return true or false
560 561 562 563 564 565 |
# File 'lib/linguist/generated.rb', line 560 def generated_module? return false unless extname == '.mod' return false unless lines.count > 1 return lines[0].include?("PCBNEW-LibModule-V") || lines[0].include?("GFORTRAN module version '") end |
#generated_net_designer_file? ⇒ Boolean
Internal: Is this a codegen file for a .NET project?
Visual Studio often uses code generation to generate partial classes, and these files can be quite unwieldy. Let’s hide them.
Returns true or false
265 266 267 |
# File 'lib/linguist/generated.rb', line 265 def generated_net_designer_file? !!name.match(/\.designer\.(cs|vb)$/i) end |
#generated_net_docfile? ⇒ Boolean
Internal: Is this a generated documentation file for a .NET assembly?
.NET developers often check in the XML Intellisense file along with an assembly - however, these don’t have a special extension, so we have to dig into the contents to determine if it’s a docfile. Luckily, these files are extremely structured, so recognizing them is easy.
Returns true or false
248 249 250 251 252 253 254 255 256 257 |
# File 'lib/linguist/generated.rb', line 248 def generated_net_docfile? return false unless extname.downcase == ".xml" return false unless lines.count > 3 # .NET Docfiles always open with <doc> and their first tag is an # <assembly> tag return lines[1].include?("<doc>") && lines[2].include?("<assembly>") && lines[-2].include?("</doc>") end |
#generated_net_specflow_feature_file? ⇒ Boolean
Internal: Is this a codegen file for Specflow feature file?
Visual Studio’s SpecFlow extension generates *.feature.cs files from *.feature files, they are not meant to be consumed by humans. Let’s hide them.
Returns true or false
276 277 278 |
# File 'lib/linguist/generated.rb', line 276 def generated_net_specflow_feature_file? !!name.match(/\.feature\.cs$/i) end |
#generated_parser? ⇒ Boolean
Internal: Is the blob of JS a parser generated by PEG.js?
PEG.js-generated parsers are not meant to be consumed by humans.
Return true or false
285 286 287 288 289 290 291 292 293 294 295 |
# File 'lib/linguist/generated.rb', line 285 def generated_parser? return false unless extname == '.js' # PEG.js-generated parsers include a comment near the top of the file # that marks them as such. if lines[0..4].join('') =~ /^(?:[^\/]|\/[^\*])*\/\*(?:[^\*]|\*[^\/])*Generated by PEG.js/ return true end false end |
#generated_pascal_tlb? ⇒ Boolean
Internal: Is this a generated Delphi Interface file for a type library?
Delphi Type Library Import tool generates *_TLB.pas files based on .ridl files. They are not meant to be altered by humans.
Returns true or false
802 803 804 |
# File 'lib/linguist/generated.rb', line 802 def generated_pascal_tlb? !!name.match(/_tlb\.pas$/i) end |
#generated_perl_ppport_header? ⇒ Boolean
Internal: Is the file a generated Perl/Pollution/Portability header file?
Returns true or false.
685 686 687 688 689 |
# File 'lib/linguist/generated.rb', line 685 def generated_perl_ppport_header? return false unless name.match(/ppport\.h$/) return false unless lines.count > 10 return lines[8].include?("Automatically created by Devel::PPPort") end |
#generated_postscript? ⇒ Boolean
Internal: Is the blob of PostScript generated?
PostScript files are often generated by other programs. If they tell us so, we can detect them.
Returns true or false.
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
# File 'lib/linguist/generated.rb', line 303 def generated_postscript? return false unless ['.ps', '.eps', '.pfa'].include? extname # Type 1 and Type 42 fonts converted to PostScript are stored as hex-encoded byte streams; these # streams are always preceded the `eexec` operator (if Type 1), or the `/sfnts` key (if Type 42). return true if data =~ /^\s*(?:currentfile eexec\s+|\/sfnts\s+\[\s<)/ # We analyze the "%%Creator:" comment, which contains the author/generator # of the file. If there is one, it should be in one of the first few lines. creator = lines[0..9].find {|line| line =~ /^%%Creator: /} return false if creator.nil? # Most generators write their version number, while human authors' or companies' # names don't contain numbers. So look if the line contains digits. Also # look for some special cases without version numbers. return true if creator =~ /[0-9]|draw|mpage|ImageMagick|inkscape|MATLAB/ || creator =~ /PCBNEW|pnmtops|\(Unknown\)|Serif Affinity|Filterimage -tops/ # EAGLE doesn't include a version number when it generates PostScript. # However, it does prepend its name to the document's "%%Title" field. !!creator.include?("EAGLE") and lines[0..4].find {|line| line =~ /^%%Title: EAGLE Drawing /} end |
#generated_protocol_buffer? ⇒ Boolean
Internal: Is the blob a C++, Java or Python source file generated by the Protocol Buffer compiler?
Returns true or false.
350 351 352 353 354 355 |
# File 'lib/linguist/generated.rb', line 350 def generated_protocol_buffer? return false unless PROTOBUF_EXTENSIONS.include?(extname) return false unless lines.count > 1 return lines.first(3).any? { |l| l.include?("Generated by the protocol buffer compiler. DO NOT EDIT!") } end |
#generated_protocol_buffer_from_go? ⇒ Boolean
Internal: Is the blob a protocol buffer file generated by the go-to-protobuf tool?
Returns true or false
337 338 339 340 341 342 |
# File 'lib/linguist/generated.rb', line 337 def generated_protocol_buffer_from_go? return false unless extname == '.proto' return false unless lines.count > 1 return lines.first(20).any? { |l| l.include? "This file was autogenerated by go-to-protobuf" } end |
#generated_racc? ⇒ Boolean
Internal: Is this a Racc-generated file?
A Racc-generated file contains: # This file is automatically generated by Racc x.y.z on the third line.
Return true or false
587 588 589 590 591 |
# File 'lib/linguist/generated.rb', line 587 def generated_racc? return false unless extname == '.rb' return false unless lines.count > 2 return lines[2].start_with?("# This file is automatically generated by Racc") end |
#generated_roxygen2? ⇒ Boolean
Internal: Is this a roxygen2-generated file?
A roxygen2-generated file typically contain: % Generated by roxygen2: do not edit by hand on the first line.
Return true or false
627 628 629 630 631 632 |
# File 'lib/linguist/generated.rb', line 627 def generated_roxygen2? return false unless extname == '.Rd' return false unless lines.count > 1 return lines[0].include?("% Generated by roxygen2: do not edit by hand") end |
#generated_sorbet_rbi? ⇒ Boolean
Internal: Is this a Sorbet RBI file generated by Tapioca?
Tapioca generates non-human-editable .rbi files in several different ways:
-
‘tapioca gem` uses reflection to generate generic .rbi for gems.
-
‘tapioca dsl` uses DSL compilers to generate .rbi for modules/classes.
-
‘tapioca annotations` pulls .rbi from remote sources.
All are marked with similar wording.
Returns true or false
818 819 820 821 822 823 824 |
# File 'lib/linguist/generated.rb', line 818 def generated_sorbet_rbi? return false unless extname.downcase == '.rbi' return false unless lines.count >= 5 lines[0].match?(/^# typed:/) && lines[2].include?("DO NOT EDIT MANUALLY") && lines[4].match?(/^# Please (run|instead update this file by running) `bin\/tapioca/) end |
#generated_sqlx_query? ⇒ Boolean
Internal: Is this a generated SQLx query file?
SQLx is a Rust SQL library which generates ‘*/.sqlx/query-.json` files in offline mode (enabled by default).
These are used to be able to compile a project without requiring the development database to be online.
Returns true or false.
863 864 865 |
# File 'lib/linguist/generated.rb', line 863 def generated_sqlx_query? !!name.match(/(?:^|.*\/)\.sqlx\/query-.+\.json$/) end |
#generated_unity3d_meta? ⇒ Boolean
Internal: Is this a metadata file from Unity3D?
Unity3D Meta files start with:
fileFormatVersion: X
guid: XXXXXXXXXXXXXXX
Return true or false
574 575 576 577 578 |
# File 'lib/linguist/generated.rb', line 574 def return false unless extname == '.meta' return false unless lines.count > 1 return lines[0].include?("fileFormatVersion: ") end |
#generated_visualstudio6? ⇒ Boolean
Internal: Is this a generated Microsoft Visual Studio 6.0 build file?
Return true or false
728 729 730 731 |
# File 'lib/linguist/generated.rb', line 728 def generated_visualstudio6? return false unless extname.downcase == '.dsp' lines.first(3).any? { |l| l.include? '# Microsoft Developer Studio Generated Build File' } end |
#generated_yarn_plugnplay? ⇒ Boolean
Internal: Is the blob a generated Yarn Plug’n’Play?
Returns true or false.
449 450 451 |
# File 'lib/linguist/generated.rb', line 449 def generated_yarn_plugnplay? !!name.match(/(^|\/)\.pnp\..*$/) end |
#go_lock? ⇒ Boolean
Internal: Is the blob a generated Go dep or glide lock file?
Returns true or false.
407 408 409 |
# File 'lib/linguist/generated.rb', line 407 def go_lock? !!name.match(/(Gopkg|glide)\.lock/) end |
#go_vendor? ⇒ Boolean
Internal: Is the blob part of the Go vendor/ tree, not meant for humans in pull requests.
Returns true or false.
400 401 402 |
# File 'lib/linguist/generated.rb', line 400 def go_vendor? !!name.match(/vendor\/((?!-)[-0-9A-Za-z]+(?<!-)\.)+(com|edu|gov|in|me|net|org|fm|io)/) end |
#godeps? ⇒ Boolean
Internal: Is the blob part of Godeps/, which are not meant for humans in pull requests.
Returns true or false.
457 458 459 |
# File 'lib/linguist/generated.rb', line 457 def godeps? !!name.match(/Godeps\//) end |
#has_source_map? ⇒ Boolean
Internal: Does the blob contain a source-map reference?
We assume that if one of the last 2 lines starts with a source-map reference, then the current file was generated from other files.
We use the last 2 lines because the last line might be empty.
Returns true or false.
182 183 184 185 |
# File 'lib/linguist/generated.rb', line 182 def has_source_map? return false unless maybe_minified? lines.last(2).any? { |l| l.match(/^\/[*\/][\#@] source(?:Mapping)?URL|sourceURL=/) } end |
#htmlcov? ⇒ Boolean
Internal: Is this an HTML coverage report?
Tools like coverage.py generate HTML reports under an ‘htmlcov` directory.
Returns true or false.
831 832 833 |
# File 'lib/linguist/generated.rb', line 831 def htmlcov? !!name.match(/(?:^|\/)htmlcov\//) end |
#intellij_file? ⇒ Boolean
Internal: Is the blob an IntelliJ IDEA project file?
JetBrains IDEs generate project files under an ‘.idea` directory that are sometimes checked into version control.
Returns true or false.
133 134 135 |
# File 'lib/linguist/generated.rb', line 133 def intellij_file? !!name.match(/(?:^|\/)\.idea\//) end |
#lines ⇒ Object
Public: Get each line of data
Returns an Array of lines
39 40 41 42 |
# File 'lib/linguist/generated.rb', line 39 def lines # TODO: data should be required to be a String, no nils @lines ||= data ? data.split("\n", -1) : [] end |
#maybe_minified? ⇒ Boolean
Internal: Does extname indicate a filetype which is commonly minified?
Returns true or false.
154 155 156 |
# File 'lib/linguist/generated.rb', line 154 def maybe_minified? ['.js', '.css'].include? extname.downcase end |
#minified_files? ⇒ Boolean
Internal: Is the blob a minified file?
Consider a file minified if the average line length is greater then 110c.
Currently, only JS and CSS files are detected by this method.
Returns true or false.
166 167 168 169 170 171 172 |
# File 'lib/linguist/generated.rb', line 166 def minified_files? if maybe_minified? and lines.any? (lines.inject(0) { |n, l| n += l.length } / lines.length) > 110 else false end end |
#node_modules? ⇒ Boolean
Internal: Is the blob part of node_modules/, which are not meant for humans in pull requests.
Returns true or false.
392 393 394 |
# File 'lib/linguist/generated.rb', line 392 def node_modules? !!name.match(/node_modules\//) end |
#npm_shrinkwrap_or_package_lock? ⇒ Boolean
Internal: Is the blob a generated npm shrinkwrap or package lock file?
Returns true or false.
435 436 437 |
# File 'lib/linguist/generated.rb', line 435 def npm_shrinkwrap_or_package_lock? !!name.match(/npm-shrinkwrap\.json/) || !!name.match(/package-lock\.json/) end |
#pdm_lock? ⇒ Boolean
Internal: Is the blob a generated pdm.lock?
Returns true or false.
421 422 423 |
# File 'lib/linguist/generated.rb', line 421 def pdm_lock? !!name.match(/pdm\.lock/) end |
#pipenv_lock? ⇒ Boolean
Internal: Is this a Pipenv lock file?
Returns true or false.
538 539 540 |
# File 'lib/linguist/generated.rb', line 538 def pipenv_lock? !!name.match(/Pipfile\.lock/) end |
#pnpm_lock? ⇒ Boolean
Internal: Is the blob a generated pnpm lockfile?
Returns true or false.
442 443 444 |
# File 'lib/linguist/generated.rb', line 442 def pnpm_lock? !!name.match(/pnpm-lock\.yaml/) end |
#poetry_lock? ⇒ Boolean
Internal: Is the blob a generated poetry.lock?
Returns true or false.
414 415 416 |
# File 'lib/linguist/generated.rb', line 414 def poetry_lock? !!name.match(/poetry\.lock/) end |
#source_map? ⇒ Boolean
Internal: Is the blob a generated source-map?
Source-maps usually have .css.map or .js.map extensions. In case they are not following the name convention, detect them based on the content.
Returns true or false.
193 194 195 196 197 198 199 |
# File 'lib/linguist/generated.rb', line 193 def source_map? return false unless extname.downcase == '.map' name =~ /(\.css|\.js)\.map$/i || # Name convention lines[0] =~ /^{"version":\d+,/ || # Revision 2 and later begin with the version number lines[0] =~ /^\/\*\* Begin line maps\. \*\*\/{/ # Revision 1 begins with a magic comment end |
#terraform_lock? ⇒ Boolean
Internal: Is this a Terraform lock file?
Returns true or false.
545 546 547 |
# File 'lib/linguist/generated.rb', line 545 def terraform_lock? !!name.match(/(?:^|\/)\.terraform\.lock\.hcl$/) end |
#vcr_cassette? ⇒ Boolean
Is the blob a VCR Cassette file?
Returns true or false
506 507 508 509 510 511 |
# File 'lib/linguist/generated.rb', line 506 def vcr_cassette? return false unless extname == '.yml' return false unless lines.count > 2 # VCR Cassettes have "recorded_with: VCR" in the second last line. return lines[-2].include?("recorded_with: VCR") end |
#xcode_file? ⇒ Boolean
Internal: Is the blob an Xcode file?
Generated if the file extension is an Xcode file extension.
Returns true or false.
123 124 125 |
# File 'lib/linguist/generated.rb', line 123 def xcode_file? ['.nib', '.xcworkspacedata', '.xcuserstate'].include?(extname) end |