Remove unnecessary specs for funs with default arguments (#6095)

The command used to detect these lines is:
$ ag "(\@spec\s+[a-zA-Z0-9_?!]+\()[^\n]*\s*\1" -A2
This commit is contained in:
Eksperimental
2017-05-14 21:32:43 +02:00
committed by José Valim
parent 9747e58db7
commit 6a2cfef1a2
11 changed files with 4 additions and 34 deletions
-15
View File
@@ -170,7 +170,6 @@ defmodule Base do
"666f6f626172"
"""
@spec encode16(binary) :: binary
@spec encode16(binary, Keyword.t) :: binary
def encode16(data, opts \\ []) when is_binary(data) do
case = Keyword.get(opts, :case, :upper)
@@ -204,7 +203,6 @@ defmodule Base do
{:ok, "foobar"}
"""
@spec decode16(binary) :: {:ok, binary} | :error
@spec decode16(binary, Keyword.t) :: {:ok, binary} | :error
def decode16(string, opts \\ []) do
{:ok, decode16!(string, opts)}
@@ -242,7 +240,6 @@ defmodule Base do
"foobar"
"""
@spec decode16!(binary) :: binary
@spec decode16!(binary, Keyword.t) :: binary
def decode16!(string, opts \\ [])
@@ -273,7 +270,6 @@ defmodule Base do
"Zm9vYg"
"""
@spec encode64(binary) :: binary
@spec encode64(binary, Keyword.t) :: binary
def encode64(data, opts \\ []) when is_binary(data) do
pad? = Keyword.get(opts, :padding, true)
@@ -304,7 +300,6 @@ defmodule Base do
{:ok, "foob"}
"""
@spec decode64(binary) :: {:ok, binary} | :error
@spec decode64(binary, Keyword.t) :: {:ok, binary} | :error
def decode64(string, opts \\ []) when is_binary(string) do
{:ok, decode64!(string, opts)}
@@ -339,7 +334,6 @@ defmodule Base do
"foob"
"""
@spec decode64!(binary) :: binary
@spec decode64!(binary, Keyword.t) :: binary
def decode64!(string, opts \\ []) when is_binary(string) do
pad? = Keyword.get(opts, :padding, true)
@@ -362,7 +356,6 @@ defmodule Base do
"_3_-_A"
"""
@spec url_encode64(binary) :: binary
@spec url_encode64(binary, Keyword.t) :: binary
def url_encode64(data, opts \\ []) when is_binary(data) do
pad? = Keyword.get(opts, :padding, true)
@@ -391,7 +384,6 @@ defmodule Base do
{:ok, <<255, 127, 254, 252>>}
"""
@spec url_decode64(binary) :: {:ok, binary} | :error
@spec url_decode64(binary, Keyword.t) :: {:ok, binary} | :error
def url_decode64(string, opts \\ []) when is_binary(string) do
{:ok, url_decode64!(string, opts)}
@@ -424,7 +416,6 @@ defmodule Base do
<<255, 127, 254, 252>>
"""
@spec url_decode64!(binary) :: binary
@spec url_decode64!(binary, Keyword.t) :: binary
def url_decode64!(string, opts \\ []) when is_binary(string) do
pad? = Keyword.get(opts, :padding, true)
@@ -463,7 +454,6 @@ defmodule Base do
"MZXW6YTBOI"
"""
@spec encode32(binary) :: binary
@spec encode32(binary, Keyword.t) :: binary
def encode32(data, opts \\ []) when is_binary(data) do
case = Keyword.get(opts, :case, :upper)
@@ -507,7 +497,6 @@ defmodule Base do
{:ok, "foobar"}
"""
@spec decode32(binary) :: {:ok, binary} | :error
@spec decode32(binary, Keyword.t) :: {:ok, binary} | :error
def decode32(string, opts \\ []) do
{:ok, decode32!(string, opts)}
@@ -554,7 +543,6 @@ defmodule Base do
"foobar"
"""
@spec decode32!(binary) :: binary
@spec decode32!(binary, Keyword.t) :: binary
def decode32!(string, opts \\ []) when is_binary(string) do
case = Keyword.get(opts, :case, :upper)
@@ -595,7 +583,6 @@ defmodule Base do
"CPNMUOJ1E8"
"""
@spec hex_encode32(binary) :: binary
@spec hex_encode32(binary, Keyword.t) :: binary
def hex_encode32(data, opts \\ []) when is_binary(data) do
case = Keyword.get(opts, :case, :upper)
@@ -640,7 +627,6 @@ defmodule Base do
{:ok, "foobar"}
"""
@spec hex_decode32(binary) :: {:ok, binary} | :error
@spec hex_decode32(binary, Keyword.t) :: {:ok, binary} | :error
def hex_decode32(string, opts \\ []) do
{:ok, hex_decode32!(string, opts)}
@@ -688,7 +674,6 @@ defmodule Base do
"foobar"
"""
@spec hex_decode32!(binary) :: binary
@spec hex_decode32!(binary, Keyword.t) :: binary
def hex_decode32!(string, opts \\ []) when is_binary(string) do
case = Keyword.get(opts, :case, :upper)
-3
View File
@@ -226,7 +226,6 @@ defmodule Enum do
false
"""
@spec all?(t) :: boolean
@spec all?(t, (element -> as_boolean(term))) :: boolean
def all?(enumerable, fun \\ fn(x) -> x end)
@@ -264,7 +263,6 @@ defmodule Enum do
true
"""
@spec any?(t) :: boolean
@spec any?(t, (element -> as_boolean(term))) :: boolean
def any?(enumerable, fun \\ fn(x) -> x end)
@@ -2650,7 +2648,6 @@ defmodule Enum do
[a: 3, b: 4, c: 5]
"""
@spec with_index(t) :: [{element, index}]
@spec with_index(t, integer) :: [{element, index}]
def with_index(enumerable, offset \\ 0) do
map_reduce(enumerable, offset, fn x, acc ->
-1
View File
@@ -174,7 +174,6 @@ defmodule Keyword do
3
"""
@spec get(t, key) :: value
@spec get(t, key, value) :: value
def get(keywords, key, default \\ nil) when is_list(keywords) and is_atom(key) do
case :lists.keyfind(key, 1, keywords) do
-2
View File
@@ -504,7 +504,6 @@ defmodule Macro do
1
"""
@spec escape(term) :: Macro.t
@spec escape(term, Keyword.t) :: Macro.t
def escape(expr, opts \\ []) do
elem(:elixir_quote.escape(expr, Keyword.get(opts, :unquote, false)), 0)
@@ -682,7 +681,6 @@ defmodule Macro do
"one + two"
"""
@spec to_string(Macro.t) :: String.t
@spec to_string(Macro.t, (Macro.t, String.t -> String.t)) :: String.t
def to_string(tree, fun \\ fn(_ast, string) -> string end)
-1
View File
@@ -398,7 +398,6 @@ defmodule Map do
3
"""
@spec get(map, key) :: value
@spec get(map, key, value) :: value
def get(map, key, default \\ nil) do
case fetch(map, key) do
-2
View File
@@ -40,7 +40,6 @@ defmodule Process do
Returns the value for the given `key` in the process dictionary,
or `default` if `key` is not set.
"""
@spec get(term) :: term
@spec get(term, default :: term) :: term
def get(key, default \\ nil) do
case :erlang.get(key) do
@@ -399,7 +398,6 @@ defmodule Process do
Inlined by the compiler.
"""
@spec demonitor(reference) :: true
@spec demonitor(reference, options :: [:flush | :info]) :: boolean
defdelegate demonitor(monitor_ref, options \\ []), to: :erlang
-2
View File
@@ -155,7 +155,6 @@ defmodule Stream do
[[1, 2, 3], [4, 5, 6]]
"""
@spec chunk(Enumerable.t, pos_integer, pos_integer) :: Enumerable.t
@spec chunk(Enumerable.t, pos_integer, pos_integer, Enumerable.t | nil) :: Enumerable.t
def chunk(enum, n, step, leftover \\ nil)
when is_integer(n) and n > 0 and is_integer(step) and step > 0 do
@@ -954,7 +953,6 @@ defmodule Stream do
[{1, 3}, {2, 4}, {3, 5}]
"""
@spec with_index(Enumerable.t) :: Enumerable.t
@spec with_index(Enumerable.t, integer) :: Enumerable.t
def with_index(enum, offset \\ 0) do
lazy enum, offset, fn(f1) -> R.with_index(f1) end
-1
View File
@@ -347,7 +347,6 @@ defmodule String do
["1", "2", "3", "4"]
"""
@spec split(t, pattern | Regex.t) :: [t]
@spec split(t, pattern | Regex.t, Keyword.t) :: [t]
def split(string, pattern, options \\ [])
-1
View File
@@ -318,7 +318,6 @@ defmodule Supervisor do
name, the supported values are described in the "Name registration"
section in the `GenServer` module docs.
"""
@spec start_link(module, term) :: on_start
@spec start_link(module, term, options) :: on_start
def start_link(module, arg, options \\ []) when is_list(options) do
case Keyword.get(options, :name) do
-2
View File
@@ -462,7 +462,6 @@ defmodule System do
System.halt(:abort)
"""
@spec halt() :: no_return
@spec halt(non_neg_integer | binary | :abort) :: no_return
def halt(status \\ 0)
@@ -494,7 +493,6 @@ defmodule System do
System.stop(1)
"""
@spec stop() :: no_return
@spec stop(non_neg_integer | binary) :: no_return
def stop(status \\ 0)
+4 -4
View File
@@ -188,16 +188,16 @@ defmodule IEx.HelpersTest do
assert capture_io(fn -> s IEx.Remsh end) == "No specification for IEx.Remsh was found\n"
# Test that it shows at least two specs
assert Enum.count(capture_io(fn -> s Enum end) |> String.split("\n"), fn line ->
assert Enum.count(capture_io(fn -> s Process end) |> String.split("\n"), fn line ->
String.starts_with? line, "@spec"
end) >= 2
assert Enum.count(capture_io(fn -> s Enum.all? end) |> String.split("\n"), fn line ->
assert Enum.count(capture_io(fn -> s Process.demonitor end) |> String.split("\n"), fn line ->
String.starts_with? line, "@spec"
end) >= 2
assert capture_io(fn -> s Enum.all?/1 end) ==
"@spec all?(t()) :: boolean()\n"
assert capture_io(fn -> s Process.register/2 end) ==
"@spec register(pid() | port(), atom()) :: true\n"
assert capture_io(fn -> s struct end) ==
"@spec struct(module() | struct(), Enum.t()) :: struct()\n"
end