mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 03:38:29 +00:00
Improve lint even more
This commit is contained in:
parent
1fb404bebe
commit
6be97e2250
@ -19,8 +19,8 @@ pub const CHECK_URL_IMPROVEMENTS: Pass = Pass {
|
|||||||
const URL_REGEX: &str = concat!(
|
const URL_REGEX: &str = concat!(
|
||||||
r"https?://", // url scheme
|
r"https?://", // url scheme
|
||||||
r"([-a-zA-Z0-9@:%._\+~#=]{2,256}\.)+", // one or more subdomains
|
r"([-a-zA-Z0-9@:%._\+~#=]{2,256}\.)+", // one or more subdomains
|
||||||
r"[a-zA-Z]{2,4}", // root domain
|
r"[a-zA-Z]{2,63}", // root domain
|
||||||
r"\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)" // optional query or url fragments
|
r"\b([-a-zA-Z0-9@:%_\+.~#?&/=]*)" // optional query or url fragments
|
||||||
);
|
);
|
||||||
|
|
||||||
struct UrlImprovementsLinter<'a, 'tcx> {
|
struct UrlImprovementsLinter<'a, 'tcx> {
|
||||||
@ -101,8 +101,9 @@ impl<'a, 'tcx> DocFolder for UrlImprovementsLinter<'a, 'tcx> {
|
|||||||
while let Some((event, range)) = p.next() {
|
while let Some((event, range)) = p.next() {
|
||||||
match event {
|
match event {
|
||||||
Event::End(Tag::Link(_, url, _)) => {
|
Event::End(Tag::Link(_, url, _)) => {
|
||||||
// NOTE: links cannot be nested, so we don't need to check `kind`
|
// NOTE: links cannot be nested, so we don't need to
|
||||||
if url.as_ref() == title && !ignore {
|
// check `kind`
|
||||||
|
if url.as_ref() == title && !ignore && self.regex.matches(url) {
|
||||||
report_diag(
|
report_diag(
|
||||||
self.cx,
|
self.cx,
|
||||||
"unneeded long form for URL",
|
"unneeded long form for URL",
|
||||||
|
@ -55,6 +55,8 @@ pub fn c() {}
|
|||||||
/// ```
|
/// ```
|
||||||
/// This link should not be linted: http://example.com
|
/// This link should not be linted: http://example.com
|
||||||
/// ```
|
/// ```
|
||||||
|
///
|
||||||
|
/// [should_not.lint](should_not.lint)
|
||||||
pub fn everything_is_fine_here() {}
|
pub fn everything_is_fine_here() {}
|
||||||
|
|
||||||
#[allow(url_improvements)]
|
#[allow(url_improvements)]
|
||||||
|
Loading…
Reference in New Issue
Block a user