Skip to content

Commit 34738f5

Browse files
committed
feat(extension,credo)!: configurable cli options and new default (#322)
Previously, we hard coded the `--strict --all` cli options, but these really shouldn't be the default. You can also now pass in the cli options you'd like to use.
1 parent 6fda39e commit 34738f5

File tree

4 files changed

+55
-14
lines changed

4 files changed

+55
-14
lines changed

lib/next_ls.ex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,8 @@ defmodule NextLS do
11011101

11021102
defmodule InitOpts.Extensions.Credo do
11031103
@moduledoc false
1104-
defstruct enable: true
1104+
defstruct enable: true,
1105+
cli_options: []
11051106
end
11061107

11071108
defmodule InitOpts.Extensions do
@@ -1136,7 +1137,8 @@ defmodule NextLS do
11361137
schema(NextLS.InitOpts.Extensions, %{
11371138
optional(:credo) =>
11381139
schema(NextLS.InitOpts.Extensions.Credo, %{
1139-
optional(:enable) => bool()
1140+
optional(:enable) => bool(),
1141+
optional(:cli_options) => list(str())
11401142
}),
11411143
optional(:elixir) =>
11421144
map(%{

lib/next_ls/extensions/credo_extension.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ defmodule NextLS.CredoExtension do
8888

8989
task =
9090
Task.Supervisor.async_nolink(state.task_supervisor, fn ->
91-
case Runtime.call(runtime, {:_next_ls_private_credo, :issues, [path]}) do
91+
case Runtime.call(runtime, {:_next_ls_private_credo, :issues, [state.settings.cli_options, path]}) do
9292
{:ok, issues} -> issues
9393
_error -> []
9494
end

priv/monkey/_next_ls_private_credo.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
defmodule :_next_ls_private_credo do
22
@moduledoc false
33

4-
def issues(dir) do
5-
["--strict", "--all", "--working-dir", dir]
4+
def issues(args, dir) do
5+
args
6+
|> Kernel.++(["--working-dir", dir])
67
|> Credo.run()
78
|> Credo.Execution.get_issues()
89
end

test/next_ls/extensions/credo_extension_test.exs

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ defmodule NextLS.CredoExtensionTest do
2323
File.write!(foo, """
2424
defmodule Foo do
2525
def run() do
26-
:ok
26+
dbg(:ok)
2727
end
2828
end
2929
""")
@@ -39,7 +39,7 @@ defmodule NextLS.CredoExtensionTest do
3939
setup :with_lsp
4040

4141
@tag init_options: %{"extensions" => %{"credo" => %{"enable" => false}}}
42-
test "disables Credo", %{client: client, foo: foo} = context do
42+
test "disables Credo", %{client: client} = context do
4343
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
4444

4545
assert_is_ready(context, "my_proj")
@@ -51,6 +51,44 @@ defmodule NextLS.CredoExtensionTest do
5151
}
5252
end
5353

54+
@tag init_options: %{"extensions" => %{"credo" => %{"cli_options" => ["--only", "warning"]}}}
55+
test "configures cli options", %{client: client, foo: foo} = context do
56+
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
57+
58+
assert_is_ready(context, "my_proj")
59+
assert_compiled(context, "my_proj")
60+
61+
assert_notification "window/logMessage", %{
62+
"message" => "[NextLS] [extension] Credo initializing with options" <> _,
63+
"type" => 4
64+
}
65+
66+
uri = uri(foo)
67+
68+
assert_notification "textDocument/publishDiagnostics", %{
69+
"uri" => ^uri,
70+
"diagnostics" => [
71+
%{
72+
"code" => "Credo.Check.Warning.Dbg",
73+
"codeDescription" => %{
74+
"href" => "https://hexdocs.pm/credo/Credo.Check.Warning.Dbg.html"
75+
},
76+
"data" => %{
77+
"check" => "Elixir.Credo.Check.Warning.Dbg",
78+
"file" => "lib/foo.ex"
79+
},
80+
"message" => "There should be no calls to dbg.",
81+
"range" => %{
82+
"end" => %{"character" => 999, "line" => 2},
83+
"start" => %{"character" => 4, "line" => 2}
84+
},
85+
"severity" => 2,
86+
"source" => "credo"
87+
}
88+
]
89+
}
90+
end
91+
5492
test "publishes credo diagnostics", %{client: client, foo: foo} = context do
5593
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
5694

@@ -69,20 +107,20 @@ defmodule NextLS.CredoExtensionTest do
69107
"uri" => ^uri,
70108
"diagnostics" => [
71109
%{
72-
"code" => "Credo.Check.Readability.ParenthesesOnZeroArityDefs",
110+
"code" => "Credo.Check.Warning.Dbg",
73111
"codeDescription" => %{
74-
"href" => "https://hexdocs.pm/credo/Credo.Check.Readability.ParenthesesOnZeroArityDefs.html"
112+
"href" => "https://hexdocs.pm/credo/Credo.Check.Warning.Dbg.html"
75113
},
76114
"data" => %{
77-
"check" => "Elixir.Credo.Check.Readability.ParenthesesOnZeroArityDefs",
115+
"check" => "Elixir.Credo.Check.Warning.Dbg",
78116
"file" => "lib/foo.ex"
79117
},
80-
"message" => "Do not use parentheses when defining a function which has no arguments.",
118+
"message" => "There should be no calls to dbg.",
81119
"range" => %{
82-
"end" => %{"character" => 999, "line" => 1},
83-
"start" => %{"character" => 0, "line" => 1}
120+
"end" => %{"character" => 999, "line" => 2},
121+
"start" => %{"character" => 4, "line" => 2}
84122
},
85-
"severity" => 3,
123+
"severity" => 2,
86124
"source" => "credo"
87125
},
88126
%{

0 commit comments

Comments
 (0)