Skip to content

Commit 63dd724

Browse files
author
Brian Obot
committed
Add Pre-commit to repo
1 parent 74d5296 commit 63dd724

49 files changed

Lines changed: 276 additions & 89 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Quality Check & PR to Master
2+
3+
on:
4+
push:
5+
branches:
6+
- dev
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout Code
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: '3.11' # You can change this to your preferred version
20+
cache: 'pip'
21+
22+
- name: Install Dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
26+
pip install pytest # Ensures pytest is available even if not in requirements.txt
27+
28+
# - name: Create .env file
29+
# run: |
30+
31+
# - name: Run Tests
32+
# run: |
33+
# mkdir logs
34+
# pytest -s
35+
36+
create_pull_request:
37+
runs-on: ubuntu-latest
38+
needs: test # This creates the dependency link
39+
if: github.actor == 'brianobot'
40+
permissions:
41+
contents: write
42+
pull-requests: write
43+
env:
44+
GITHUB_TOKEN: ${{ secrets.MY_PERSONAL_TOKEN }}
45+
steps:
46+
- name: Checkout Code
47+
uses: actions/checkout@v4
48+
49+
- name: Create Pull Request
50+
run: |
51+
# Check if a PR already exists from dev to master
52+
PR_EXISTS=$(gh pr list --head dev --base master --state open --json number -q '.[0].number')
53+
54+
if [ -z "$PR_EXISTS" ]; then
55+
echo "No open PR found. Creating a new one..."
56+
gh pr create \
57+
--head dev \
58+
--base master \
59+
--title "Auto-PR: Dev to Master" \
60+
--body "Automated PR triggered by push from ${{ github.actor }}" \
61+
--assignee "${{ github.actor }}"
62+
else
63+
echo "PR already exists: #$PR_EXISTS. Skipping creation."
64+
fi

.pre-commit-config.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
repos:
2+
- repo: local
3+
hooks:
4+
- id: rustfmt
5+
name: rustfmt
6+
entry: cargo fmt --all -- --check
7+
language: system
8+
types: [rust]
9+
pass_filenames: false
10+
11+
- id: cargo-check
12+
name: cargo-check
13+
entry: cargo check
14+
language: system
15+
types: [rust]
16+
pass_filenames: false
17+
18+
- id: clippy
19+
name: clippy
20+
entry: cargo clippy -- -D warnings
21+
language: system
22+
types: [rust]
23+
pass_filenames: false

src/bin/01_variables.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn main() {
2323
// causes the compiler to produce an error message, so only use mut if you indeed need to mutate
2424
// the variable in question
2525
println!("The value of y is {y}");
26-
y = y + 10;
26+
y += 10;
2727
println!("The new value of y is {y}");
2828

2929
// CONSTANTS are not allowed to be made mutable, they are always immutable
@@ -73,7 +73,7 @@ fn main() {
7373

7474
timeout = 12.10;
7575

76-
timeout -= 1 as f32;
76+
timeout -= 1f32;
7777

7878
println!("Timeout = {timeout}");
7979

@@ -134,7 +134,8 @@ fn main() {
134134
x += 10;
135135
println!("X = {x}");
136136

137-
let ass_val = x = 10;
137+
#[allow(clippy::let_unit_value)]
138+
let _ass_val = x = 10;
138139
println!("X = {}", x);
139-
println!("Assigment value = {:?}", ass_val);
140+
println!("Assigment value = {:?}", ());
140141
}

src/bin/02_data_types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ fn main() {
3232
// you can mix underscore and type suffix to better indicate the type of an integer
3333
//
3434
let _rating = 24_u8; // the underscore is ignore and only needed to make it easier to read
35-
let _score = 25__u16;
35+
let _score = 25_u16;
3636

3737
let some_value = 123u16;
3838
println!("Some Value = {:?}", some_value);
3939

4040
// floating point type
41-
let _rating = 5__f32; // again the underscore is ignored
41+
let _rating = 5_f32; // again the underscore is ignored
4242
let _average = 32f64;
4343

4444
// the floating point type has associated constant to meet IEEE specs

src/bin/02b_literals.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::nonminimal_bool)]
2+
13
fn main() {
24
// integers 1
35
// floats 1.23

src/bin/02e_vectors.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::vec_init_then_push)]
2+
13
use std::vec;
24

