Skip to content

Commit

Permalink
Rollup merge of rust-lang#60338 - petrochenkov:notidy, r=varkor
Browse files Browse the repository at this point in the history
tidy: Fix some more false positives for long URLs

A URL that's simply longer than 100 characters is ok regardless of context.

r? @varkor
  • Loading branch information
Centril committed Apr 28, 2019
2 parents bdfdbcd + 2ae7b0c commit f3328ce
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
2 changes: 0 additions & 2 deletions src/ci/docker/scripts/sccache.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# ignore-tidy-linelength

set -ex

curl -fo /usr/local/bin/sccache \
Expand Down
1 change: 0 additions & 1 deletion src/librustc/error_codes.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// ignore-tidy-linelength
#![allow(non_snake_case)]

// Error messages for EXXXX errors.
Expand Down
1 change: 0 additions & 1 deletion src/librustc_typeck/error_codes.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// ignore-tidy-linelength
// ignore-tidy-filelength

#![allow(non_snake_case)]
Expand Down
17 changes: 11 additions & 6 deletions src/tools/tidy/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ when executed when assertions are disabled.
Use llvm::report_fatal_error for increased robustness.";

/// Parser states for `line_is_url`.
#[derive(PartialEq)]
#[derive(Clone, Copy, PartialEq)]
#[allow(non_camel_case_types)]
enum LIUState {
EXP_COMMENT_START,
Expand All @@ -56,26 +56,31 @@ enum LIUState {
fn line_is_url(line: &str) -> bool {
use self::LIUState::*;
let mut state: LIUState = EXP_COMMENT_START;
let is_url = |w: &str| w.starts_with("http://") || w.starts_with("https://");

for tok in line.split_whitespace() {
match (state, tok) {
(EXP_COMMENT_START, "//") => state = EXP_LINK_LABEL_OR_URL,
(EXP_COMMENT_START, "///") => state = EXP_LINK_LABEL_OR_URL,
(EXP_COMMENT_START, "//") |
(EXP_COMMENT_START, "///") |
(EXP_COMMENT_START, "//!") => state = EXP_LINK_LABEL_OR_URL,

(EXP_LINK_LABEL_OR_URL, w)
if w.len() >= 4 && w.starts_with('[') && w.ends_with("]:")
=> state = EXP_URL,

(EXP_LINK_LABEL_OR_URL, w)
if w.starts_with("http://") || w.starts_with("https://")
if is_url(w)
=> state = EXP_END,

(EXP_URL, w)
if w.starts_with("http://") || w.starts_with("https://") || w.starts_with("../")
if is_url(w) || w.starts_with("../")
=> state = EXP_END,

(_, _) => return false,
(_, w)
if w.len() > COLS && is_url(w)
=> state = EXP_END,

(_, _) => {}
}
}

Expand Down

0 comments on commit f3328ce

Please sign in to comment.