Skip to content

Commit

Permalink
Revamp lints, share across workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
jhpratt committed Aug 29, 2023
1 parent 7d54150 commit 79e4437
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 188 deletions.
21 changes: 21 additions & 0 deletions .clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
msrv = "1.67"

missing-docs-in-crate-items = true
disallowed-macros = [
"std::column",
"std::env",
"std::file",
"std::include_bytes",
"std::include_str",
"std::include",
"std::line",
"std::module_path",
"std::option_env",
]
disallowed-names = ["alpha", "beta", "gamma", "delta"]
matches-for-let-else = "AllTypes"
enforced-import-renames = [
{ path = "std::time::Duration", rename = "StdDuration" },
{ path = "std::time::Instant", rename = "StdInstant" },
]
semicolon-outside-block-ignore-multiline = true
11 changes: 7 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ jobs:
uses: actions/checkout@v3

- name: Install toolchain
uses: dtolnay/rust-toolchain@stable
uses: dtolnay/rust-toolchain@nightly
with:
components: clippy

- name: Install targets
run: |
Expand All @@ -272,8 +274,8 @@ jobs:
x86_64-unknown-illumos \
wasm32-wasi
- name: Cache cargo output
uses: Swatinem/rust-cache@v2
# - name: Cache cargo output
# uses: Swatinem/rust-cache@v2

- name: Run clippy
run: |
Expand All @@ -286,7 +288,8 @@ jobs:
--target x86_64-pc-windows-gnu \
--target x86_64-unknown-netbsd \
--target x86_64-unknown-illumos \
--target wasm32-wasi
--target wasm32-wasi \
-Zlints
env:
RUSTFLAGS: --cfg bench

Expand Down
92 changes: 92 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,95 @@ debug = 0

[profile.test]
debug = 2

# Deny-by-default lints: These are lints that indicate a lack of compiler guarantees, future
# incompatibility (with no guarantees in the meantime) introduce surprising behavior, or are likely
# to cause undesired behavior. Code that trigger these lints should only be allowed with a
# compelling reason that is clearly documented.

# Warn-by-default lints: These are lints that indicate possible errors, future incompatibility
# (with guaranteed behavior in the meantime), or other stylistic issues (including idioms). Code
# that trigger these lints should not cause undesired behavior and may be allowed as necessary.

# All overrides need higher priority. Any overrides that are for a specific crate need to be done
# the "traditional" way of using attributes at the crate root.

[workspace.lints.rust]
ambiguous-glob-reexports = "deny"
clashing-extern-declarations = "deny"
const-item-mutation = "deny"
deref-nullptr = "deny"
drop-bounds = "deny"
future-incompatible = "deny"
hidden-glob-reexports = "deny"
improper-ctypes = "deny"
improper-ctypes-definitions = "deny"
invalid-from-utf8 = "deny"
invalid-macro-export-arguments = "deny"
invalid-nan-comparisons = "deny"
invalid-reference-casting = "deny"
invalid-value = "deny"
named-arguments-used-positionally = "deny"
non-ascii-idents = "deny"
opaque-hidden-inferred-bound = "deny"
overlapping-range-endpoints = "deny"
suspicious-double-ref-op = "deny"
temporary-cstring-as-ptr = "deny"
unconditional-recursion = "deny"
unnameable-test-items = "deny"
unsafe-op-in-unsafe-fn = "deny"
unstable-syntax-pre-expansion = "deny"

keyword-idents = "warn"
let-underscore = "warn"
macro-use-extern-crate = "warn"
meta-variable-misuse = "warn"
missing-abi = "warn"
missing-copy-implementations = "warn"
missing-debug-implementations = "warn"
missing-docs = "warn"
noop-method-call = "warn"
single-use-lifetimes = "warn"
trivial-casts = "warn"
trivial-numeric-casts = "warn"
unreachable-pub = "warn"
unstable-name-collisions = { level = "warn", priority = 1 } # overrides #![deny(future_incompatible)]
unused = "warn"
unused-import-braces = "warn"
unused-lifetimes = "warn"
unused-qualifications = "warn"
# unused-results = "warn"
unused-tuple-struct-fields = "warn"
variant-size-differences = "warn"

