implement nitpick_ignore_regex

This commit is contained in:
ruro 2021-04-24 02:13:20 +03:00
parent 9e1b4a8f16
commit 00bc3465b3
No known key found for this signature in database
GPG Key ID: 58187C6CC59F5BB0
2 changed files with 16 additions and 1 deletions

View File

@ -131,6 +131,7 @@ class Config:
'manpages_url': (None, 'env', []),
'nitpicky': (False, None, []),
'nitpick_ignore': ([], None, []),
'nitpick_ignore_regex': ([], None, []),
'numfig': (False, 'env', []),
'numfig_secnum_depth': (1, 'env', []),
'numfig_format': ({}, 'env', []), # will be initialized in init_numfig_format()

View File

@ -8,6 +8,7 @@
:license: BSD, see LICENSE for details.
"""
import re
from typing import Any, Dict, List, Optional, Tuple, Type, cast
from docutils import nodes
@ -171,14 +172,27 @@ class ReferencesResolver(SphinxPostTransform):
warn = node.get('refwarn')
if self.config.nitpicky:
warn = True
dtype = '%s:%s' % (domain.name, typ) if domain else typ
if self.config.nitpick_ignore:
dtype = '%s:%s' % (domain.name, typ) if domain else typ
if (dtype, target) in self.config.nitpick_ignore:
warn = False
# for "std" types also try without domain name
if (not domain or domain.name == 'std') and \
(typ, target) in self.config.nitpick_ignore:
warn = False
if self.config.nitpick_ignore_regex:
def matches_ignore(entry_type: str, entry_target: str) -> bool:
for ignore_type, ignore_target in self.config.nitpick_ignore_regex:
if re.fullmatch(ignore_type, entry_type) and \
re.fullmatch(ignore_target, entry_target):
return True
return False
if matches_ignore(dtype, target):
warn = False
# for "std" types also try without domain name
if (not domain or domain.name == 'std') and \
matches_ignore(typ, target):
warn = False
if not warn:
return