-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Warn on empty lines after outer attributes #2340
Conversation
77997d8
to
b6720d8
Compare
Looks like by reusing the |
|
There should also be a test case for items with a comment between the attribute and item. |
469eb49
to
ec77e33
Compare
The lint now works for all members of syntax::ast::Item_, I added test cases for |
I'm not really sure why edit: ok, nevermind I found out how to reproduce it locally: cargo build --features debugging
cp target/debug/cargo-clippy ~/rust/cargo/bin/cargo-clippy
cp target/debug/clippy-driver ~/rust/cargo/bin/clippy-driver
~/rust/cargo/bin/cargo-clippy clippy --all -- -D clippy |
Nah, the current tests are sufficient
That is very weird. Something must be converting the inner attribute into an outer attribute. You can try dumping the crate AST and look at that |
Ok this seems like a weird problem. I managed to dump the AST of
The attribute seems to be an I did some more shots in the dark and now I'm sure that this is caused by the // ./test/weird_spans.rs
#![feature(plugin)]
#![plugin(clippy)]
fn main() {
assert!(true);
} So, somewhere an I will try to dig deeper in the next days, but it looks like it will take some more time to get this merged |
Oh... just throw in a macro check for now. The attribute should probably have some expansion info. |
ec77e33
to
642b321
Compare
Unfortunately, I was unable to find any macro expansion info in the spans I'm using. The |
What will happen if somebody makes a file like #[allow(foo)]
fn main() {} |
duh, you are right, that would not be detected then 👍 I added a debugging commit, because I'm running out of time for today and want to pick it up again on Sunday. I also added a separate test file at |
Looking at the output and the Attribute docs again, it says:
So, maybe it makes sense to check if the attribute span |
Starting with this piece of code: #![feature(plugin)]
#![plugin(clippy)]
fn main() {
"hmm"
} I managed to get the expanded macro with #![feature(prelude_import)]
#![no_std]
#![feature(plugin)]
#![plugin(clippy)]
#[prelude_import]
use std::prelude::v1::*;
#[macro_use]
extern crate std as std;
#[allow(dead_code)]
fn main() { "hmm" }
<snip> So, when iterating over the items, it picks up the #![feature(prelude_import)]
#![no_std]
#![feature(plugin)]
#![plugin(clippy)]
#[prelude_import]
use std::prelude::v1::*;
#[macro_use]
extern crate std as std;
#[allow(dead_code)]
#[allow(dead_code)]
fn main() { "hmm" }
<snip> The most interesting part is, is that one of the |
4c40d7c
to
b956c4d
Compare
sgtm |
b956c4d
to
7160ccb
Compare
If the snippet is empty, it's an attribute that was inserted during macro expansion and we want to ignore those, because they could come from external sources that the user has no control over. For some reason these attributes don't have any expansion info on them, so we have to check it this way until there is a better way.
7160ccb
to
3d54e56
Compare
I added an |
Great! Thanks |
Thank you! |
Seeing what looks like a false positive on this: /// A mapping from coordinates in the source sequence to coordinates in the sequence after
/// the delta is applied.
// TODO: this doesn't need the new strings, so it should either be based on a new structure
// like Delta but missing the strings, or perhaps the two subsets it's synthesized from.
pub struct Transformer<'a, N: NodeInfo + 'a> {
// warning: src/delta.rs:447: Found an empty line after an outer attribute. Perhaps you forgot to add a '!' to make // it an inner attribute?
// note: src/delta.rs:447: #[warn(empty_line_after_outer_attr)] on by default
// help: src/delta.rs:447: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.184/index.html#empty_line_after_outer_attr
// warning: src/delta.rs:448: Found an empty line after an outer attribute. Perhaps you forgot to add a '!' to make it an inner attribute?
// help: src/delta.rs:448: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.184/index.html#empty_line_after_outer_attr |
This should special case doc comments. |
I will have a look 👍 |
btw, example on https://rust-lang-nursery.github.io/rust-clippy/v0.0.184/index.html#empty_line_after_outer_attr is broken - there're no empty lines: |
This adds a new lint to warn on empty lines after outer attributes.
Still fairly new to Rust, so I'm not sure if the empty line detection could be shortened or if the tests cover all edge cases, but it seems to work so far 👍 .
Note that rustc already handles attributes with a missing item: libsyntax/parse/parser.rb#L3938
Closes #1165