Giter VIP home page Giter VIP logo

protofmt's Introduction

protofmt - Formatter for Protocol Buffer Files

๐Ÿ‘Ž ๐Ÿ‘
before after

Formatting Rules

  • Applies google's official protobuf style guide
  • Indentation with 2 spaces
  • Import groups are sorted alphabetically
  • Makes all string literals double quoted: option opt = 'foo'; => option opt = "foo";
  • Makes all enum fields uppercase: enum E { field = 1 } => enum E { FIELD = 1 }
  • Makes opening braces on the declaration line: message M {
  • Strips redundant semicolons: enum E { A = 0;;;; };;;; => enum E {A = 0;}
  • Full comment support

Installation

protofmt is written in Haskell, you can use cabal to install it.

git clone https://github.com/pabloariasal/protofmt.git
cd protofmt
cabal install

Usage

Just pass the file to be formatted:

protofmt <path_to_unformatted_proto_file>

Example:

$ cat unformatted.proto
syntax = 'proto3';
message M { string field = 1; };

$ protofmt unformatted.proto
syntax = "proto3";
message M {
  string field = 1;
}

$ protofmt unformatted.proto | tee formatted.proto
syntax = "proto3";
message M {
  string field = 1;
}

$ cat formatted.proto
syntax = "proto3";
message M {
  string field = 1;
}

Known Limitations (to be fixed soon)

Language

  • Only protobuf 3
  • inf and nan are not supported as floating point literals (PR welcome)
  • enum fields must be decimal literals (no hex, octal or binary) (PR welcome)
  • No service definitions (PR welcome)
  • No optional nor required keywords supported (PR welcome)

API

  • Only one file can be processed at once
  • No --in-place flag supported
  • No --recursive flag supported
  • No --diff flag to display a diff between formatted and unformatted file (status code 0 if no diff)

Contributing

protofmt's People

Contributors

pabloariasal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.