Skip to content
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

extlink: Add support for suppressing 'hardcoded link' warnings #10123

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/usage/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ General configuration
* ``app.add_generic_role``
* ``app.add_source_parser``
* ``download.not_readable``
* ``extlink.hardcoded``
* ``image.not_readable``
* ``ref.term``
* ``ref.ref``
Expand Down
7 changes: 7 additions & 0 deletions doc/usage/extensions/extlinks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,10 @@ The extension adds a config value:

Since links are generated from the role in the reading stage, they appear as
ordinary links to e.g. the ``linkcheck`` builder.

.. versionchanged:: 4.4.0

Added warning on hardcoded links that could be replaced with an extlink.
This can be disabled with::

suppress_warnings = ["extlink.hardcoded"]
3 changes: 2 additions & 1 deletion sphinx/ext/extlinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def check_uri(self, refnode: nodes.reference) -> None:
msg = __('hardcoded link %r could be replaced by an extlink '
'(try using %r instead)')
replacement = f":{alias}:`{match.groupdict().get('value')}`"
logger.warning(msg, uri, replacement, location=refnode)
logger.warning(msg, uri, replacement, location=refnode,
type="extlink", subtype="hardcoded")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I'm no maintainer, just someone lurking around.)

I think you also need to update the list of warnings in the documentation of suppress_warnings here:

https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-suppress_warnings

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, I'm blind. Sorry.



def make_link_role(name: str, base_url: str, caption: str) -> RoleFunction:
Expand Down