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

Avoid linting in macros, if MacroReport is set in declare_lint #149

Open
xFrednet opened this issue Jun 24, 2023 · 1 comment
Open

Avoid linting in macros, if MacroReport is set in declare_lint #149

xFrednet opened this issue Jun 24, 2023 · 1 comment
Labels
A-driver Area: Driver or something related to the internal working of a driver. A-marker-adapter Area: Adapter C-enhancement Category: New feature or request E-help-wanted Participation: Issues with some complexity and where help would be highly appreciated

Comments

@xFrednet
Copy link
Member

A common pattern during linting is to check if the current code originates from a macro, and if so, abort early. This works well in most instances, but has some edge cases, where it doesn't. Mostly, proc macros, that manipulate spans for error reporting.

When I designed the initial Lint struct, I proposed (and by this mean, just added) a MacroReport enum, which allows the user to directly specify how macros should be handled by lint emissions. The idea was to automate a macro handling and make it as simple as possible.

So, this issue is about implementing the required functions for MacroReport. I'm guessing it should be enough to do so, in the adapter. It might also be possible to track the current status InsideMacro/UserCode/... in the AstContext to safe some performance for lookups.

There is no tried and true methods, this requires some prototyping :)

@xFrednet xFrednet added C-enhancement Category: New feature or request E-help-wanted Participation: Issues with some complexity and where help would be highly appreciated A-marker-adapter Area: Adapter A-driver Area: Driver or something related to the internal working of a driver. labels Jun 24, 2023
@xFrednet
Copy link
Member Author

xFrednet commented Jul 8, 2023

I just learned, that span::is_from_macro() isn't even working correctly right now 😅

Reproducible/Test code:

Lint code:

        if matches!(lint.report_in_macro, MacroReport::No | MacroReport::Local)
            && span.is_from_macro()
        {
            return;
        }

Test file:

macro_rules! ignore_macro_magic {
    () => {
        static FIND_ITEM: u32 = 4;
    }
}

mod find_real_item {
    static FIND_ITEM: u32 = 4;
}

mod ignore_macro_item {
    ignore_macro_magic!();
}

fn main() {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-driver Area: Driver or something related to the internal working of a driver. A-marker-adapter Area: Adapter C-enhancement Category: New feature or request E-help-wanted Participation: Issues with some complexity and where help would be highly appreciated
Projects
None yet
Development

No branches or pull requests

1 participant