Skip to content

Flag env! macro usage in build scripts #15872

@d-e-s-o

Description

@d-e-s-o

What it does

I am not sure if lints can or should make assumptions about the file they are defined in, but it would be good to flag usage of the env! (and option_env!) macro in build scripts. In all likelihood this is wrong. It certainly is wrong for CARGO_* variables [0].

Advantage

It is easy to miss this wrong usage, as it may not break immediately.

Drawbacks

None that I can think of.

Example

env!("CARGO_PKG_VERSION")

Could be written as:

std::env::var("CARGO_PKG_VERSION").expect("CARGO_PKG_VERSION variable not set")

Comparison with existing lints

Not aware of existing lints doing something similar.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions