-
Notifications
You must be signed in to change notification settings - Fork 341
Fix Erlang Scanning & Warnings #1818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
wojtekmach
merged 5 commits into
elixir-lang:main
from
garazdawi:lukas/fix-erlang-warnings-and-scanning
Nov 15, 2023
+246
−64
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4f1211f
Move autolink function parsing to language specific part
garazdawi a27be64
Parse Erlang module names using erl_scan to make things consistent
garazdawi a72f81f
Add correct line numbers to Erlang link warnings
garazdawi 774aacd
Warning on undefined types and callbacks in Erlang
garazdawi db1c726
Fix warnings for un-implemented see links
garazdawi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,9 @@ defmodule ExDoc.Autolink do | |
# * `:current_module` - the module that the docs are being generated for. Used to link local | ||
# calls and see if remote calls are in the same app. | ||
# | ||
# * `:current_kfa` - the kind, function, arity that the docs are being generated for. Is nil | ||
# if there is no such thing. Used to generate more accurate warnings. | ||
# | ||
# * `:module_id` - id of the module being documented (e.g.: `"String"`) | ||
# | ||
# * `:file` - source file location | ||
|
@@ -48,6 +51,7 @@ defmodule ExDoc.Autolink do | |
extras: [], | ||
deps: [], | ||
ext: ".html", | ||
current_kfa: nil, | ||
siblings: [], | ||
skip_undefined_reference_warnings_on: [], | ||
skip_code_autolink_to: [], | ||
|
@@ -371,29 +375,6 @@ defmodule ExDoc.Autolink do | |
end | ||
end | ||
|
||
# There are special forms that are forbidden by the tokenizer | ||
def parse_function("__aliases__"), do: {:function, :__aliases__} | ||
def parse_function("__block__"), do: {:function, :__block__} | ||
def parse_function("%"), do: {:function, :%} | ||
|
||
def parse_function(string) do | ||
case Code.string_to_quoted("& #{string}/0", warnings: false) do | ||
{:ok, {:&, _, [{:/, _, [{:__aliases__, _, [function]}, 0]}]}} when is_atom(function) -> | ||
## When function starts with capital letter | ||
{:function, function} | ||
|
||
## When function is 'nil' | ||
{:ok, {:&, _, [{:/, _, [nil, 0]}]}} -> | ||
{:function, nil} | ||
|
||
{:ok, {:&, _, [{:/, _, [{function, _, _}, 0]}]}} when is_atom(function) -> | ||
{:function, function} | ||
|
||
_ -> | ||
:error | ||
end | ||
end | ||
|
||
def kind("c:" <> rest), do: {:callback, rest} | ||
def kind("t:" <> rest), do: {:type, rest} | ||
## \\ does not work for :custom_url as Earmark strips the \... | ||
|
@@ -432,7 +413,7 @@ defmodule ExDoc.Autolink do | |
{:type, _visibility} -> | ||
case config.language.try_builtin_type(name, arity, mode, config, original_text) do | ||
nil -> | ||
if mode == :custom_link do | ||
if mode == :custom_link or config.language == ExDoc.Language.Erlang do | ||
maybe_warn(config, ref, visibility, %{original_text: original_text}) | ||
end | ||
|
||
|
@@ -501,7 +482,9 @@ defmodule ExDoc.Autolink do | |
|
||
nil | ||
|
||
{:regular_link, _module_visibility, :undefined} when not same_module? -> | ||
{:regular_link, _module_visibility, :undefined} | ||
when not same_module? and | ||
(config.language != ExDoc.Language.Erlang or kind == :function) -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, feel free to let it warn on Elixir, assuming it is one of |
||
nil | ||
|
||
{_mode, _module_visibility, visibility} -> | ||
|
@@ -518,7 +501,16 @@ defmodule ExDoc.Autolink do | |
# TODO: Remove on Elixir v1.14 | ||
stacktrace_info = | ||
if unquote(Version.match?(System.version(), ">= 1.14.0")) do | ||
[file: config.file, line: config.line] | ||
f = | ||
case config.current_kfa do | ||
{:function, f, a} -> | ||
[function: {f, a}] | ||
|
||
_ -> | ||
[] | ||
end | ||
|
||
[file: config.file, line: config.line, module: config.current_module] ++ f | ||
else | ||
[] | ||
end | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this check here to avoid warning in Elixir? If so, you can go ahead and warn. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is, but if I remove it a lot (~20) of tests break (or not break, but they start to emit warnings to stdout).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, @wojtekmach please look into it afterwards then. :)
Ideally we want to avoid hardcoding the language here, an option would be better, but since this is temporary, it is fine by me. :)