Skip to content

Commit

Permalink
Detect ts-proto generated files. (#7082)
Browse files Browse the repository at this point in the history
ts-proto [added generated code comments in May](stephenh/ts-proto#1037). This updates linguist to properly detect them.
  • Loading branch information
bobthecow authored Nov 25, 2024
1 parent c637573 commit 9150b62
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/linguist/generated.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def generated?
generated_protocol_buffer_from_go? ||
generated_protocol_buffer? ||
generated_javascript_protocol_buffer? ||
generated_typescript_protocol_buffer? ||
generated_apache_thrift? ||
generated_jni_header? ||
vcr_cassette? ||
Expand Down Expand Up @@ -367,6 +368,28 @@ def generated_javascript_protocol_buffer?
return lines[5].include?("GENERATED CODE -- DO NOT EDIT!")
end

# Internal: Is the blob a TypeScript source file generated by the
# Protocol Buffer compiler?
#
# Files generated by ts-proto typically start with something like this
# (though the versions lines are optional):
#
# // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
# // versions:
# // protoc-gen-ts_proto v1.181.2
# // protoc v5.28.2
# // source: hello.proto
#
# /* eslint-disable */
#
# Returns true or false.
def generated_typescript_protocol_buffer?
return false unless extname == ".ts"
return false unless lines.count > 4

return lines[0].include?("Code generated by protoc-gen-ts_proto. DO NOT EDIT.")
end

APACHE_THRIFT_EXTENSIONS = ['.rb', '.py', '.go', '.js', '.m', '.java', '.h', '.cc', '.cpp', '.php']

# Internal: Is the blob generated by Apache Thrift compiler?
Expand Down
113 changes: 113 additions & 0 deletions samples/TypeScript/proto.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/test_blob.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ def test_generated
assert sample_blob_memory("Go/embedded.go").generated?
assert sample_blob_memory("Go/oapi-codegen.go").generated?
assert sample_blob_memory("JavaScript/proto.js").generated?
assert sample_blob_memory("TypeScript/proto.ts").generated?
assert sample_blob_memory("PHP/ProtobufGenerated.php").generated?

# Apache Thrift generated code
Expand Down

0 comments on commit 9150b62

Please sign in to comment.