Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(json): add json #26

Merged
merged 1 commit into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions lua/splitjoin/languages/json/defaults.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
local Node = require'splitjoin.util.node'

---@type SplitjoinLanguageConfig
return {

nodes = {

object = {
surround = { '{', '}' },
split = Node.split,
join = Node.join,
trailing_separator = false,
},

array = {
surround = { '[', ']' },
split = Node.split,
join = Node.join,
trailing_separator = false,
},

},

}
12 changes: 12 additions & 0 deletions lua/splitjoin/languages/json/options.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---@type SplitjoinLanguageConfig
return {

nodes = {

object = {
padding = ' ',
},

},

}
1 change: 1 addition & 0 deletions lua/splitjoin/util/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ local function get_defaults()
ecmascript = require'splitjoin.languages.ecmascript.defaults',
javascript = require'splitjoin.languages.javascript.defaults',
typescript = require'splitjoin.languages.typescript.defaults',
json = require'splitjoin.languages.json.defaults',
html = require'splitjoin.languages.html.defaults',
css = require'splitjoin.languages.css.defaults',
},
Expand Down
3 changes: 3 additions & 0 deletions queries/json/splitjoin.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
; collections
(object) @splitjoin.json.object
(array) @splitjoin.json.array
16 changes: 16 additions & 0 deletions test/fixtures/fixture.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"one": 1,
"two": 2,
"three": {
"four": 4,
"five": 5,
"six": [
1,
2,
[
3,
4
]
]
}
}
1 change: 1 addition & 0 deletions test/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function M.setup()
ensure_installed = {
'lua',
'css',
'json',
'javascript',
'typescript',
'html',
Expand Down
103 changes: 103 additions & 0 deletions test/json_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
local d = require'plenary.strings'.dedent

local H = require'test.helpers'

local lang = 'json'

describe(lang, function()

describe('object', function()
H.make_suite(lang,
'',
d[[
{ "one": 1, "two": 2, "three": 3 }
]],
d[[
{
"one": 1,
"two": 2,
"three": 3
}
]],
','
)

H.make_suite(lang,
'inner',
d[[
{ "one": 1, "two": 2, "three": { "four": 4, "five": 5 } }
]],
d[[
{ "one": 1, "two": 2, "three": {
"four": 4,
"five": 5
} }
]],
'4'
)

H.make_suite(lang,
'outer',
d[[
{ "one": 1, "two": 2, "three": { "four": 4, "five": 5 } }
]],
d[[
{
"one": 1,
"two": 2,
"three": { "four": 4, "five": 5 }
}
]],
'o'
)

end)

describe('array', function()

H.make_suite(lang,
'',
d[=[
[1, 2, 3]
]=],
d[=[
[
1,
2,
3
]
]=],
','
)

H.make_suite(lang,
'inner',
d[=[
[1, 2, [3, 4]]
]=],
d[=[
[1, 2, [
3,
4
]]
]=],
'3'
)

H.make_suite(lang,
'outer',
d[=[
[1, 2, [3, 4]]
]=],
d[=[
[
1,
2,
[3, 4]
]
]=],
'1'
)

end)
end)