12 Commits

Author SHA1 Message Date
Roger Luethi
e77e51365b Add final newline to file formatting
The JSON formatting created by jsoncheck.py omits the file's final
newline. It claims that files with such a newline need reformatting
and removes the final newline in a file when reformatting.

This patch brings jsoncheck.py in line with the rest of the tools
which prefer text files to end with a newline.

Update release notes for pushing out the bug fix.

Closes-Bug: #1403159
Change-Id: I35eab544b183c05b167ce9917d92f0f1f919b745
2014-12-16 22:02:24 +01:00
Roger Luethi
1192da60ee Use jsoncheck in doctest
This patch makes doctest use jsoncheck.

It offers:
- more helpful syntax error messages (courtesy of demjson)
- additional niceness checks for standardized formatting

Change-Id: Id92c43daeb6ee17ed03052b3c9b92cbf60f3f4a5
blueprint modularize-doctest
2014-10-21 10:23:53 +02:00
Roger Luethi
e43a8cd9e1 jsoncheck: set exit status if exception occured
This patch makes jsoncheck set the exit status to 1 if an exception
occured (i.e. if a syntax or formatting check failed).

This affects only the use of jsoncheck as a commandline tool.

Change-Id: Ibb38893b9c3010715c7112216b79b3b03c449992
2014-08-17 16:46:10 +02:00
Roger Luethi
eeadcf46dd jsoncheck: use ValueError to pass errors to outside callers
With this patch, errors that need to be passed back to external callers
are raised in ValueError.

The message indicating that a file has been successfully reformatted is
still directly printed for the CLI interface of jsoncheck. External
callers can choose to have that message printed by setting verbose=True.

blueprint modularize-doctest
Change-Id: I85071fe0e96c8787f14f9f9eb0b3c123e22e0c75
2014-08-13 10:16:22 +02:00
Roger Luethi
483122f1fd jsoncheck: indent strings only when printing them
In preparation for passing strings to external callers that do no expect
indented strings, call _indent_note only when strings are printed.

blueprint modularize-doctest
Change-Id: Ic8e27f213215d075f0d3248ea87b18294f0bbe83
2014-08-11 09:38:16 +02:00
Roger Luethi
b0a2f9818a jsoncheck: fix _indent_note for pre-formatted strings
Current versions of demjson return pre-formatted, pre-indented strings.
Line wrapping them results in strings that are harder to read.

With this patch, _indent_note splits strings into lines before indenting
and (if necessary) line wrapping them.

blueprint modularize-doctest
Change-Id: If7023f825c76bec16980dc84283da446c18a82b7
2014-08-06 15:46:41 +02:00
Roger Luethi
e75e7eeb36 jsoncheck: fix handling of formatting argument
Raise ValueError rather than returning it, add None as an allowed
value for the formatting option, and change the error/doc string
accordingly.

blueprint modularize-doctest
Change-Id: I6455c02dec3980f07984a884035b5ec41e8687e7
2014-08-06 15:46:35 +02:00
Roger Luethi
690507c39d Add a public interface to jsoncheck.py
blueprint modularize-doctest

Add to jsoncheck.py a public interface for external users (such as
doctest.py) to call. It consists of three functions:

check_syntax(path)
check_formatting(path)
fix_formatting(path)

Internal functions are renamed to have an underscore prefix.

Change-Id: I1ef6f389e97bb0b30382f165efae449bd0dfd50f
2014-06-20 20:10:30 +02:00
Roger Luethi
b69c648337 jsoncheck: make formatting check optional
blueprint modularize-doctest

doctest.py expects to enable syntax checks and formatting checks
individually. This patch changes jsoncheck.py to allow that.

The former boolean "format" argument becomes "formatting", a variable
that can be either "check" or "fix".

A ValueError is thrown if an invalid formatting argument is given to the
function (to be caught by external callers).

Change-Id: If57af0c6f0d46de69c0785635cd57c3a0995654e
2014-06-14 11:13:44 +02:00
Roger Luethi
7c43f2d360 remove jsoncheck's check_format()
blueprint modularize-doctest

The split between process_file (formerly main) and check_format resulted
in a function signature that had three parameters transport four pieces
of information (path indicated whether formatting should take place). The
function used an exception to return a custom warning message when JSON
files were not properly formatted.

This patch merges these two functions and splits out format_parsed_json
instead, which takes one argument and returns formatted JSON. This also
eliminates the FormattingException.

Change-Id: Ia15e862abe181909e4007817c97ceb6ce9e133e7
2014-06-10 07:54:58 +02:00
Roger Luethi
c1542b1a5e jsoncheck: split process_one_file from main
blueprint modularize-doctest

This patch moves most of the code from checkjson's main into a new
function process_file. External users of the module will have their
own filesystem walker, they just use the module to check/format a file
of interest.

Change-Id: I510b5d3d5ea20d2c0a694ef3401eb9fafc15bed4
2014-06-07 10:24:05 +02:00
Roger Luethi
3d61e98305 Add new script jsoncheck.py
Add a new script that can reformat JSON files and check for niceness.
We can use this later as niceness check for openstack-doc-test.

Change-Id: I33c5309bfa2e1abfa6a35d1cfcdc984775e85f05
2014-05-07 22:11:21 +02:00