Skip to content

Commit

Permalink
vendor Dialyxir
Browse files Browse the repository at this point in the history
This prevents module conflicts with the user's version of Dialyxir (and Dialyzex) since
both are loaded into the same beam instance
  • Loading branch information
lukaszsamson committed Oct 30, 2022
1 parent 1de32e1 commit b610d1a
Show file tree
Hide file tree
Showing 90 changed files with 462 additions and 464 deletions.
2 changes: 0 additions & 2 deletions .tool-versions

This file was deleted.

4 changes: 2 additions & 2 deletions lib/dialyxir.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Dialyxir do
defmodule DialyxirVendored do
@moduledoc false
use Application
alias Dialyxir.Output
alias DialyxirVendored.Output

def start(_, _) do
Output.info("""
Expand Down
26 changes: 13 additions & 13 deletions lib/dialyxir/dialyzer.ex
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
defmodule Dialyxir.Dialyzer do
import Dialyxir.Output, only: [color: 2, info: 1]
defmodule DialyxirVendored.Dialyzer do
import DialyxirVendored.Output, only: [color: 2, info: 1]
alias String.Chars
alias Dialyxir.Formatter
alias Dialyxir.Project
alias Dialyxir.FilterMap
alias DialyxirVendored.Formatter
alias DialyxirVendored.Project
alias DialyxirVendored.FilterMap

defmodule Runner do
@dialyxir_args [
Expand All @@ -20,28 +20,28 @@ defmodule Dialyxir.Dialyzer do
formatter =
cond do
split[:format] == "dialyzer" ->
Dialyxir.Formatter.Dialyzer
DialyxirVendored.Formatter.Dialyzer

split[:format] == "dialyxir" ->
Dialyxir.Formatter.Dialyxir
DialyxirVendored.Formatter.DialyxirVendored

split[:format] == "github" ->
Dialyxir.Formatter.Github
DialyxirVendored.Formatter.Github

split[:format] == "ignore_file" ->
Dialyxir.Formatter.IgnoreFile
DialyxirVendored.Formatter.IgnoreFile

split[:format] == "raw" ->
Dialyxir.Formatter.Raw
DialyxirVendored.Formatter.Raw

split[:format] == "short" ->
Dialyxir.Formatter.Short
DialyxirVendored.Formatter.Short

split[:raw] ->
Dialyxir.Formatter.Raw
DialyxirVendored.Formatter.Raw

true ->
Dialyxir.Formatter.Dialyxir
DialyxirVendored.Formatter.DialyxirVendored
end

info("Starting Dialyzer")
Expand Down
2 changes: 1 addition & 1 deletion lib/dialyxir/filter_map.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Dialyxir.FilterMap do
defmodule DialyxirVendored.FilterMap do
@moduledoc """
A counters holding warnings to be skipped.
Expand Down
12 changes: 6 additions & 6 deletions lib/dialyxir/formatter.ex
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
defmodule Dialyxir.Formatter do
defmodule DialyxirVendored.Formatter do
@moduledoc """
Elixir-friendly dialyzer formatter.
Wrapper around normal Dialyzer warning messages that provides
example output for error messages.
"""
import Dialyxir.Output, only: [info: 1]
import DialyxirVendored.Output, only: [info: 1]

alias Dialyxir.FilterMap
alias DialyxirVendored.FilterMap

@type warning() :: {tag :: term(), {file :: Path.t(), line :: pos_integer()}, {atom(), list()}}

Expand Down Expand Up @@ -96,11 +96,11 @@ defmodule Dialyxir.Formatter do
end

defp filter_warning(filterer, warning = {_, {file, line}, {warning_type, _}}, filter_map) do
if Map.has_key?(Dialyxir.Warnings.warnings(), warning_type) do
if Map.has_key?(DialyxirVendored.Warnings.warnings(), warning_type) do
{skip?, matching_filters} =
try do
filterer.filter_warning?(
{to_string(file), warning_type, line, Dialyxir.Formatter.Short.format(warning)},
{to_string(file), warning_type, line, DialyxirVendored.Formatter.Short.format(warning)},
filter_map
)
rescue
Expand Down Expand Up @@ -130,7 +130,7 @@ defmodule Dialyxir.Formatter do
Enum.reject(warnings, fn warning ->
formatted_warnings =
warning
|> Dialyxir.Formatter.Dialyzer.format()
|> DialyxirVendored.Formatter.Dialyzer.format()
|> List.wrap()

Enum.empty?(filterer.filter_legacy_warnings(formatted_warnings))
Expand Down
10 changes: 5 additions & 5 deletions lib/dialyxir/formatter/dialyxir.ex
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
defmodule Dialyxir.Formatter.Dialyxir do
defmodule DialyxirVendored.Formatter.DialyxirVendored do
@moduledoc false

@behaviour Dialyxir.Formatter
@behaviour DialyxirVendored.Formatter

@impl Dialyxir.Formatter
@impl DialyxirVendored.Formatter
def format(dialyzer_warning = {_tag, {file, line}, message}) do
{warning_name, arguments} = message
base_name = Path.relative_to_cwd(file)
Expand Down Expand Up @@ -76,12 +76,12 @@ defmodule Dialyxir.Formatter.Dialyxir do
#{message}
Legacy warning:
#{Dialyxir.Formatter.Dialyzer.format(warning)}
#{DialyxirVendored.Formatter.Dialyzer.format(warning)}
"""
end

defp warning(warning_name) do
warnings = Dialyxir.Warnings.warnings()
warnings = DialyxirVendored.Warnings.warnings()

if Map.has_key?(warnings, warning_name) do
Map.get(warnings, warning_name)
Expand Down
6 changes: 3 additions & 3 deletions lib/dialyxir/formatter/dialyzer.ex
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
defmodule Dialyxir.Formatter.Dialyzer do
defmodule DialyxirVendored.Formatter.Dialyzer do
@moduledoc false

@behaviour Dialyxir.Formatter
@behaviour DialyxirVendored.Formatter

@impl Dialyxir.Formatter
@impl DialyxirVendored.Formatter
def format(warning) do
# OTP 22 uses indented output, but that's incompatible with dialyzer.ignore-warnings format.
# Can be disabled, but OTP 21 and older only accept an atom, so only disable on OTP 22+.
Expand Down
8 changes: 4 additions & 4 deletions lib/dialyxir/formatter/github.ex
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
defmodule Dialyxir.Formatter.Github do
defmodule DialyxirVendored.Formatter.Github do
@moduledoc false

@behaviour Dialyxir.Formatter
@behaviour DialyxirVendored.Formatter

@impl Dialyxir.Formatter
@impl DialyxirVendored.Formatter
def format({_tag, {file, line}, {warning_name, arguments}}) do
base_name = Path.relative_to_cwd(file)

Expand All @@ -14,7 +14,7 @@ defmodule Dialyxir.Formatter.Github do
end

defp warning(warning_name) do
warnings = Dialyxir.Warnings.warnings()
warnings = DialyxirVendored.Warnings.warnings()

if Map.has_key?(warnings, warning_name) do
Map.get(warnings, warning_name)
Expand Down
6 changes: 3 additions & 3 deletions lib/dialyxir/formatter/ignore_file.ex
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
defmodule Dialyxir.Formatter.IgnoreFile do
defmodule DialyxirVendored.Formatter.IgnoreFile do
@moduledoc false

@behaviour Dialyxir.Formatter
@behaviour DialyxirVendored.Formatter

@impl Dialyxir.Formatter
@impl DialyxirVendored.Formatter
def format({_tag, {file, _line}, {warning_name, _arguments}}) do
~s({"#{file}", :#{warning_name}},)
end
Expand Down
6 changes: 3 additions & 3 deletions lib/dialyxir/formatter/raw.ex
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
defmodule Dialyxir.Formatter.Raw do
defmodule DialyxirVendored.Formatter.Raw do
@moduledoc false

@behaviour Dialyxir.Formatter
@behaviour DialyxirVendored.Formatter

@impl Dialyxir.Formatter
@impl DialyxirVendored.Formatter
def format(warning) do
inspect(warning, limit: :infinity)
end
Expand Down
8 changes: 4 additions & 4 deletions lib/dialyxir/formatter/short.ex
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
defmodule Dialyxir.Formatter.Short do
defmodule DialyxirVendored.Formatter.Short do
@moduledoc false

@behaviour Dialyxir.Formatter
@behaviour DialyxirVendored.Formatter

@impl Dialyxir.Formatter
@impl DialyxirVendored.Formatter
def format({_tag, {file, line}, {warning_name, arguments}}) do
base_name = Path.relative_to_cwd(file)

Expand All @@ -14,7 +14,7 @@ defmodule Dialyxir.Formatter.Short do
end

defp warning(warning_name) do
warnings = Dialyxir.Warnings.warnings()
warnings = DialyxirVendored.Warnings.warnings()

if Map.has_key?(warnings, warning_name) do
Map.get(warnings, warning_name)
Expand Down
2 changes: 1 addition & 1 deletion lib/dialyxir/output.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Dialyxir.Output do
defmodule DialyxirVendored.Output do
alias IO.ANSI

def color(text, color) when is_binary(text) do
Expand Down
6 changes: 3 additions & 3 deletions lib/dialyxir/plt.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# Copyright by James Fish
# https://github.com/fishcakez/dialyze

defmodule Dialyxir.Plt do
defmodule DialyxirVendored.Plt do
@moduledoc false

import Dialyxir.Output
alias Dialyxir.Formatter
import DialyxirVendored.Output
alias DialyxirVendored.Formatter

def check(plts, fun \\ &check_plt/4) do
find_plts(plts, [], fun)
Expand Down
12 changes: 6 additions & 6 deletions lib/dialyxir/project.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
defmodule Dialyxir.Project do
defmodule DialyxirVendored.Project do
@moduledoc false
import Dialyxir.Output, only: [info: 1, error: 1]
import DialyxirVendored.Output, only: [info: 1, error: 1]

alias Dialyxir.FilterMap
alias DialyxirVendored.FilterMap

def plts_list(deps, include_project \\ true, exclude_core \\ false) do
elixir_apps = [:elixir]
Expand Down Expand Up @@ -33,7 +33,7 @@ defmodule Dialyxir.Project do
def check_config do
if is_binary(dialyzer_config()[:plt_file]) do
info("""
Notice: :plt_file is deprecated as Dialyxir now uses project-private PLT files by default.
Notice: :plt_file is deprecated as DialyxirVendored now uses project-private PLT files by default.
If you want to use this setting without seeing this warning, provide it in a pair
with the :no_warn key e.g. `dialyzer: plt_file: {:no_warn, "~/mypltfile"}`
""")
Expand Down Expand Up @@ -295,7 +295,7 @@ defmodule Dialyxir.Project do

:project ->
info(
"Dialyxir has deprecated plt_add_deps: :project in favor of apps_direct, which includes only runtime dependencies."
"DialyxirVendored has deprecated plt_add_deps: :project in favor of apps_direct, which includes only runtime dependencies."
)

deps_project() ++ deps_app(false)
Expand All @@ -305,7 +305,7 @@ defmodule Dialyxir.Project do

:transitive ->
info(
"Dialyxir has deprecated plt_add_deps: :transitive in favor of app_tree, which includes only runtime dependencies."
"DialyxirVendored has deprecated plt_add_deps: :transitive in favor of app_tree, which includes only runtime dependencies."
)

deps_transitive() ++ deps_app(true)
Expand Down
2 changes: 1 addition & 1 deletion lib/dialyxir/warning.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Dialyxir.Warning do
defmodule DialyxirVendored.Warning do
@moduledoc """
Behaviour for defining warning semantics.
Expand Down
2 changes: 1 addition & 1 deletion lib/dialyxir/warning_helpers.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Dialyxir.WarningHelpers do
defmodule DialyxirVendored.WarningHelpers do
@spec ordinal(non_neg_integer) :: String.t()
def ordinal(1), do: "1st"
def ordinal(2), do: "2nd"
Expand Down
94 changes: 47 additions & 47 deletions lib/dialyxir/warnings.ex
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
defmodule Dialyxir.Warnings do
defmodule DialyxirVendored.Warnings do
@warnings Enum.into(
[
Dialyxir.Warnings.AppCall,
Dialyxir.Warnings.Apply,
Dialyxir.Warnings.BinaryConstruction,
Dialyxir.Warnings.Call,
Dialyxir.Warnings.CallToMissingFunction,
Dialyxir.Warnings.CallWithOpaque,
Dialyxir.Warnings.CallWithoutOpaque,
Dialyxir.Warnings.CallbackArgumentTypeMismatch,
Dialyxir.Warnings.CallbackInfoMissing,
Dialyxir.Warnings.CallbackMissing,
Dialyxir.Warnings.CallbackNotExported,
Dialyxir.Warnings.CallbackSpecArgumentTypeMismatch,
Dialyxir.Warnings.CallbackSpecTypeMismatch,
Dialyxir.Warnings.CallbackTypeMismatch,
Dialyxir.Warnings.ContractDiff,
Dialyxir.Warnings.ContractRange,
Dialyxir.Warnings.ContractSubtype,
Dialyxir.Warnings.ContractSupertype,
Dialyxir.Warnings.ContractWithOpaque,
Dialyxir.Warnings.ExactEquality,
Dialyxir.Warnings.ExtraRange,
Dialyxir.Warnings.FunctionApplicationArguments,
Dialyxir.Warnings.FunctionApplicationNoFunction,
Dialyxir.Warnings.GuardFail,
Dialyxir.Warnings.GuardFailPattern,
Dialyxir.Warnings.ImproperListConstruction,
Dialyxir.Warnings.InvalidContract,
Dialyxir.Warnings.MapUpdate,
Dialyxir.Warnings.MissingRange,
Dialyxir.Warnings.NegativeGuardFail,
Dialyxir.Warnings.NoReturn,
Dialyxir.Warnings.OpaqueGuard,
Dialyxir.Warnings.OpaqueEquality,
Dialyxir.Warnings.OpaqueMatch,
Dialyxir.Warnings.OpaqueNonequality,
Dialyxir.Warnings.OpaqueTypeTest,
Dialyxir.Warnings.OverlappingContract,
Dialyxir.Warnings.PatternMatch,
Dialyxir.Warnings.PatternMatchCovered,
Dialyxir.Warnings.RecordConstruction,
Dialyxir.Warnings.RecordMatching,
Dialyxir.Warnings.UnknownBehaviour,
Dialyxir.Warnings.UnknownFunction,
Dialyxir.Warnings.UnknownType,
Dialyxir.Warnings.UnmatchedReturn,
Dialyxir.Warnings.UnusedFunction
DialyxirVendored.Warnings.AppCall,
DialyxirVendored.Warnings.Apply,
DialyxirVendored.Warnings.BinaryConstruction,
DialyxirVendored.Warnings.Call,
DialyxirVendored.Warnings.CallToMissingFunction,
DialyxirVendored.Warnings.CallWithOpaque,
DialyxirVendored.Warnings.CallWithoutOpaque,
DialyxirVendored.Warnings.CallbackArgumentTypeMismatch,
DialyxirVendored.Warnings.CallbackInfoMissing,
DialyxirVendored.Warnings.CallbackMissing,
DialyxirVendored.Warnings.CallbackNotExported,
DialyxirVendored.Warnings.CallbackSpecArgumentTypeMismatch,
DialyxirVendored.Warnings.CallbackSpecTypeMismatch,
DialyxirVendored.Warnings.CallbackTypeMismatch,
DialyxirVendored.Warnings.ContractDiff,
DialyxirVendored.Warnings.ContractRange,
DialyxirVendored.Warnings.ContractSubtype,
DialyxirVendored.Warnings.ContractSupertype,
DialyxirVendored.Warnings.ContractWithOpaque,
DialyxirVendored.Warnings.ExactEquality,
DialyxirVendored.Warnings.ExtraRange,
DialyxirVendored.Warnings.FunctionApplicationArguments,
DialyxirVendored.Warnings.FunctionApplicationNoFunction,
DialyxirVendored.Warnings.GuardFail,
DialyxirVendored.Warnings.GuardFailPattern,
DialyxirVendored.Warnings.ImproperListConstruction,
DialyxirVendored.Warnings.InvalidContract,
DialyxirVendored.Warnings.MapUpdate,
DialyxirVendored.Warnings.MissingRange,
DialyxirVendored.Warnings.NegativeGuardFail,
DialyxirVendored.Warnings.NoReturn,
DialyxirVendored.Warnings.OpaqueGuard,
DialyxirVendored.Warnings.OpaqueEquality,
DialyxirVendored.Warnings.OpaqueMatch,
DialyxirVendored.Warnings.OpaqueNonequality,
DialyxirVendored.Warnings.OpaqueTypeTest,
DialyxirVendored.Warnings.OverlappingContract,
DialyxirVendored.Warnings.PatternMatch,
DialyxirVendored.Warnings.PatternMatchCovered,
DialyxirVendored.Warnings.RecordConstruction,
DialyxirVendored.Warnings.RecordMatching,
DialyxirVendored.Warnings.UnknownBehaviour,
DialyxirVendored.Warnings.UnknownFunction,
DialyxirVendored.Warnings.UnknownType,
DialyxirVendored.Warnings.UnmatchedReturn,
DialyxirVendored.Warnings.UnusedFunction
],
%{},
fn warning -> {warning.warning(), warning} end
Expand Down
Loading

0 comments on commit b610d1a

Please sign in to comment.