Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect go files as generated according to official rules #4821

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/linguist/generated.rb
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def generated_go?
return false unless extname == '.go'
return false unless lines.count > 1

return lines[0].include?("Code generated by")
return lines.first(10).any? { |l| l.include? "Code generated by" }
end

PROTOBUF_EXTENSIONS = ['.py', '.java', '.h', '.cc', '.cpp', '.m', '.rb']
Expand Down Expand Up @@ -605,7 +605,7 @@ def generated_gamemakerstudio?
return lines[2].match(/\"modelName\"\:\s*\"GM/) ||
lines[0] =~ /^\d\.\d\.\d.+\|\{/
end

# Internal: Is this a generated GIMP C image file?
#
# GIMP saves C sources with one of two comment forms:
Expand Down
50 changes: 50 additions & 0 deletions samples/Go/oapi-codegen.go

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 @@ -204,6 +204,7 @@ def test_generated
assert sample_blob_memory("Python/protocol_buffer_pb2.py").generated?
assert sample_blob_memory("Go/api.pb.go").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?

# Apache Thrift generated code
Expand Down
1 change: 1 addition & 0 deletions test/test_file_blob.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ def test_generated
assert sample_blob("Python/protocol_buffer_pb2.py").generated?
assert sample_blob("Go/api.pb.go").generated?
assert sample_blob("Go/embedded.go").generated?
assert sample_blob("Go/oapi-codegen.go").generated?

# Apache Thrift generated code
assert sample_blob("Python/gen-py-linguist-thrift.py").generated?
Expand Down