From d5344dc1789ccf528e23f786693f4441bff90f64 Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Mon, 5 Feb 2024 15:44:08 +0100 Subject: [PATCH] Add `rustfmt` to CI, ignore all files We add the previously discussed `rustfmt.toml` and enforce it in CI for any files that are not contained in an exclusion list. To start, we add all current Rust files to this exclusion list. This means that formatter rules will be enforced for any newly introduced files, and we'll then start going through the codebase file-by-file, removing them from the list as we go. --- .github/workflows/build.yml | 17 +++ ci/rustfmt.sh | 13 ++ rustfmt.toml | 13 +- rustfmt_excluded_files | 270 ++++++++++++++++++++++++++++++++++++ 4 files changed, 312 insertions(+), 1 deletion(-) create mode 100755 ci/rustfmt.sh create mode 100644 rustfmt_excluded_files diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ab10b36d2..0b03e4644 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -216,3 +216,20 @@ jobs: - name: Run default clippy linting run: | cargo clippy -- -Aclippy::erasing_op -Aclippy::never_loop -Aclippy::if_same_then_else -Dclippy::try_err + + rustfmt: + runs-on: ubuntu-latest + env: + TOOLCHAIN: 1.63.0 + steps: + - name: Checkout source code + uses: actions/checkout@v3 + - name: Install Rust ${{ env.TOOLCHAIN }} toolchain + run: | + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal --default-toolchain ${{ env.TOOLCHAIN }} + rustup override set ${{ env.TOOLCHAIN }} + - name: Install rustfmt + run: | + rustup component add rustfmt + - name: Run rustfmt checks + run: ci/rustfmt.sh diff --git a/ci/rustfmt.sh b/ci/rustfmt.sh new file mode 100755 index 000000000..dfc181dee --- /dev/null +++ b/ci/rustfmt.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -eox pipefail + +# Generate initial exclusion list +#find . -name '*.rs' -type f |sort >rustfmt_excluded_files + +# Run fmt +TMP_FILE=$(mktemp) +find . -name '*.rs' -type f |sort >$TMP_FILE +for file in $(comm -23 $TMP_FILE rustfmt_excluded_files); do + echo "Checking formatting of $file" + rustfmt +1.63.0 --check $file +done diff --git a/rustfmt.toml b/rustfmt.toml index 91b802328..027fcfc65 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1 +1,12 @@ -disable_all_formatting = true \ No newline at end of file +use_small_heuristics = "Max" +fn_args_layout = "Compressed" +hard_tabs = true +use_field_init_shorthand = true +max_width = 100 +match_block_trailing_comma = true +# UNSTABLE: format_code_in_doc_comments = true +# UNSTABLE: overflow_delimited_expr = true +# UNSTABLE: comment_width = 100 +# UNSTABLE: format_macro_matchers = true +# UNSTABLE: format_strings = true +# UNSTABLE: group_imports = "StdExternalCrate" diff --git a/rustfmt_excluded_files b/rustfmt_excluded_files new file mode 100644 index 000000000..f5c7323d2 --- /dev/null +++ b/rustfmt_excluded_files @@ -0,0 +1,270 @@ +./bench/benches/bench.rs +./fuzz/src/base32.rs +./fuzz/src/bech32_parse.rs +./fuzz/src/bin/base32_target.rs +./fuzz/src/bin/bech32_parse_target.rs +./fuzz/src/bin/chanmon_consistency_target.rs +./fuzz/src/bin/chanmon_deser_target.rs +./fuzz/src/bin/fromstr_to_netaddress_target.rs +./fuzz/src/bin/full_stack_target.rs +./fuzz/src/bin/indexedmap_target.rs +./fuzz/src/bin/invoice_deser_target.rs +./fuzz/src/bin/invoice_request_deser_target.rs +./fuzz/src/bin/msg_accept_channel_target.rs +./fuzz/src/bin/msg_accept_channel_v2_target.rs +./fuzz/src/bin/msg_announcement_signatures_target.rs +./fuzz/src/bin/msg_channel_announcement_target.rs +./fuzz/src/bin/msg_channel_details_target.rs +./fuzz/src/bin/msg_channel_ready_target.rs +./fuzz/src/bin/msg_channel_reestablish_target.rs +./fuzz/src/bin/msg_channel_update_target.rs +./fuzz/src/bin/msg_closing_signed_target.rs +./fuzz/src/bin/msg_commitment_signed_target.rs +./fuzz/src/bin/msg_decoded_onion_error_packet_target.rs +./fuzz/src/bin/msg_error_message_target.rs +./fuzz/src/bin/msg_funding_created_target.rs +./fuzz/src/bin/msg_funding_signed_target.rs +./fuzz/src/bin/msg_gossip_timestamp_filter_target.rs +./fuzz/src/bin/msg_init_target.rs +./fuzz/src/bin/msg_node_announcement_target.rs +./fuzz/src/bin/msg_open_channel_target.rs +./fuzz/src/bin/msg_open_channel_v2_target.rs +./fuzz/src/bin/msg_ping_target.rs +./fuzz/src/bin/msg_pong_target.rs +./fuzz/src/bin/msg_query_channel_range_target.rs +./fuzz/src/bin/msg_query_short_channel_ids_target.rs +./fuzz/src/bin/msg_reply_channel_range_target.rs +./fuzz/src/bin/msg_reply_short_channel_ids_end_target.rs +./fuzz/src/bin/msg_revoke_and_ack_target.rs +./fuzz/src/bin/msg_shutdown_target.rs +./fuzz/src/bin/msg_splice_ack_target.rs +./fuzz/src/bin/msg_splice_locked_target.rs +./fuzz/src/bin/msg_splice_target.rs +./fuzz/src/bin/msg_stfu_target.rs +./fuzz/src/bin/msg_tx_abort_target.rs +./fuzz/src/bin/msg_tx_ack_rbf_target.rs +./fuzz/src/bin/msg_tx_add_input_target.rs +./fuzz/src/bin/msg_tx_add_output_target.rs +./fuzz/src/bin/msg_tx_complete_target.rs +./fuzz/src/bin/msg_tx_init_rbf_target.rs +./fuzz/src/bin/msg_tx_remove_input_target.rs +./fuzz/src/bin/msg_tx_remove_output_target.rs +./fuzz/src/bin/msg_tx_signatures_target.rs +./fuzz/src/bin/msg_update_add_htlc_target.rs +./fuzz/src/bin/msg_update_fail_htlc_target.rs +./fuzz/src/bin/msg_update_fail_malformed_htlc_target.rs +./fuzz/src/bin/msg_update_fee_target.rs +./fuzz/src/bin/msg_update_fulfill_htlc_target.rs +./fuzz/src/bin/offer_deser_target.rs +./fuzz/src/bin/onion_hop_data_target.rs +./fuzz/src/bin/onion_message_target.rs +./fuzz/src/bin/peer_crypt_target.rs +./fuzz/src/bin/process_network_graph_target.rs +./fuzz/src/bin/refund_deser_target.rs +./fuzz/src/bin/router_target.rs +./fuzz/src/bin/zbase32_target.rs +./fuzz/src/chanmon_consistency.rs +./fuzz/src/chanmon_deser.rs +./fuzz/src/fromstr_to_netaddress.rs +./fuzz/src/full_stack.rs +./fuzz/src/indexedmap.rs +./fuzz/src/invoice_deser.rs +./fuzz/src/invoice_request_deser.rs +./fuzz/src/lib.rs +./fuzz/src/msg_targets/mod.rs +./fuzz/src/msg_targets/msg_accept_channel.rs +./fuzz/src/msg_targets/msg_accept_channel_v2.rs +./fuzz/src/msg_targets/msg_announcement_signatures.rs +./fuzz/src/msg_targets/msg_channel_announcement.rs +./fuzz/src/msg_targets/msg_channel_details.rs +./fuzz/src/msg_targets/msg_channel_ready.rs +./fuzz/src/msg_targets/msg_channel_reestablish.rs +./fuzz/src/msg_targets/msg_channel_update.rs +./fuzz/src/msg_targets/msg_closing_signed.rs +./fuzz/src/msg_targets/msg_commitment_signed.rs +./fuzz/src/msg_targets/msg_decoded_onion_error_packet.rs +./fuzz/src/msg_targets/msg_error_message.rs +./fuzz/src/msg_targets/msg_funding_created.rs +./fuzz/src/msg_targets/msg_funding_signed.rs +./fuzz/src/msg_targets/msg_gossip_timestamp_filter.rs +./fuzz/src/msg_targets/msg_init.rs +./fuzz/src/msg_targets/msg_node_announcement.rs +./fuzz/src/msg_targets/msg_open_channel.rs +./fuzz/src/msg_targets/msg_open_channel_v2.rs +./fuzz/src/msg_targets/msg_ping.rs +./fuzz/src/msg_targets/msg_pong.rs +./fuzz/src/msg_targets/msg_query_channel_range.rs +./fuzz/src/msg_targets/msg_query_short_channel_ids.rs +./fuzz/src/msg_targets/msg_reply_channel_range.rs +./fuzz/src/msg_targets/msg_reply_short_channel_ids_end.rs +./fuzz/src/msg_targets/msg_revoke_and_ack.rs +./fuzz/src/msg_targets/msg_shutdown.rs +./fuzz/src/msg_targets/msg_splice.rs +./fuzz/src/msg_targets/msg_splice_ack.rs +./fuzz/src/msg_targets/msg_splice_locked.rs +./fuzz/src/msg_targets/msg_stfu.rs +./fuzz/src/msg_targets/msg_tx_abort.rs +./fuzz/src/msg_targets/msg_tx_ack_rbf.rs +./fuzz/src/msg_targets/msg_tx_add_input.rs +./fuzz/src/msg_targets/msg_tx_add_output.rs +./fuzz/src/msg_targets/msg_tx_complete.rs +./fuzz/src/msg_targets/msg_tx_init_rbf.rs +./fuzz/src/msg_targets/msg_tx_remove_input.rs +./fuzz/src/msg_targets/msg_tx_remove_output.rs +./fuzz/src/msg_targets/msg_tx_signatures.rs +./fuzz/src/msg_targets/msg_update_add_htlc.rs +./fuzz/src/msg_targets/msg_update_fail_htlc.rs +./fuzz/src/msg_targets/msg_update_fail_malformed_htlc.rs +./fuzz/src/msg_targets/msg_update_fee.rs +./fuzz/src/msg_targets/msg_update_fulfill_htlc.rs +./fuzz/src/msg_targets/msg_warning_message.rs +./fuzz/src/msg_targets/utils.rs +./fuzz/src/offer_deser.rs +./fuzz/src/onion_hop_data.rs +./fuzz/src/onion_message.rs +./fuzz/src/peer_crypt.rs +./fuzz/src/process_network_graph.rs +./fuzz/src/refund_deser.rs +./fuzz/src/router.rs +./fuzz/src/utils/mod.rs +./fuzz/src/utils/test_logger.rs +./fuzz/src/utils/test_persister.rs +./fuzz/src/zbase32.rs +./lightning-background-processor/src/lib.rs +./lightning-block-sync/src/convert.rs +./lightning-block-sync/src/gossip.rs +./lightning-block-sync/src/http.rs +./lightning-block-sync/src/init.rs +./lightning-block-sync/src/lib.rs +./lightning-block-sync/src/poll.rs +./lightning-block-sync/src/rest.rs +./lightning-block-sync/src/rpc.rs +./lightning-block-sync/src/test_utils.rs +./lightning-block-sync/src/utils.rs +./lightning-custom-message/src/lib.rs +./lightning-invoice/fuzz/fuzz_targets/serde_data_part.rs +./lightning-invoice/src/de.rs +./lightning-invoice/src/lib.rs +./lightning-invoice/src/payment.rs +./lightning-invoice/src/ser.rs +./lightning-invoice/src/tb.rs +./lightning-invoice/src/utils.rs +./lightning-invoice/tests/ser_de.rs +./lightning-net-tokio/src/lib.rs +./lightning-persister/src/fs_store.rs +./lightning-persister/src/lib.rs +./lightning-persister/src/test_utils.rs +./lightning-persister/src/utils.rs +./lightning-rapid-gossip-sync/src/error.rs +./lightning-rapid-gossip-sync/src/lib.rs +./lightning-rapid-gossip-sync/src/processing.rs +./lightning-transaction-sync/src/common.rs +./lightning-transaction-sync/src/electrum.rs +./lightning-transaction-sync/src/error.rs +./lightning-transaction-sync/src/esplora.rs +./lightning-transaction-sync/src/lib.rs +./lightning-transaction-sync/tests/integration_tests.rs +./lightning/src/blinded_path/message.rs +./lightning/src/blinded_path/mod.rs +./lightning/src/blinded_path/payment.rs +./lightning/src/blinded_path/utils.rs +./lightning/src/chain/chaininterface.rs +./lightning/src/chain/chainmonitor.rs +./lightning/src/chain/channelmonitor.rs +./lightning/src/chain/mod.rs +./lightning/src/chain/onchaintx.rs +./lightning/src/chain/package.rs +./lightning/src/chain/transaction.rs +./lightning/src/crypto/chacha20.rs +./lightning/src/crypto/chacha20poly1305rfc.rs +./lightning/src/crypto/mod.rs +./lightning/src/crypto/poly1305.rs +./lightning/src/crypto/streams.rs +./lightning/src/crypto/utils.rs +./lightning/src/events/bump_transaction.rs +./lightning/src/events/mod.rs +./lightning/src/lib.rs +./lightning/src/ln/async_signer_tests.rs +./lightning/src/ln/blinded_payment_tests.rs +./lightning/src/ln/chan_utils.rs +./lightning/src/ln/chanmon_update_fail_tests.rs +./lightning/src/ln/channel.rs +./lightning/src/ln/channel_id.rs +./lightning/src/ln/channel_keys.rs +./lightning/src/ln/channelmanager.rs +./lightning/src/ln/features.rs +./lightning/src/ln/functional_test_utils.rs +./lightning/src/ln/functional_tests.rs +./lightning/src/ln/inbound_payment.rs +./lightning/src/ln/mod.rs +./lightning/src/ln/monitor_tests.rs +./lightning/src/ln/msgs.rs +./lightning/src/ln/offers_tests.rs +./lightning/src/ln/onion_payment.rs +./lightning/src/ln/onion_route_tests.rs +./lightning/src/ln/onion_utils.rs +./lightning/src/ln/outbound_payment.rs +./lightning/src/ln/payment_tests.rs +./lightning/src/ln/peer_channel_encryptor.rs +./lightning/src/ln/peer_handler.rs +./lightning/src/ln/priv_short_conf_tests.rs +./lightning/src/ln/reload_tests.rs +./lightning/src/ln/reorg_tests.rs +./lightning/src/ln/script.rs +./lightning/src/ln/shutdown_tests.rs +./lightning/src/ln/wire.rs +./lightning/src/offers/invoice.rs +./lightning/src/offers/invoice_error.rs +./lightning/src/offers/invoice_request.rs +./lightning/src/offers/merkle.rs +./lightning/src/offers/mod.rs +./lightning/src/offers/offer.rs +./lightning/src/offers/parse.rs +./lightning/src/offers/payer.rs +./lightning/src/offers/refund.rs +./lightning/src/offers/signer.rs +./lightning/src/offers/test_utils.rs +./lightning/src/onion_message/functional_tests.rs +./lightning/src/onion_message/messenger.rs +./lightning/src/onion_message/mod.rs +./lightning/src/onion_message/offers.rs +./lightning/src/onion_message/packet.rs +./lightning/src/routing/gossip.rs +./lightning/src/routing/mod.rs +./lightning/src/routing/router.rs +./lightning/src/routing/scoring.rs +./lightning/src/routing/test_utils.rs +./lightning/src/routing/utxo.rs +./lightning/src/sign/ecdsa.rs +./lightning/src/sign/mod.rs +./lightning/src/sign/taproot.rs +./lightning/src/sign/type_resolver.rs +./lightning/src/sync/debug_sync.rs +./lightning/src/sync/fairrwlock.rs +./lightning/src/sync/mod.rs +./lightning/src/sync/nostd_sync.rs +./lightning/src/sync/test_lockorder_checks.rs +./lightning/src/util/atomic_counter.rs +./lightning/src/util/base32.rs +./lightning/src/util/byte_utils.rs +./lightning/src/util/config.rs +./lightning/src/util/errors.rs +./lightning/src/util/fuzz_wrappers.rs +./lightning/src/util/indexed_map.rs +./lightning/src/util/invoice.rs +./lightning/src/util/logger.rs +./lightning/src/util/macro_logger.rs +./lightning/src/util/message_signing.rs +./lightning/src/util/mod.rs +./lightning/src/util/persist.rs +./lightning/src/util/scid_utils.rs +./lightning/src/util/ser.rs +./lightning/src/util/ser_macros.rs +./lightning/src/util/string.rs +./lightning/src/util/test_channel_signer.rs +./lightning/src/util/test_utils.rs +./lightning/src/util/time.rs +./lightning/src/util/transaction_utils.rs +./lightning/src/util/wakers.rs +./msrv-no-dev-deps-check/src/lib.rs +./no-std-check/src/lib.rs -- 2.39.5