[workspace.lints.clippy]
alloc-instead-of-core = "deny"
std-instead-of-core = "deny"
undocumented-unsafe-blocks = "deny"

all = "warn"
dbg-macro = "warn"
decimal-literal-representation = "warn"
explicit-auto-deref = "warn"
get-unwrap = "warn"
manual-let-else = "warn"
missing-docs-in-private-items = "warn"
missing-enforced-import-renames = "warn"
nursery = "warn"
obfuscated-if-else = "warn"
print-stdout = "warn"
semicolon-outside-block = "warn"
todo = "warn"
unimplemented = "warn"
uninlined-format-args = "warn"
unnested-or-patterns = "warn"
unwrap-in-result = "warn"
unwrap-used = "warn"
use-debug = "warn"

option-if-let-else = { level = "allow", priority = 1 } # suggests terrible code, overrides #![warn(clippy::nursery)]
redundant-pub-crate = { level = "allow", priority = 1 } # rust-lang/rust-clippy#5369, overrides #![warn(clippy::nursery)]

[workspace.lints.rustdoc]
private-doc-tests = "warn"
unescaped-backticks = "warn"
36 changes: 6 additions & 30 deletions benchmarks/main.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,10 @@
#![deny(
anonymous_parameters,
clippy::all,
illegal_floating_point_literal_pattern,
late_bound_lifetime_arguments,
path_statements,
patterns_in_fns_without_body,
rust_2018_idioms,
trivial_casts,
trivial_numeric_casts,
unreachable_pub,
unsafe_code,
unused_extern_crates
#![allow(
missing_docs,
clippy::missing_docs_in_private_items,
clippy::std_instead_of_core, // irrelevant for benchmarks
clippy::std_instead_of_alloc, // irrelevant for benchmarks
clippy::alloc_instead_of_core, // irrelevant for benchmarks
)]
#![warn(
clippy::dbg_macro,
clippy::decimal_literal_representation,
clippy::get_unwrap,
clippy::nursery,
clippy::print_stdout,
clippy::todo,
clippy::unimplemented,
clippy::unwrap_in_result,
clippy::unwrap_used,
clippy::use_debug,
missing_copy_implementations,
missing_debug_implementations,
unused_qualifications,
variant_size_differences
)]
#![allow(clippy::many_single_char_names)]

#[cfg(not(all(
feature = "default",
Expand Down
40 changes: 6 additions & 34 deletions tests/main.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,10 @@
#![deny(
anonymous_parameters,
clippy::all,
clippy::undocumented_unsafe_blocks,
illegal_floating_point_literal_pattern,
late_bound_lifetime_arguments,
path_statements,
patterns_in_fns_without_body,
rust_2018_idioms,
trivial_casts,
trivial_numeric_casts,
unreachable_pub,
unused_extern_crates
)]
#![warn(
clippy::dbg_macro,
clippy::decimal_literal_representation,
clippy::get_unwrap,
clippy::missing_docs_in_private_items,
clippy::nursery,
clippy::print_stdout,
clippy::todo,
clippy::unimplemented,
clippy::unwrap_in_result,
clippy::unwrap_used,
clippy::use_debug,
unused_qualifications,
variant_size_differences
)]
#![allow(
clippy::clone_on_copy,
clippy::cmp_owned,
clippy::cognitive_complexity,
clippy::missing_const_for_fn,
clippy::unwrap_used
clippy::missing_const_for_fn, // irrelevant for tests
clippy::std_instead_of_core, // irrelevant for tests
clippy::std_instead_of_alloc, // irrelevant for tests
clippy::alloc_instead_of_core, // irrelevant for tests
clippy::cognitive_complexity, // TODO split up tests as necessary
clippy::unwrap_used, // TODO convert to expect or better error handling
)]

#[cfg(not(all(
Expand Down
3 changes: 3 additions & 0 deletions time-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ description = "This crate is an implementation detail and should not be relied u
[package.metadata.docs.rs]
rustdoc-args = ["--generate-link-to-definition"]

[lints]
workspace = true

