Skip to content

Print values for empty JSON fields in FileAnnotations #1930

@ymn64

Description

@ymn64

Problem

When we run buf lint --error-format=json on an empty proto file, we get the following JSON output:

{
  "path": "path/to/file.proto",
  "type": "PACKAGE_DEFINED",
  "message": "Files must have a package defined."
}
{
  "path": "path/to/file.proto",
  "type": "SYNTAX_SPECIFIED",
  "message": "Files must have a syntax explicitly specified. If no syntax is specified, the file defaults to \"proto2\"."
}

This output is missing 4 fields start_line, start_column, end_line and end_column which makes consuming this JSON by third party tools problematic as one may easily forget to check if these fields are not null before assigning them as numeric values.

Proposition

Add the missing fields with value 1 so that the output becomes:

{
  "path": "path/to/file.proto",
  "start_line": 1,
  "start_column": 1,
  "end_line": 1,
  "end_column": 1,
  "type": "PACKAGE_DEFINED",
  "message": "Files must have a package defined."
}
{
  "path": "path/to/file.proto",
  "start_line": 1,
  "start_column": 1,
  "end_line": 1,
  "end_column": 1,
  "type": "SYNTAX_SPECIFIED",
  "message": "Files must have a syntax explicitly specified. If no syntax is specified, the file defaults to \"proto2\"."
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions