Git Product home page Git Product logo

cargo-check-external-types's Introduction

cargo-check-external-types

cargo-check-external-types is a static analysis tool for Rust library authors to set and verify which types from other libraries are allowed to be are exposed in their public API. This is useful for ensuring that a breaking change to a dependency doesn't force a breaking change in the library that's using it.

The tool has two output formats to cover different use-cases:

  • errors (the default): Output error messages for each type that is exposed in the public API and exit with status 1 if there is at least one error. This is useful for continuous integration.
  • markdown-table: Output the places types are exposed as a Markdown table. This is intended as a discovery tool for established projects.

The tool has an optional configuration file where types can by explicitly allowed.

Example Output

The test suite has a Rust library that relies on some external types. When the tool is run against this library without any configuration, it emits errors for each occurrence of an external type in the public API.

When a config file is provided, the allowed external types no longer show up in the output.

When the output format is set to markdown-table, then a table of external types is output.

How to Use

Important: This tool requires a nightly build of Rust to be installed since it relies on the rustdoc JSON output, which hasn't been stabilized yet. It was last tested against nightly-2023-05-31.

To install, run the following from this README path:

cargo install --locked cargo-check-external-types

Then, in your library crate path, run:

cargo +nightly check-external-types

This will produce errors if any external types are used in a public API at all. That's not terribly useful on its own, so the tool can be given a config file to allow certain types. For example, we can allow any type in bytes with:

allowed_external_types = [
    "bytes::*",
]

Save that file somewhere in your project (in this example, we choose the name external-types.toml), and then run the command with:

cargo +nightly check-external-types --config external-types.toml

Caveats

When public types and modules declared inside a #[doc(hidden)] module are reexported from a public module, they aren't checked for external types. This is because of how they are recorded in RustDoc's index. When such types and modules are encountered by this tool, a warning will be logged.

Security

See CONTRIBUTING for more information.

License

This project is licensed under the Apache-2.0 License.

cargo-check-external-types's People

Contributors

amazon-auto avatar dependabot[bot] avatar jdisanti avatar rcoh avatar taiki-e avatar velfi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.