mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-22 03:44:24 +00:00
Fix spans in doc_markdown
in most cases
This commit is contained in:
parent
d2ef1b318d
commit
aaf9bce905
@ -3,7 +3,8 @@ use pulldown_cmark;
|
||||
use rustc::lint::*;
|
||||
use syntax::ast;
|
||||
use syntax::codemap::{Span, BytePos};
|
||||
use utils::span_lint;
|
||||
use syntax_pos::Pos;
|
||||
use utils::{span_lint, snippet_opt};
|
||||
|
||||
/// **What it does:** Checks for the presence of `_`, `::` or camel-case words
|
||||
/// outside ticks in documentation.
|
||||
@ -134,7 +135,6 @@ pub fn check_attrs<'a>(cx: &EarlyContext, valid_idents: &[String], attrs: &'a [a
|
||||
current += offset_copy;
|
||||
}
|
||||
|
||||
println!("{:?}", spans);
|
||||
if !doc.is_empty() {
|
||||
let parser = Parser::new(pulldown_cmark::Parser::new(&doc));
|
||||
let parser = parser.coalesce(|x, y| {
|
||||
@ -163,6 +163,7 @@ fn check_doc<'a, Events: Iterator<Item=(usize, pulldown_cmark::Event<'a>)>>(
|
||||
|
||||
let mut in_code = false;
|
||||
|
||||
println!("{:?}", spans);
|
||||
for (offset, event) in docs {
|
||||
println!("{:?}, {:?}", offset, event);
|
||||
match event {
|
||||
@ -180,7 +181,17 @@ fn check_doc<'a, Events: Iterator<Item=(usize, pulldown_cmark::Event<'a>)>>(
|
||||
Err(e) => e-1,
|
||||
};
|
||||
|
||||
let (_, span) = spans[index];
|
||||
let (begin, span) = spans[index];
|
||||
|
||||
println!("raw: {:?}, {}, {}, {:?}", snippet_opt(cx, span), offset, begin, span);
|
||||
|
||||
// Adjust for the begining of the current `Event`
|
||||
let span = Span {
|
||||
lo: span.lo + BytePos::from_usize(offset - begin),
|
||||
..span
|
||||
};
|
||||
|
||||
println!("adjusted: {:?}", snippet_opt(cx, span));
|
||||
check_text(cx, valid_idents, &text, span);
|
||||
}
|
||||
},
|
||||
@ -199,6 +210,14 @@ fn check_text(cx: &EarlyContext, valid_idents: &[String], text: &str, span: Span
|
||||
continue;
|
||||
}
|
||||
|
||||
// Adjust for the current word
|
||||
let offset = word.as_ptr() as usize - text.as_ptr() as usize;
|
||||
let span = Span {
|
||||
lo: span.lo + BytePos::from_usize(offset),
|
||||
hi: span.lo + BytePos::from_usize(offset + word.len()),
|
||||
..span
|
||||
};
|
||||
|
||||
check_word(cx, word, span);
|
||||
}
|
||||
}
|
||||
|
@ -2,13 +2,13 @@
|
||||
|
||||
#![feature(plugin)]
|
||||
#![plugin(clippy)]
|
||||
|
||||
#![allow(dead_code)]
|
||||
#![warn(doc_markdown)]
|
||||
|
||||
/// The foo_bar function does _nothing_. See also foo::bar. (note the dot there)
|
||||
/// Markdown is _weird_. I mean _really weird_. This \_ is ok. So is `_`. But not Foo::some_fun
|
||||
/// which should be reported only once despite being __doubly bad__.
|
||||
/// Here be ::is::a::global:path.
|
||||
/// Here be ::a::global:path.
|
||||
/// That's not code ~NotInCodeBlock~.
|
||||
/// be_sure_we_got_to_the_end_of_it
|
||||
fn foo_bar() {
|
||||
@ -49,35 +49,6 @@ fn test_emphasis() {
|
||||
fn test_units() {
|
||||
}
|
||||
|
||||
/// This one checks we don’t try to split unicode codepoints
|
||||
/// `ß`
|
||||
/// `ℝ`
|
||||
/// `💣`
|
||||
/// `❤️`
|
||||
/// ß_foo
|
||||
/// ℝ_foo
|
||||
/// 💣_foo
|
||||
/// ❤️_foo
|
||||
/// foo_ß
|
||||
/// foo_ℝ
|
||||
/// foo_💣
|
||||
/// foo_❤️
|
||||
/// [ßdummy textß][foo_1ß]
|
||||
/// [ℝdummy textℝ][foo_2ℝ]
|
||||
/// [💣dummy tex💣t][foo3_💣]
|
||||
/// [❤️dummy text❤️][foo_4❤️]
|
||||
/// [ßdummy textß](foo_5ß)
|
||||
/// [ℝdummy textℝ](foo_6ℝ)
|
||||
/// [💣dummy tex💣t](fo7o_💣)
|
||||
/// [❤️dummy text❤️](foo_8❤️)
|
||||
/// [foo1_ß]: dummy text
|
||||
/// [foo2_ℝ]: dummy text
|
||||
/// [foo3_💣]: dummy text
|
||||
/// [foo4_❤️]: dummy text
|
||||
/// be_sure_we_got_to_the_end_of_it
|
||||
fn test_unicode() {
|
||||
}
|
||||
|
||||
/// This test has [a link_with_underscores][chunked-example] inside it. See #823.
|
||||
/// See also [the issue tracker](https://github.com/Manishearth/rust-clippy/search?q=doc_markdown&type=Issues)
|
||||
/// on GitHub (which is a camel-cased word, but is OK). And here is another [inline link][inline_link].
|
||||
|
Loading…
Reference in New Issue
Block a user