chore: use stylua for formatting (#1040)

* chore: stylua job and config

* reformat with stylua
This commit is contained in:
Simon Hauser
2021-07-23 17:42:37 +02:00
committed by GitHub
parent 664690029f
commit 79644ab677
75 changed files with 3201 additions and 2809 deletions

View File

@@ -1,70 +1,92 @@
local actions = require('telescope.actions')
local action_set = require('telescope.actions.set')
local actions = require "telescope.actions"
local action_set = require "telescope.actions.set"
local transform_mod = require('telescope.actions.mt').transform_mod
local transform_mod = require("telescope.actions.mt").transform_mod
local eq = function(a, b)
assert.are.same(a, b)
end
describe('actions', function()
it('should allow creating custom actions', function()
describe("actions", function()
it("should allow creating custom actions", function()
local a = transform_mod {
x = function() return 5 end,
x = function()
return 5
end,
}
eq(5, a.x())
end)
it('allows adding actions', function()
it("allows adding actions", function()
local a = transform_mod {
x = function() return "x" end,
y = function() return "y" end,
x = function()
return "x"
end,
y = function()
return "y"
end,
}
local x_plus_y = a.x + a.y
eq({"x", "y"}, {x_plus_y()})
eq({ "x", "y" }, { x_plus_y() })
end)
it('ignores nils from added actions', function()
it("ignores nils from added actions", function()
local a = transform_mod {
x = function() return "x" end,
y = function() return "y" end,
nil_maker = function() return nil end,
x = function()
return "x"
end,
y = function()
return "y"
end,
nil_maker = function()
return nil
end,
}
local x_plus_y = a.x + a.nil_maker + a.y
eq({"x", "y"}, {x_plus_y()})
eq({ "x", "y" }, { x_plus_y() })
end)
it('allows overriding an action', function()
it("allows overriding an action", function()
local a = transform_mod {
x = function() return "x" end,
y = function() return "y" end,
x = function()
return "x"
end,
y = function()
return "y"
end,
}
-- actions.file_goto_selection_edit:replace(...)
a.x:replace(function() return "foo" end)
a.x:replace(function()
return "foo"
end)
eq("foo", a.x())
a._clear()
eq("x", a.x())
end)
it('allows overriding an action only in specific cases with if', function()
it("allows overriding an action only in specific cases with if", function()
local a = transform_mod {
x = function(e) return e * 10 end,
y = function() return "y" end,
x = function(e)
return e * 10
end,
y = function()
return "y"
end,
}
-- actions.file_goto_selection_edit:replace(...)
a.x:replace_if(
function(e) return e > 0 end,
function(e) return (e / 10) end
)
a.x:replace_if(function(e)
return e > 0
end, function(e)
return (e / 10)
end)
eq(-100, a.x(-10))
eq(10, a.x(100))
eq(1, a.x(10))
@@ -73,16 +95,28 @@ describe('actions', function()
eq(100, a.x(10))
end)
it('allows overriding an action only in specific cases with mod', function()
it("allows overriding an action only in specific cases with mod", function()
local a = transform_mod {
x = function(e) return e * 10 end,
y = function() return "y" end,
x = function(e)
return e * 10
end,
y = function()
return "y"
end,
}
-- actions.file_goto_selection_edit:replace(...)
a.x:replace_map {
[function(e) return e > 0 end] = function(e) return (e / 10) end,
[function(e) return e == 0 end] = function(e) return (e + 10) end,
[function(e)
return e > 0
end] = function(e)
return (e / 10)
end,
[function(e)
return e == 0
end] = function(e)
return (e + 10)
end,
}
eq(-100, a.x(-10))
@@ -94,33 +128,51 @@ describe('actions', function()
eq(100, a.x(10))
end)
it('continuous replacement', function()
it("continuous replacement", function()
local a = transform_mod {
x = function() return "cleared" end,
y = function() return "y" end,
x = function()
return "cleared"
end,
y = function()
return "y"
end,
}
-- Replace original, which becomes new fallback
a.x:replace(function() return "negative" end)
a.x:replace(function()
return "negative"
end)
-- actions.file_goto_selection_edit:replace(...)
a.x:replace_map {
[function(e) return e > 0 end] = function(e) return "positive" end,
[function(e) return e == 0 end] = function(e) return "zero" end,
[function(e)
return e > 0
end] = function(e)
return "positive"
end,
[function(e)
return e == 0
end] = function(e)
return "zero"
end,
}
eq("positive", a.x(10))
eq("zero" , a.x(0))
eq("zero", a.x(0))
eq("negative", a.x(-10))
a._clear()
eq("cleared", a.x(10))
end)
it('enhance.pre', function()
it("enhance.pre", function()
local a = transform_mod {
x = function() return "x" end,
y = function() return "y" end,
x = function()
return "x"
end,
y = function()
return "y"
end,
}
local called_pre = false
@@ -134,10 +186,14 @@ describe('actions', function()
eq(true, called_pre)
end)
it('enhance.post', function()
it("enhance.post", function()
local a = transform_mod {
x = function() return "x" end,
y = function() return "y" end,
x = function()
return "x"
end,
y = function()
return "y"
end,
}
local called_post = false
@@ -151,10 +207,14 @@ describe('actions', function()
eq(true, called_post)
end)
it('can call both', function()
it("can call both", function()
local a = transform_mod {
x = function() return "x" end,
y = function() return "y" end,
x = function()
return "x"
end,
y = function()
return "y"
end,
}
local called_count = 0
@@ -171,10 +231,14 @@ describe('actions', function()
eq(2, called_count)
end)
it('can call both even when combined', function()
it("can call both even when combined", function()
local a = transform_mod {
x = function() return "x" end,
y = function() return "y" end,
x = function()
return "x"
end,
y = function()
return "y"
end,
}
local called_count = 0
@@ -188,7 +252,7 @@ describe('actions', function()
}
a.x:enhance {
post = count_inc
post = count_inc,
}
local x_plus_y = a.x + a.y
@@ -197,10 +261,14 @@ describe('actions', function()
eq(3, called_count)
end)
it('clears enhance', function()
it("clears enhance", function()
local a = transform_mod {
x = function() return "x" end,
y = function() return "y" end,
x = function()
return "x"
end,
y = function()
return "y"
end,
}
local called_post = false
@@ -217,31 +285,41 @@ describe('actions', function()
eq(false, called_post)
end)
it('handles passing arguments', function()
it("handles passing arguments", function()
local a = transform_mod {
x = function(bufnr) return string.format("bufnr: %s") end,
x = function(bufnr)
return string.format "bufnr: %s"
end,
}
a.x:replace(function(bufnr) return string.format("modified: %s", bufnr) end)
a.x:replace(function(bufnr)
return string.format("modified: %s", bufnr)
end)
eq("modified: 5", a.x(5))
end)
describe('action_set', function()
it('can replace `action_set.edit`', function()
action_set.edit:replace(function(_, arg) return "replaced:" .. arg end)
describe("action_set", function()
it("can replace `action_set.edit`", function()
action_set.edit:replace(function(_, arg)
return "replaced:" .. arg
end)
eq("replaced:edit", actions.file_edit())
eq("replaced:vnew", actions.file_vsplit())
end)
it('handles backwards compat with select and edit files', function()
it("handles backwards compat with select and edit files", function()
-- Reproduce steps:
-- In config, we have { ["<CR>"] = actions.select, ... }
-- In caller, we have actions._goto:replace(...)
-- Person calls `select`, does not see update
action_set.edit:replace(function(_, arg) return "default_to_edit:" .. arg end)
action_set.edit:replace(function(_, arg)
return "default_to_edit:" .. arg
end)
eq("default_to_edit:edit", actions.select_default())
action_set.select:replace(function(_, arg) return "override_with_select:" .. arg end)
action_set.select:replace(function(_, arg)
return "override_with_select:" .. arg
end)
eq("override_with_select:default", actions.select_default())
-- Sometimes you might want to change the default selection...