Skip to content

Commit

Permalink
Improve json linter log readability (#39597)
Browse files Browse the repository at this point in the history
* feat: make json linter log easier to understand
* fix: fix astyle formatting in json formatter >.<
  • Loading branch information
nphyx authored Apr 16, 2020
1 parent 93c4a41 commit d67db55
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions tools/format/format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "getpost.h"

#include <unistd.h>
#include <cstdlib>
#include <fstream>
#include <functional>
Expand Down Expand Up @@ -212,14 +213,18 @@ int main( int argc, char *argv[] )
#ifdef MSYS2
erase_char( in_str, '\r' );
#endif
bool supports_color = isatty( STDOUT_FILENO );
std::string color_good = supports_color ? "\x1b[32m" : std::string();
std::string color_bad = supports_color ? "\x1b[31m" : std::string();
std::string color_end = supports_color ? "\x1b[0m" : std::string();
if( in_str == out.str() ) {
std::cout << "Unformatted " << filename << std::endl;
std::cout << color_good << "Well formatted: " << color_end << filename << std::endl;
exit( EXIT_SUCCESS );
} else {
std::ofstream fout( filename, std::ios::binary | std::ios::trunc );
fout << out.str();
fout.close();
std::cout << filename << " needs to be linted" << std::endl;
std::cout << color_bad << "Needs linting : " << color_end << filename << std::endl;
std::cout << "Please read doc/JSON_STYLE.md" << std::endl;
exit( EXIT_FAILURE );
}
Expand Down

0 comments on commit d67db55

Please sign in to comment.