Skip to content

Commit 736a5a9

Browse files
authored
Merge pull request #167 from enigbe/chore-consistent-formating-across-repo
chore: add rustfmt and clippy
2 parents 3050a6d + 731d71d commit 736a5a9

File tree

8 files changed

+81
-27
lines changed

8 files changed

+81
-27
lines changed

.github/workflows/build-and-test.yml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@ permissions:
66
contents: read
77

88
jobs:
9-
clippy:
10-
name: Lint
9+
check:
10+
name: Check Code with stable output
1111
runs-on: ubuntu-latest
1212
steps:
13+
- name: Install protoc
14+
run: sudo apt install -y protobuf-compiler
1315
- uses: actions/checkout@v4
1416
- uses: dtolnay/rust-toolchain@stable
15-
with:
16-
components: clippy
17-
- uses: giraffate/clippy-action@v1
18-
with:
19-
reporter: github-pr-review
20-
github_token: ${{ secrets.GITHUB_TOKEN }}
21-
clippy_flags: --all-features --all-targets --color always -- --deny warnings
17+
- name: run check
18+
run: make check
2219

2320
build:
2421
name: Build and test

CONTRIBUTING.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
## Contributing
2+
3+
SimLN is open and welcomes contributions from the community. A good place to start if you have questions is our [discussions forum](https://github.com/bitcoin-dev-project/sim-ln/discussions/123).
4+
5+
## Pull Request (PR) Requirements
6+
7+
The list below contains mandatory checks to be adhered to before a PR can be opened and/or reviewed.
8+
9+
1. [Testing](#testing)
10+
2. [Formating and Linting](#formatting-and-linting)
11+
4. [Commit history](#commit-history)
12+
13+
**Note**: Reviews are contigent on these checks passing locally and in CI.
14+
15+
### Testing
16+
17+
All tests must pass. Do so by running the command
18+
19+
```sh
20+
$ cargo test
21+
```
22+
23+
### Formatting and Linting
24+
25+
Formatting and linting should adhere to the rules specified by default and/or specifically in `rustfmt.toml`. Adhere to the linter suggestions made by `clippy`.
26+
In addition to these check, the recipe `stable-output` ensures consistent and reliable output locally and in CI environment.
27+
28+
```sh
29+
$ make check
30+
```
31+
32+
### Commit history
33+
34+
- Have a clean commit history: It is preferable to use [fixup and squash](https://andrewlock.net/smoother-rebases-with-auto-squashing-git-commits/) in addressing feedback from PR review. The former (i.e. `fixup`) for the commits they apply to (during review), and latter (`squash`) once review is complete.
35+
- Use [good commit messages](https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html)
36+
- Resolve all conflicts
37+
- Rebase often

Makefile

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,18 @@ run-interactive:
3131
docker run -it --rm --name sim-ln --init -v simln-data:${DEFAULT_DATA_DIR} -e SIMFILE_PATH=${DEFAULT_SIMFILE_PATH} -e DATA_DIR=${DATA_DIR} -e LOG_LEVEL=$(LOG_LEVEL) -e HELP=${HELP} -e PRINT_BATCH_SIZE=${PRINT_BATCH_SIZE} -e TOTAL_TIME=${TOTAL_TIME} sim-ln
3232

3333
stop-docker:
34-
docker stop sim-ln
34+
docker stop sim-ln
35+
36+
check-code:
37+
cargo fmt --check --all
38+
cargo clippy --all-features
39+
40+
stable-output:
41+
@if [ -n "$$(git status --porcelain)" ]; then \
42+
echo "Error: There are unstaged or uncommitted changes after running 'make check-code'."; \
43+
exit 1; \
44+
else \
45+
echo "No unstaged or uncommitted changes found."; \
46+
fi
47+
48+
check: check-code stable-output

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ sim-cli
4949

5050
Run `sim-cli -h` for details on `--data-dir` and `--sim-file` options that allow specifying custom simulation file locations.
5151

52+
Interested in contributing to the project? See [CONTRIBUTING](CONTRIBUTING.md) for more details.
53+
5254
### Simulation File Setup
5355
The simulator requires access details for a set of `nodes` that you
5456
have permission to execute commands on. Note that the current version
@@ -207,4 +209,4 @@ see the [Scaling Lightning](https://github.com/scaling-lightning/scaling-lightni
207209
project.
208210

209211
## Docker
210-
If you want to run the cli in a containerized environment, see the docker set up docs [here](./docker/README.md)
212+
If you want to run the cli in a containerized environment, see the docker set up docs [here](./docker/README.md)

rustfmt.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
edition = "2021"
2+
match_block_trailing_comma = true
3+
newline_style = "Unix"
4+
use_try_shorthand = true

sim-cli/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn deserialize_f64_greater_than_zero(x: String) -> Result<f64, String> {
4040
"capacity_multiplier must be higher than 0. {x} received."
4141
))
4242
}
43-
}
43+
},
4444
Err(e) => Err(e.to_string()),
4545
}
4646
}
@@ -159,7 +159,7 @@ async fn main() -> anyhow::Result<()> {
159159
act.destination
160160
)));
161161
}
162-
}
162+
},
163163
NodeId::PublicKey(pk) => {
164164
if let Some(info) = pk_node_map.get(pk) {
165165
info.clone()
@@ -179,7 +179,7 @@ async fn main() -> anyhow::Result<()> {
179179
))
180180
})?
181181
}
182-
}
182+
},
183183
};
184184

