Skip to content

Commit

Permalink
Merge pull request #63 from josevalim/patch-1
Browse files Browse the repository at this point in the history
Simplify diagnostic handling
  • Loading branch information
sasa1977 authored Dec 18, 2023
2 parents 1d06d62 + 49334eb commit 61d0e0e
Showing 1 changed file with 9 additions and 26 deletions.
35 changes: 9 additions & 26 deletions lib/boundary/mix/tasks/compile/boundary.ex
Original file line number Diff line number Diff line change
Expand Up @@ -394,31 +394,14 @@ defmodule Mix.Tasks.Compile.Boundary do
end

def diagnostic(message, opts \\ []) do
diagnostic =
%Mix.Task.Compiler.Diagnostic{
compiler_name: "boundary",
details: nil,
file: nil,
message: message,
position: 0,
severity: :warning
}
|> Map.merge(Map.new(opts))

cond do
diagnostic.file == nil ->
%{diagnostic | file: "unknown"}

diagnostic.position == 0 and File.exists?(diagnostic.file) ->
num_lines =
diagnostic.file
|> File.stream!()
|> Enum.count()

%{diagnostic | position: {1, 0, num_lines + 1, 0}}

true ->
diagnostic
end
%Mix.Task.Compiler.Diagnostic{
compiler_name: "boundary",
details: nil,
file: nil,
message: message,
position: 0,
severity: :warning
}
|> struct(opts)
end
end

0 comments on commit 61d0e0e

Please sign in to comment.