├── .cargo └── config.toml ├── .github ├── dependabot.yml └── workflows │ └── ci.yml ├── .gitignore ├── Cargo.toml ├── README.md ├── rust-toolchain ├── scripts ├── names.sh ├── start_from_clippy_lint.sh ├── start_new_lint.sh └── test_start_from_clippy_lint.sh ├── src └── lib.rs ├── start_from_clippy_lint.sh ├── start_new_lint.sh └── ui ├── main.rs └── main.stderr /.cargo/config.toml: -------------------------------------------------------------------------------- 1 | [target.aarch64-apple-darwin] 2 | linker = "dylint-link" 3 | 4 | [target.x86_64-apple-darwin] 5 | linker = "dylint-link" 6 | 7 | [target.x86_64-unknown-linux-gnu] 8 | linker = "dylint-link" 9 | 10 | [target.x86_64-pc-windows-msvc] 11 | linker = "dylint-link" 12 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "cargo" 4 | directory: "/" 5 | schedule: 6 | interval: "daily" 7 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | test: 7 | runs-on: ubuntu-latest 8 | 9 | steps: 10 | - uses: actions/checkout@v2 11 | 12 | - name: Format 13 | run: cargo +stable fmt && git diff --exit-code 14 | 15 | - name: Install cargo-dylint 16 | run: cargo install cargo-dylint 17 | 18 | - name: Install dylint-link 19 | run: cargo install dylint-link 20 | 21 | - name: Build 22 | run: cargo build 23 | 24 | - name: List 25 | run: DYLINT_LIBRARY_PATH=$PWD/target/debug cargo dylint --list | grep -w fill_me_in 26 | 27 | - name: Test 28 | run: cargo test 29 | 30 | - name: Doc Test 31 | # MinerSebas: Doc-Tests cannot be run on "cdylib" crates. 32 | # Due to this the crate will be changed to a regular "lib" and then run the Doc-Tests. 33 | run: | 34 | sed -i 's/"cdylib"/"lib"/g' Cargo.toml 35 | cargo test --doc 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /Cargo.lock 3 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fill_me_in" 3 | version = "0.1.0" 4 | authors = ["authors go here"] 5 | description = "decription goes here" 6 | edition = "2018" 7 | publish = false 8 | 9 | [lib] 10 | crate-type = ["cdylib"] 11 | 12 | [dependencies] 13 | clippy_utils = { git = "https://github.com/rust-lang/rust-clippy", rev = "7b2896a8fc9f0b275692677ee6d2d66a7cbde16a" } 14 | dylint_linting = "2.0.1" 15 | if_chain = "1.0.2" 16 | 17 | [dev-dependencies] 18 | dylint_testing = "2.0.1" 19 | 20 | [package.metadata.rust-analyzer] 21 | rustc_private = true 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Template Dylint library 2 | 3 | This repository is archived. Please use the following command to create new [Dylint](https://github.com/trailofbits/dylint) libraries: 4 | 5 | ``` 6 | cargo dylint --new 7 | ``` 8 | 9 | --- 10 | 11 | [Dylint](https://github.com/trailofbits/dylint) is a tool for running Rust lints from dynamic libraries. This repository is a "blank slate" Dylint library. 12 | 13 | The recommended way to create a new Dylint library is with `cargo dylint --new PATH`. 14 | 15 | However, forking this respository and running `./start_new_lint.sh NEW_LINT_NAME` should also work. 16 | 17 | The documentation for `start_from_clippy_lint.sh` is retained below. However, the script is currently non-functional and requires updating. 18 | 19 | --- 20 | 21 | **Experimental** 22 | 23 | Choose a [Clippy lint](https://rust-lang.github.io/rust-clippy/master/) and run the following two commands: 24 | 25 | ```sh 26 | ./start_from_clippy_lint.sh CLIPPY_LINT_NAME NEW_LINT_NAME 27 | cargo build 28 | ``` 29 | 30 | If the first command fails: sorry. Perhaps try another Clippy lint. 31 | 32 | If the first command succeeds, but the second fails: you are probably halfway to having a functional Dylint library. 33 | 34 | If both commands succeed: hooray! You might then try the following: 35 | 36 | ```sh 37 | DYLINT_LIBRARY_PATH=$PWD/target/debug cargo dylint NEW_LINT_NAME -- --manifest-path=PATH_TO_OTHER_PACKAGES_MANIFEST 38 | ``` 39 | -------------------------------------------------------------------------------- /rust-toolchain: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "nightly-2022-02-24" 3 | components = ["llvm-tools-preview", "rustc-dev"] 4 | -------------------------------------------------------------------------------- /scripts/names.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | CLIPPY_UPPER="${CLIPPY_LOWER^^}" 4 | NEW_UPPER="${NEW_LOWER^^}" 5 | 6 | camelize() { 7 | UNDERSCORE=1 8 | while read -n1 X; do 9 | if [[ "$X" = '_' ]]; then 10 | UNDERSCORE=1 11 | elif [[ -n "$UNDERSCORE" ]]; then 12 | echo -n "${X^}" 13 | UNDERSCORE= 14 | else 15 | echo -n "$X" 16 | fi 17 | done 18 | } 19 | 20 | CLIPPY_CAMEL="$(echo -n "$CLIPPY_LOWER" | camelize)" 21 | NEW_CAMEL="$(echo -n "$NEW_LOWER" | camelize)" 22 | 23 | CLIPPY_KEBAB="$(echo -n "$CLIPPY_LOWER" | tr '_' '-')" 24 | NEW_KEBAB="$(echo -n "$NEW_LOWER" | tr '_' '-')" 25 | -------------------------------------------------------------------------------- /scripts/start_from_clippy_lint.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | TEST_START_FROM_CLIPPY_LINT_SRC="$TEST_START_FROM_CLIPPY_LINT_SRC" 4 | 5 | # set -x 6 | set -euo pipefail 7 | 8 | if [[ $# -lt 1 || $# -ge 3 ]]; then 9 | echo "Usage: $(basename $0) CLIPPY_LINT_NAME [NEW_LINT_NAME]" >&2 10 | exit 1 11 | fi 12 | 13 | REV=ae72f1adb9cbf16141f880e9e955723a5fdabf00 14 | 15 | CLIPPY_LOWER="$1" 16 | if [[ $# -ge 2 ]]; then 17 | NEW_LOWER="$2" 18 | else 19 | NEW_LOWER="$CLIPPY_LOWER" 20 | fi 21 | 22 | source "$(dirname "$(readlink -f $0)")"/names.sh 23 | 24 | DST="$(dirname "$(readlink -f $0)")"/.. 25 | 26 | if [[ -n "$TEST_START_FROM_CLIPPY_LINT_SRC" ]]; then 27 | SRC="$TEST_START_FROM_CLIPPY_LINT_SRC" 28 | else 29 | SRC="$(mktemp -d --tmpdir rust-clippy.XXXXXX)" 30 | git clone 'https://github.com/rust-lang/rust-clippy' "$SRC" 31 | fi 32 | 33 | cd "$SRC" 34 | git checkout "$REV" --quiet 35 | 36 | if [[ ! -f "clippy_lints/src/$CLIPPY_LOWER.rs" ]]; then 37 | echo "$0: could not find '$CLIPPY_LOWER'" >&2 38 | exit 1 39 | fi 40 | 41 | # Cargo.toml 42 | 43 | sed -i "s/\/$NEW_LOWER/g" "$DST/Cargo.toml" 44 | 45 | # README.md 46 | 47 | ( 48 | echo "# $NEW_LOWER" 49 | echo 50 | cat "clippy_lints/src/$CLIPPY_LOWER.rs" | 51 | sed -n 's,^[[:space:]]*///[[:space:]]*\(.*\)$,\1,;T;p' 52 | ) > "$DST/README.md" 53 | 54 | # src/lib.rs 55 | 56 | sed -i " 57 | s/\/$NEW_LOWER/g; 58 | s/\/$NEW_UPPER/g; 59 | s/\/$NEW_CAMEL/g 60 | " "$DST/src/lib.rs" 61 | 62 | # src/fill_me_in.rs 63 | 64 | cat "clippy_lints/src/$CLIPPY_LOWER.rs" | 65 | sed " 66 | s/\/clippy_utils::consts/g 67 | s/\/clippy_utils/g 68 | s/\/declare_lint/g 69 | s/\/declare_lint/g 70 | s/\/Warn/g 71 | s/\<$CLIPPY_LOWER\>/$NEW_LOWER/g 72 | s/\<$CLIPPY_UPPER\>/$NEW_UPPER/g 73 | s/\<$CLIPPY_CAMEL\>/$NEW_CAMEL/g 74 | " | 75 | cat > "$DST/src/fill_me_in.rs" 76 | 77 | mv "$DST/src/fill_me_in.rs" "$DST/src/$NEW_LOWER.rs" 78 | 79 | # ui/main.rs 80 | 81 | cat "tests/ui/$CLIPPY_LOWER.rs" | 82 | sed "s/\/$NEW_LOWER/g" | 83 | cat > "$DST/ui/main.rs" 84 | 85 | mv "$DST/ui/main.rs" "$DST/ui/$NEW_LOWER.rs" 86 | 87 | # ui/main.stderr 88 | 89 | cat "tests/ui/$CLIPPY_LOWER.stderr" | 90 | sed "s/\/$NEW_KEBAB/g" | 91 | cat > "$DST/ui/main.stderr" 92 | 93 | mv "$DST/ui/main.stderr" "$DST/ui/$NEW_LOWER.stderr" 94 | -------------------------------------------------------------------------------- /scripts/start_new_lint.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | # set -x 4 | set -euo pipefail 5 | 6 | if [[ $# -ne 1 ]]; then 7 | echo "Usage: $(basename $0) NEW_LINT_NAME" >&2 8 | exit 1 9 | fi 10 | 11 | CLIPPY_LOWER="fill_me_in" 12 | NEW_LOWER="$1" 13 | 14 | source "$(dirname "$(readlink -f $0)")"/names.sh 15 | 16 | DST="$(dirname "$(readlink -f $0)")"/.. 17 | 18 | # Cargo.toml 19 | 20 | sed -i "s/\/$NEW_LOWER/g" "$DST/Cargo.toml" 21 | 22 | # README.md 23 | 24 | ( 25 | echo "# $NEW_LOWER" 26 | echo 27 | cat "$DST/src/lib.rs" | 28 | sed -n 's,^[[:space:]]*///[[:space:]]*\(.*\)$,\1,;T;p' 29 | ) > "$DST/README.md" 30 | 31 | # src/lib.rs 32 | 33 | sed -i " 34 | s/\/clippy_utils::consts/g 35 | s/\/clippy_utils/g 36 | s/\/declare_lint/g 37 | s/\/declare_lint/g 38 | s/\/Warn/g 39 | s/\<$CLIPPY_LOWER\>/$NEW_LOWER/g 40 | s/\<$CLIPPY_UPPER\>/$NEW_UPPER/g 41 | s/\<$CLIPPY_CAMEL\>/$NEW_CAMEL/g 42 | " "$DST/src/lib.rs" 43 | 44 | # ui/main.rs 45 | 46 | sed -i "s/\/$NEW_LOWER/g" "$DST/ui/main.rs" 47 | 48 | mv "$DST/ui/main.rs" "$DST/ui/$NEW_LOWER.rs" 49 | 50 | # ui/main.stderr 51 | 52 | sed -i "s/\/$NEW_KEBAB/g" "$DST/ui/main.stderr" 53 | 54 | mv "$DST/ui/main.stderr" "$DST/ui/$NEW_LOWER.stderr" 55 | -------------------------------------------------------------------------------- /scripts/test_start_from_clippy_lint.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | # set -x 4 | set -euo pipefail 5 | 6 | if [[ $# -ne 0 ]]; then 7 | echo "$0: expect no arguments" >&2 8 | exit 1 9 | fi 10 | 11 | if [[ -n "$(git status --porcelain)" ]]; then 12 | echo "$0: repository contains uncommitted changes; please run in a clean repository" >&2 13 | exit 1 14 | fi 15 | 16 | RED="\033[0;31m" 17 | GREEN="\033[0;32m" 18 | YELLOW="\033[0;33m" 19 | RESET="\033[0m" 20 | 21 | SRC="$(mktemp -d --tmpdir rust-clippy.XXXXXX)" 22 | git clone 'https://github.com/rust-lang/rust-clippy' "$SRC" 23 | 24 | curl 'https://rust-lang.github.io/rust-clippy/master/lints.json' | 25 | jq -r '.[] .id' | 26 | while read CLIPPY_LINT_NAME; do 27 | echo -n "$CLIPPY_LINT_NAME: " 28 | true && 29 | (TEST_START_FROM_CLIPPY_LINT_SRC="$SRC" "$(dirname $0)"/start_from_clippy_lint.sh "$CLIPPY_LINT_NAME" 2>/dev/null || 30 | (echo -e "${RED}start_from_clippy_lint.sh failed${RESET}" && false)) && 31 | (cargo build 2>/dev/null || 32 | (echo -e "${YELLOW}cargo build failed${RESET}" && false)) && 33 | (echo -e "${GREEN}ok${RESET}") 34 | git checkout . --quiet 35 | git clean -dfx src ui --quiet 36 | done 37 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | #![feature(rustc_private)] 2 | #![warn(unused_extern_crates)] 3 | 4 | extern crate rustc_ast; 5 | extern crate rustc_ast_pretty; 6 | extern crate rustc_data_structures; 7 | extern crate rustc_errors; 8 | extern crate rustc_hir; 9 | extern crate rustc_hir_pretty; 10 | extern crate rustc_index; 11 | extern crate rustc_infer; 12 | extern crate rustc_lexer; 13 | extern crate rustc_middle; 14 | extern crate rustc_mir_dataflow; 15 | extern crate rustc_parse; 16 | extern crate rustc_parse_format; 17 | extern crate rustc_span; 18 | extern crate rustc_target; 19 | extern crate rustc_trait_selection; 20 | extern crate rustc_typeck; 21 | 22 | use rustc_lint::LateLintPass; 23 | 24 | dylint_linting::declare_late_lint! { 25 | /// **What it does:** 26 | /// 27 | /// **Why is this bad?** 28 | /// 29 | /// **Known problems:** None. 30 | /// 31 | /// **Example:** 32 | /// 33 | /// ```rust 34 | /// // example code where a warning is issued 35 | /// ``` 36 | /// Use instead: 37 | /// ```rust 38 | /// // example code that does not raise a warning 39 | /// ``` 40 | pub FILL_ME_IN, 41 | Warn, 42 | "description goes here" 43 | } 44 | 45 | impl<'tcx> LateLintPass<'tcx> for FillMeIn { 46 | // A list of things you might check can be found here: 47 | // https://doc.rust-lang.org/stable/nightly-rustc/rustc_lint/trait.LateLintPass.html 48 | } 49 | 50 | #[test] 51 | fn ui() { 52 | dylint_testing::ui_test( 53 | env!("CARGO_PKG_NAME"), 54 | &std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("ui"), 55 | ); 56 | } 57 | -------------------------------------------------------------------------------- /start_from_clippy_lint.sh: -------------------------------------------------------------------------------- 1 | scripts/start_from_clippy_lint.sh -------------------------------------------------------------------------------- /start_new_lint.sh: -------------------------------------------------------------------------------- 1 | scripts/start_new_lint.sh -------------------------------------------------------------------------------- /ui/main.rs: -------------------------------------------------------------------------------- 1 | fn main() {} 2 | -------------------------------------------------------------------------------- /ui/main.stderr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trailofbits/dylint-template/34228806724b048d726049833fcfe9893100cc98/ui/main.stderr --------------------------------------------------------------------------------