[dependencies]
42 changes: 1 addition & 41 deletions time-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,7 @@
//! This crate is an implementation detail of `time` and should not be relied upon directly.
#![no_std]
#![deny(
anonymous_parameters,
clippy::all,
clippy::alloc_instead_of_core,
clippy::explicit_auto_deref,
clippy::obfuscated_if_else,
clippy::std_instead_of_core,
clippy::undocumented_unsafe_blocks,
illegal_floating_point_literal_pattern,
late_bound_lifetime_arguments,
path_statements,
patterns_in_fns_without_body,
rust_2018_idioms,
trivial_casts,
trivial_numeric_casts,
unreachable_pub,
unsafe_op_in_unsafe_fn,
unused_extern_crates,
rustdoc::broken_intra_doc_links,
rustdoc::private_intra_doc_links
)]
#![warn(
clippy::dbg_macro,
clippy::decimal_literal_representation,
clippy::get_unwrap,
clippy::missing_docs_in_private_items,
clippy::nursery,
clippy::print_stdout,
clippy::todo,
clippy::unimplemented,
clippy::unnested_or_patterns,
clippy::unwrap_in_result,
clippy::unwrap_used,
clippy::use_debug,
deprecated_in_future,
missing_copy_implementations,
missing_debug_implementations,
unused_qualifications,
variant_size_differences
)]
#![allow(clippy::redundant_pub_crate)]
#![allow(missing_docs)] // TODO remove
#![doc(html_favicon_url = "https://avatars0.githubusercontent.com/u/55999857")]
#![doc(html_logo_url = "https://avatars0.githubusercontent.com/u/55999857")]
#![doc(test(attr(deny(warnings))))]
Expand Down
3 changes: 3 additions & 0 deletions time-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@ proc-macro = true
[package.metadata.docs.rs]
rustdoc-args = ["--generate-link-to-definition"]

[lints]
workspace = true

[dependencies]
time-core = { workspace = true }
39 changes: 7 additions & 32 deletions time-macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,12 @@
#![deny(
anonymous_parameters,
clippy::all,
illegal_floating_point_literal_pattern,
late_bound_lifetime_arguments,
path_statements,
patterns_in_fns_without_body,
rust_2018_idioms,
trivial_casts,
trivial_numeric_casts,
unreachable_pub,
unsafe_code,
unused_extern_crates
)]
#![warn(
clippy::dbg_macro,
clippy::decimal_literal_representation,
clippy::get_unwrap,
clippy::nursery,
clippy::print_stdout,
clippy::todo,
clippy::unimplemented,
clippy::unnested_or_patterns,
clippy::unwrap_used,
clippy::use_debug,
single_use_lifetimes,
unused_qualifications,
variant_size_differences
)]
#![allow(
clippy::missing_const_for_fn, // useless in proc macro
clippy::redundant_pub_crate, // suggests bad style
clippy::option_if_let_else, // suggests terrible code
clippy::missing_const_for_fn, // irrelevant for proc macros
clippy::missing_docs_in_private_items, // TODO remove
clippy::std_instead_of_core, // irrelevant for proc macros
clippy::std_instead_of_alloc, // irrelevant for proc macros
clippy::alloc_instead_of_core, // irrelevant for proc macros
missing_docs, // TODO remove
)]

#[allow(unused_macros)]
macro_rules! bug {
() => { compile_error!("provide an error message to help fix a possible bug") };
Expand Down
1 change: 1 addition & 0 deletions time-macros/src/to_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::num::NonZeroU16;

use proc_macro::{Group, Ident, Literal, Punct, Span, TokenStream, TokenTree};

/// Turn a type into a [`TokenStream`].
pub(crate) trait ToTokenStream: Sized {
fn append_to(self, ts: &mut TokenStream);
}
Expand Down
3 changes: 3 additions & 0 deletions time/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ include = ["src/**/*", "LICENSE-*", "README.md"]
[lib]
bench = false

[lints]
workspace = true

[package.metadata.docs.rs]
all-features = true
targets = ["x86_64-unknown-linux-gnu"]
Expand Down
Loading

0 comments on commit 79e4437

Please sign in to comment.