Skip to content

Commit

Permalink
warn about more missing comma errors
Browse files Browse the repository at this point in the history
see #34
  • Loading branch information
elzr committed Aug 22, 2014
1 parent bcf5c66 commit 6b5e003
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
26 changes: 22 additions & 4 deletions json-test.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
"semicolonAtEndOfThisObject":"trailingComma",
};

{
"object1": "missingComma"
"object2": "value"
}

// normative JSON examples from http://json.org/example.html

Expand Down Expand Up @@ -75,3 +71,25 @@
"onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
}
}}

//missing comma errors
{
"object1": "missingComma"
"object2": "value"
}
[
{ "object1": 1 }
{ "object2": 2 }
]
{
"object1": []
"object2": []
}
{
"object1": {}
"object2": []
}
{
"object1": true
"object2": 2
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Specific customizations
* Warn about *no-quotes* in keywords and *single-quotes* in keywords and values.
* Warn about *decimals* smaller than 1 that don't start with a 0 (`.1` gives a warning, it should be `0.1`).
* Warn about *comments* `//` and *trailing semicolons* `;`.
* Warn about *[missing commas](https://github.com/elzr/vim-json/issues/18)* between elements of an object.
* Warn about *[missing commas](https://github.com/elzr/vim-json/issues/18)* between elements of an object [and elsewhere](https://github.com/elzr/vim-json/issues/34).
* Warn about *trailing commas* after the last element in arrays or objects.
* (All warnings can be turned off with a `let g:vim_json_warnings=0` in your `vimrc`.)
* Recognize `.jsonp` file type. In [JSONP](http://stackoverflow.com/questions/2067472/what-is-jsonp-all-about), the wrapping function call at the beginning and the closing semicolon are recognized.
Expand Down
14 changes: 7 additions & 7 deletions syntax/json.vim
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ if (!exists("g:vim_json_warnings") || g:vim_json_warnings==1)
syn match jsonTrailingCommaError ",\_s*[}\]]"

" Syntax: Watch out for missing commas between elements
syn match jsonMissingCommaError /\("\|\d\)\zs\_s\+\ze"/
syn match jsonMissingCommaError /\("\|\]\|\d\)\zs\_s\+\ze"/
syn match jsonMissingCommaError /\(\]\|\}\)\_s\+\ze"/ "arrays/objects as values
syn match jsonMissingCommaError /}\_s\+\ze{/ "objects as elements in an array
syn match jsonMissingCommaError /\(true\|false\)\_s\+\ze"/ "true/false as value
endif

" ********************************************** END OF ERROR WARNINGS
Expand All @@ -80,15 +83,14 @@ syn match jsonPadding "\%^[[:blank:]\r\n]*[_$[:alpha:]][_$[:alnum:]]*[[:blank:]
syn match jsonPadding ");[[:blank:]\r\n]*\%$"

" Syntax: Boolean
syn keyword jsonBooleanTrue true
syn keyword jsonBooleanFalse false
syn match jsonBoolean /\(true\|false\)\(\_s\+\ze"\)\@!/

" Syntax: Null
syn keyword jsonNull null

" Syntax: Braces
syn region jsonFold matchgroup=jsonBraces start="{" end="}" transparent fold
syn region jsonFold matchgroup=jsonBraces start="\[" end="]" transparent fold
syn region jsonFold matchgroup=jsonBraces start="{" end=/}\(\_s\+\ze\("\|{\)\)\@!/ transparent fold
syn region jsonFold matchgroup=jsonBraces start="\[" end=/]\(\_s\+\ze"\)\@!/ transparent fold

" Define the default highlighting.
" For version 5.7 and earlier: only when not done already
Expand All @@ -107,8 +109,6 @@ if version >= 508 || !exists("did_json_syn_inits")
HiLink jsonNumber Number
HiLink jsonBraces Delimiter
HiLink jsonNull Function
HiLink jsonBooleanTrue jsonBoolean
HiLink jsonBooleanFalse jsonBoolean
HiLink jsonBoolean Boolean
HiLink jsonKeyword Label

Expand Down

0 comments on commit 6b5e003

Please sign in to comment.