185185
validated_activities.push(ActivityDefinition {

sim-lib/src/lib.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ impl NodeId {
5151
return Err(LightningError::ValidationError(format!(
5252
"the provided node id does not match the one returned by the backend ({} != {}).", pk, node_id)));
5353
}
54-
}
54+
},
5555
crate::NodeId::Alias(a) => {
5656
if alias != a {
5757
log::warn!("The provided alias does not match the one returned by the backend ({} != {}).", a, alias)
5858
}
5959
*alias = a.to_string();
60-
}
60+
},
6161
}
6262
Ok(())
6363
}
@@ -752,7 +752,7 @@ async fn consume_events(
752752
// We need to track the payment outcome using the payment hash that we have received.
753753
payment.hash = Some(payment_hash);
754754
SimulationOutput::SendPaymentSuccess(payment)
755-
}
755+
},
756756
Err(e) => {
757757
log::error!(
758758
"Error while sending payment {} -> {}.",
@@ -765,23 +765,23 @@ async fn consume_events(
765765
log::error!("Simulation terminated with error: {s}.");
766766
shutdown.trigger();
767767
break;
768-
}
768+
},
769769
_ => SimulationOutput::SendPaymentFailure(
770770
payment,
771771
PaymentResult::not_dispatched(),
772772
),
773773
}
774-
}
774+
},
775775
};
776776

777777
match sender.send(outcome).await {
778-
Ok(_) => {}
778+
Ok(_) => {},
779779
Err(e) => {
780780
log::error!("Error sending action outcome: {:?}.", e);
781781
break;
782-
}
782+
},
783783
}
784-
}
784+
},
785785
};
786786
}
787787
}
@@ -1055,20 +1055,20 @@ async fn track_payment_result(
10551055
res.payment_outcome
10561056
);
10571057
res
1058-
}
1058+
},
10591059
Err(e) => {
10601060
log::error!("Track payment failed for {}: {e}.", hex::encode(hash.0));
10611061
PaymentResult::track_payment_failed()
1062-
}
1062+
},
10631063
}
1064-
}
1064+
},
10651065
// None means that the payment was not dispatched, so we cannot track it.
10661066
None => {
10671067
log::error!(
10681068
"We cannot track a payment that has not been dispatched. Missing payment hash."
10691069
);
10701070
PaymentResult::not_dispatched()
1071-
}
1071+
},
10721072
};
10731073

10741074
if results.clone().send((payment, res)).await.is_err() {

sim-lib/src/lnd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl LightningNode for LndNode {
127127
return Err(LightningError::ValidationError(
128128
"simnet is not supported".to_string(),
129129
))
130-
}
130+
},
131131
x => x,
132132
})
133133
.map_err(|err| LightningError::ValidationError(err.to_string()))?)

0 commit comments

Comments
 (0)