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

tidy: Fix some more false positives for long URLs #60338

Merged
merged 1 commit into from
Apr 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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