Skip to content
This repository was archived by the owner on Mar 21, 2022. It is now read-only.

Commit a61b4c5

Browse files
committed
Initial commit
Create jsonc filetype for JSON with comments. Signed-off-by: Kevin Locke <[email protected]>
0 parents  commit a61b4c5

File tree

16 files changed

+399
-0
lines changed

16 files changed

+399
-0
lines changed

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Shared editor configuration <https://editorconfig.org>
2+
3+
# This is the top-most EditorConfig file which should apply to files below
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.vim]
12+
indent_size = 4
13+
indent_style = space

.gitattributes

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# gitattributes(5) file which defines repo-specific git attributes for paths
2+
3+
# Configure EOL handling in this repository to allow CRLF locally, commit LF:
4+
# https://help.github.com/articles/dealing-with-line-endings/
5+
# Set the default behavior, in case people don't have core.autocrlf set.
6+
* text=auto
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/sh
2+
#
3+
# Enforce hooks.allownonascii and core.whitespace configuration on commit.
4+
#
5+
# Copied from:
6+
# https://github.com/git/git/blob/v2.18.0/templates/hooks--pre-commit.sample
7+
8+
if git rev-parse --verify HEAD >/dev/null 2>&1
9+
then
10+
against=HEAD
11+
else
12+
# Initial commit: diff against an empty tree object
13+
against=$(git hash-object -t tree /dev/null)
14+
fi
15+
16+
# If you want to allow non-ASCII filenames set this variable to true.
17+
allownonascii=$(git config --bool hooks.allownonascii)
18+
19+
# Redirect output to stderr.
20+
exec 1>&2
21+
22+
# Cross platform projects tend to avoid non-ASCII filenames; prevent
23+
# them from being added to the repository. We exploit the fact that the
24+
# printable range starts at the space character and ends with tilde.
25+
if [ "$allownonascii" != "true" ] &&
26+
# Note that the use of brackets around a tr range is ok here, (it's
27+
# even required, for portability to Solaris 10's /usr/bin/tr), since
28+
# the square bracket bytes happen to fall in the designated range.
29+
test $(git diff --cached --name-only --diff-filter=A -z $against |
30+
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
31+
then
32+
cat <<\EOF
33+
Error: Attempt to add a non-ASCII file name.
34+
35+
This can cause problems if you want to work with people on other platforms.
36+
37+
To be portable it is advisable to rename the file.
38+
39+
If you know what you are doing you can disable this check using:
40+
41+
git config hooks.allownonascii true
42+
EOF
43+
exit 1
44+
fi
45+
46+
# If there are whitespace errors, print the offending file names and fail.
47+
exec git diff-index --check --cached $against --

.githooks/pre-commit/02-vint.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
# Run vint on changed .vim files
3+
4+
set -Ceu
5+
6+
if ! command -v vint >/dev/null ; then
7+
echo 'Warning: vint not installed. Skipping pre-commit check.' >&2
8+
exit
9+
fi
10+
11+
# Run vint on added/modified .vim files
12+
# Use -z to \0-separate and prevent quoting of special chars in filenames
13+
# Use tr+grep+tr to filter newline separated (could use --null-data for GNU)
14+
git diff -z --cached --name-only --diff-filter=AM |
15+
tr '\n\0' '\0\n' |
16+
grep -a '\.vim$' |
17+
tr '\0\n' '\n\0' |
18+
xargs -0r vint -s --

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Ignore build dependencies
2+
/build/

.travis.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Travis CI Configuration File
2+
# https://docs.travis-ci.com/user/customizing-the-build/
3+
4+
# vimscript is not currently supported. Use generic.
5+
# See https://github.com/travis-ci/travis-ci/issues/2867
6+
language: generic
7+
8+
# To test on OS X in addition to Linux, uncomment:
9+
# os:
10+
# - linux
11+
# - osx
12+
13+
script:
14+
- ./run-tests.sh
15+
16+
addons:
17+
apt:
18+
packages:
19+
- vim

LICENSE.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright 2015 Tim Byrne <[email protected]>
2+
Copyright 2019 Kevin Locke <[email protected]>
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to
6+
deal in the Software without restriction, including without limitation the
7+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8+
sell copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in
12+
all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20+
IN THE SOFTWARE.

README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
JSON with Comments for Vim
2+
==========================
3+
4+
[Vim](https://www.vim.org/) syntax highlighting plugin for JSON with C-style
5+
line (`//`) and block (`/* */`) comments.
6+
7+
It defines a filetype named `jsonc` (matching the name used in [VS
8+
Code](https://code.visualstudio.com/Docs/languages/json#_json-with-comments),
9+
a [Microsoft parser library](https://github.com/Microsoft/node-jsonc-parser),
10+
[.mocharc.jsonc](https://github.com/mochajs/mocha/pull/3760), and the [jsonc
11+
npm package](https://www.npmjs.com/package/jsonc)) which can be applied to
12+
files using [`set
13+
ft=jsonc`](https://vimhelp.org/options.txt.html#%27filetype%27) or a
14+
[modeline](https://vimhelp.org/options.txt.html#modeline).
15+
16+
17+
## Installation
18+
19+
This plugin can be installed in the usual ways:
20+
21+
### Using [Vim Packages](https://vimhelp.org/repeat.txt.html#packages)
22+
23+
```sh
24+
git checkout https://github.com/kevinoid/vim-jsonc.git ~/.vim/pack/git-plugins/start/vim-jsonc
25+
```
26+
27+
### Using [Pathogen](https://github.com/tpope/vim-pathogen)
28+
29+
```sh
30+
git checkout https://github.com/kevinoid/vim-jsonc.git ~/.vim/bundle/vim-jsonc
31+
```
32+
33+
### Using [Vundle](https://github.com/VundleVim/Vundle.vim)
34+
35+
Add the following to `.vimrc`:
36+
```vim
37+
Plugin 'kevinoid/vim-jsonc'
38+
```
39+
Then run `:PluginInstall`.
40+
41+
### Using [vim-plug](https://github.com/junegunn/vim-plug)
42+
43+
Add the following to `.vimrc` between `plug#begin()` and `plug#end()`:
44+
```vim
45+
Plug 'kevinoid/vim-jsonc'
46+
```
47+
48+
49+
## Implementation
50+
51+
This plugin loads the JSON syntax plugin, clears the syntax group for
52+
comments as errors, then defines additional syntax to match C-style comments.
53+
54+
This project was inspired by, and the code is based on,
55+
[elzr/vim-json#61](https://github.com/elzr/vim-json/pull/61) by
56+
[**@TheLocehiliosan**](https://github.com/TheLocehiliosan).
57+
58+
59+
## Contributing
60+
61+
Contributions are appreciated! Please add tests where possible and ensure
62+
`./run-tests.sh` passes.
63+
64+
If the desired change is large, complex, backwards-incompatible, can have
65+
significantly differing implementations, or may not be in scope for this
66+
project, opening an issue before writing the code can avoid frustration and
67+
save a lot of time and effort.
68+
69+
70+
## License
71+
72+
This package is available under the terms of the
73+
[MIT License](https://opensource.org/licenses/MIT).

ftdetect/jsonc.vim

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
augroup jsoncFtdetect
2+
" Recognize files with .jsonc extension
3+
autocmd BufNewFile,BufRead *.jsonc setfiletype jsonc
4+
5+
" Recognize some files known to support JSON with comments
6+
7+
" https://eslint.org/docs/user-guide/configuring
8+
autocmd BufNewFile,BufRead .eslintrc.json setlocal filetype=jsonc
9+
" https://jshint.com/docs/
10+
autocmd BufNewFile,BufRead .jshintrc setlocal filetype=jsonc
11+
" https://github.com/clutchski/coffeelint/pull/407
12+
autocmd BufNewFile,BufRead coffeelint.json setlocal filetype=jsonc
13+
" https://github.com/microsoft/TypeScript/pull/5450
14+
autocmd BufNewFile,BufRead tsconfig.json setlocal filetype=jsonc
15+
augroup END

ftplugin/jsonc.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
runtime ftplugin/json.vim

0 commit comments

Comments
 (0)