35
fn main() {
@@ -14,6 +16,7 @@ fn main() {
1416

1517
// you can pop elements from the vector
1618
let last_value = data.pop();
19+
#[allow(clippy::unnecessary_unwrap)]
1720
if last_value.is_some() {
1821
println!("Popped value: {}", last_value.unwrap());
1922
}
@@ -98,6 +101,7 @@ fn main() {
98101
// we can emulate the behaviour of storing different types in a vector
99102
// by storying an enum that can hold different types
100103

104+
#[allow(clippy::enum_variant_names)]
101105
#[derive(Debug)]
102106
enum FieldType {
103107
SmallIntegerField(i8),
@@ -119,13 +123,14 @@ fn main() {
119123
}
120124
}
121125

126+
#[allow(clippy::vec_init_then_push)]
122127
let mut columns: Vec<FieldType> = Vec::new();
123128

124129
columns.push(FieldType::IntergerField(10));
125130
columns.push(FieldType::SmallIntegerField(10));
126131
columns.push(FieldType::BigIntergerField(10000000));
127132
columns.push(FieldType::StringField("Hello".to_string()));
128-
columns.push(FieldType::FloatField(3.14));
133+
columns.push(FieldType::FloatField(3.146565));
129134

130135
println!("Columns = {:?}", columns);
131136

@@ -145,6 +150,7 @@ fn main() {
145150
println!("Reversed data = {:?}", data);
146151

147152
let mut names = vec!["John", "Doe", "Jane", "Doe", "Alice", "Bob"];
153+
#[allow(clippy::unnecessary_sort_by)]
148154
names.sort_by(|a, b| a.len().cmp(&b.len()));
149155
println!("Sorted names = {:?}", names);
150156

@@ -174,6 +180,7 @@ fn main() {
174180
);
175181

176182
// an example to convert an vector of &str types to a vector String types
183+
#[allow(clippy::useless_vec)]
177184
let names = vec!["james", "paul", "okon", "obot", "abasifreke"]
178185
.iter_mut()
179186
.map(|x| x.to_string())

src/bin/02g_expression.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ fn main() {
5050
#[allow(dead_code)]
5151
fn show_files() -> std::io::Result<()> {
5252
#[allow(dead_code)]
53+
#[allow(clippy::useless_vec)]
5354
let mut _v = vec![1, 2, 3];
5455

5556
// perfectly valid rust code
@@ -89,7 +90,7 @@ fn main() {
8990
println!("Current Value = {start}");
9091
start += 1;
9192

92-
if start % 24 == 0 {
93+
if start.is_multiple_of(24) {
9394
break start; // you can use break to return values from a loop in rust
9495
}
9596
};
@@ -117,10 +118,10 @@ fn main() {
117118
break 'search;
118119
}
119120
}
120-
println!("");
121+
println!(" ");
121122
temp += 2;
122123
}
123-
println!("");
124+
println!(" ");
124125

125126
// a break can have a label and a value but both are optional
126127
// break - empty break
@@ -170,7 +171,7 @@ fn partition<T: Ord>(slice: &mut [T]) -> usize {
170171

171172
for j in 0..pivot_index {
172173
if slice[j] <= slice[pivot_index] {
173-
i = i + 1isize;
174+
i += 1isize;
174175
slice.swap(i as usize, j);
175176
}
176177
}

src/bin/03_functions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,5 @@ fn with_return_value() -> u32 {
6161
}
6262

6363
fn with_return_keyword() -> f64 {
64-
return 64.0;
64+
64.0
6565
}

src/bin/03b_more_on_functions.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ fn main() {
3030
// the by value captures usually occurs for type that are non_copy
3131
// to force closure to capture a variable by value, use the keyword move before the pipes
3232

33+
#[allow(clippy::useless_vec)]
3334
let haystack = vec![1, 2, 3, 4];
3435
let contains = move |needle: i32| haystack.contains(&needle);
3536

@@ -90,6 +91,7 @@ impl _Box {
9091

9192
// &self is usually used in place of the full form self: &Self, where Self point to the type the function is
9293
// defined on, self gives access to the type fields via dot notation
94+
#[allow(clippy::needless_arbitrary_self_type)]
9395
fn _area(self: &Self) -> u8 {
9496
self.width * self.heigth
9597
}

src/bin/03c_diverging_functions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![allow(unreachable_code)]
2+
#![allow(clippy::diverging_sub_expression)]
23

34
fn main() {
45
// diverging functions are functions that never return,

0 commit comments

Comments
 (0)