-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9800 from hoefling/extlinks/replacements-check
Proposal: check if hardcoded URLs can be replaced with extlinks
- Loading branch information
Showing
8 changed files
with
141 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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 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
5 changes: 5 additions & 0 deletions
5
tests/roots/test-ext-extlinks-hardcoded-urls-multiple-replacements/conf.py
This file contains 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
extensions = ['sphinx.ext.extlinks'] | ||
extlinks = { | ||
'user': ('https://github.com/%s', '@%s'), | ||
'repo': ('https://github.com/%s', 'project %s'), | ||
} |
22 changes: 22 additions & 0 deletions
22
tests/roots/test-ext-extlinks-hardcoded-urls-multiple-replacements/index.rst
This file contains 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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
test-ext-extlinks-hardcoded-urls | ||
================================ | ||
|
||
.. Links generated by extlinks extension should not raise any warnings. | ||
.. Only hardcoded URLs are affected. | ||
:user:`octocat` | ||
|
||
:repo:`sphinx-doc/sphinx` | ||
|
||
.. hardcoded replaceable link which can be replaced as | ||
.. :repo:`octocat` or :user:`octocat` | ||
https://github.com/octocat | ||
|
||
`inline replaceable link <https://github.com/octocat>`_ | ||
|
||
`replaceable link`_ | ||
|
||
.. hyperlinks | ||
.. _replaceable link: https://github.com/octocat |
This file contains 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
extensions = ['sphinx.ext.extlinks'] | ||
extlinks = {'issue': ('https://github.com/sphinx-doc/sphinx/issues/%s', 'issue %s')} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
test-ext-extlinks-hardcoded-urls | ||
================================ | ||
|
||
.. Links generated by extlinks extension should not raise any warnings. | ||
.. Only hardcoded URLs are affected. | ||
:issue:`1` | ||
|
||
.. hardcoded replaceable link | ||
https://github.com/sphinx-doc/sphinx/issues/1 | ||
|
||
`inline replaceable link <https://github.com/sphinx-doc/sphinx/issues/1>`_ | ||
|
||
`replaceable link`_ | ||
|
||
.. hardcoded non-replaceable link | ||
https://github.com/sphinx-doc/sphinx/pulls/1 | ||
|
||
`inline non-replaceable link <https://github.com/sphinx-doc/sphinx/pulls/1>`_ | ||
|
||
`non-replaceable link`_ | ||
|
||
.. hyperlinks | ||
.. _replaceable link: https://github.com/sphinx-doc/sphinx/issues/1 | ||
.. _non-replaceable link: https://github.com/sphinx-doc/sphinx/pulls/1 |
This file contains 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import pytest | ||
|
||
|
||
@pytest.mark.sphinx('html', testroot='ext-extlinks-hardcoded-urls') | ||
def test_replaceable_uris_emit_extlinks_warnings(app, warning): | ||
app.build() | ||
warning_output = warning.getvalue() | ||
# there should be exactly three warnings for replaceable URLs | ||
message = ( | ||
"WARNING: hardcoded link 'https://github.com/sphinx-doc/sphinx/issues/1' " | ||
"could be replaced by an extlink (try using ':issue:`1`' instead)" | ||
) | ||
assert f"index.rst:11: {message}" in warning_output | ||
assert f"index.rst:13: {message}" in warning_output | ||
assert f"index.rst:15: {message}" in warning_output | ||
|
||
|
||
@pytest.mark.sphinx('html', testroot='ext-extlinks-hardcoded-urls-multiple-replacements') | ||
def test_all_replacements_suggested_if_multiple_replacements_possible(app, warning): | ||
app.build() | ||
warning_output = warning.getvalue() | ||
# there should be six warnings for replaceable URLs, three pairs per link | ||
message = ( | ||
"WARNING: hardcoded link 'https://github.com/octocat' " | ||
"could be replaced by an extlink (try using ':user:`octocat`' instead)" | ||
) | ||
assert f"index.rst:14: {message}" in warning_output | ||
assert f"index.rst:16: {message}" in warning_output | ||
assert f"index.rst:18: {message}" in warning_output | ||
message = ( | ||
"WARNING: hardcoded link 'https://github.com/octocat' " | ||
"could be replaced by an extlink (try using ':repo:`octocat`' instead)" | ||
) | ||
assert f"index.rst:14: {message}" in warning_output | ||
assert f"index.rst:16: {message}" in warning_output | ||
assert f"index.rst:18: {message}" in warning_output |