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
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
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
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
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
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
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
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
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
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
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
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