Skip to content

Commit

Permalink
Wordy: update fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Ephraim-nonso committed Oct 17, 2024
2 parents 26ff5d6 + 2b54929 commit 925e6af
Show file tree
Hide file tree
Showing 275 changed files with 4,788 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938

- name: Run markdown lint
run: ./bin/lint_markdown.sh

configlet:
name: configlet lint + fmt
uses: exercism/github-actions/.github/workflows/configlet.yml@main
with:
fmt: true
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938

- name: Run shellcheck
uses: ludeeus/action-shellcheck@00cae500b08a931fb5698e11e79bfbd38e612a38
Expand All @@ -30,7 +30,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938

- name: Fetch origin/main
run: git fetch --depth=1 origin main
Expand All @@ -51,7 +51,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938

- name: Getting scarb
uses: software-mansion/setup-scarb@v1
Expand Down
24 changes: 24 additions & 0 deletions .markdownlint-cli2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
globs:
- "concepts/**/*.md"
- "exercises/concept/**/*.md"
- "exercises/practice/*/.docs/{hints.md,*.append.md}"

config:
MD001: true
MD002: true
MD003:
style: "atx"
MD004:
style: dash
MD013: false
MD033: false
MD034:
severity: error
MD054:
autolink: false
inline: false
shortcut: false
collapsed: false

customRules:
- "single-sentence-per-line-rule.js"
1 change: 0 additions & 1 deletion .markdownlint.yaml

This file was deleted.

30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,36 @@ Basic linting finished successfully:
- Required shared exercise docs are present
```
### Markdown linting
To check for markdown files' formatting issues, open a bash terminal and run:
```shell
./bin/lint_markdown.sh
```
You can even pass the `--fix` flag to automatically fix those issues that can be fixed automatically:
```shell
./bin/lint_markdown.sh --fix
```
### Exercise formatting
To format Cairo files, open a bash terminal and run:
```shell
./bin/format_exercises.sh
```
### Format all
To run all formatting scripts at once, open a bash terminal and run:
```shell
./bin/format_all.sh
```
<br>
Expand Down
6 changes: 6 additions & 0 deletions bin/format_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -eo pipefail

./bin/lint_markdown.sh --fix
./bin/configlet fmt -uy
./bin/format_exercises.sh
5 changes: 5 additions & 0 deletions bin/format_exercises.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ for exercise_dir in $exercises; do

exercise=$(basename "$exercise_dir")

if [ ! -s "$exercise_dir/Scarb.toml" ]; then
echo "Exercise $exercise is just a stub, skipping"
continue
fi

# scarb fmt cannot currently format individual files, so we have to
# temporarily move the solution files into the Cairo package, where
# 'scarb fmt' can format it as well
Expand Down
2 changes: 1 addition & 1 deletion bin/lint_markdown.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
set -eo pipefail

npx markdownlint-cli2 docs/*.md concepts/**/*.md
npx markdownlint-cli2 "$@"
6 changes: 6 additions & 0 deletions bin/verify-exercises
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ for exercise_path in $exercises; do
cd "$repo"

exercise=$(basename "$exercise_path")

if [ ! -s "$exercise_path/Scarb.toml" ]; then
echo "Exercise $exercise is just a stub, skipping"
continue
fi

echo "Checking $exercise exercise..."

tmp_dir=$(mktemp -d)
Expand Down
25 changes: 18 additions & 7 deletions concepts/arrays/about.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Arrays

In Cairo, an array is a data structure that allows you to store a collection of elements of the same type. Arrays in Cairo have limited modification options. You can only append items to the end of an array and remove items from the front. Arrays are, in fact, queues whose values can't be modified.
In Cairo, an array is a data structure that allows you to store a collection of elements of the same type.
Arrays in Cairo have limited modification options.
You can only append items to the end of an array and remove items from the front.
Arrays are, in fact, queues whose values can't be modified.

## Array Construction

Expand Down Expand Up @@ -30,7 +33,8 @@ arr_implicit_type.append(2);
## Removing Array Elements

The only way to remove elements from an array in Cairo is from the front. This operation is facilitated by the `pop_front()` method, which returns an `Option` that can be unwrapped, containing the removed element, or `Option::None` if the array is empty.
The only way to remove elements from an array in Cairo is from the front.
This operation is facilitated by the `pop_front()` method, which returns an `Option` that can be unwrapped, containing the removed element, or `Option::None` if the array is empty.

```rust
fn main() {
Expand All @@ -42,7 +46,8 @@ fn main() {

## Accessing Values in an Array

To access array elements, you can use `get()` or `at()` array methods that return different types. An equivalent to `arr.at(index)` is the subscripting operator `arr[index]`.
To access array elements, you can use `get()` or `at()` array methods that return different types.
An equivalent to `arr.at(index)` is the subscripting operator `arr[index]`.

### Using get() Method

Expand All @@ -69,7 +74,9 @@ fn main() {

### Using at() Method

The `at()` method directly gives you a snapshot of the element at a specific index using the `unbox()` operation to extract the stored value from the box. A shorthand for this method is using the subscripting operator `arr[index]`. If you try to access an index that doesn't exist (out-of-bounds), the program will panic with an error.
The `at()` method directly gives you a snapshot of the element at a specific index using the `unbox()` operation to extract the stored value from the box.
A shorthand for this method is using the subscripting operator `arr[index]`.
If you try to access an index that doesn't exist (out-of-bounds), the program will panic with an error.

```rust
fn main() {
Expand All @@ -83,13 +90,16 @@ fn main() {

## Size-related Methods

To determine the number of elements in an array, use the `len()` method. The return value is of type `usize`.
To determine the number of elements in an array, use the `len()` method.
The return value is of type `usize`.

If you want to check if an array is empty or not, you can use the `is_empty()` method, which returns `true` if the array is empty and `false` otherwise.

## `Span`

`Span` is a struct that represents a snapshot of an `Array`. It is designed to provide safe and controlled access to the elements of an array without modifying the original array. `Span` is particularly useful for ensuring data integrity and avoiding borrowing issues when passing arrays between functions or when performing read-only operations.
`Span` is a struct that represents a snapshot of an `Array`.
It is designed to provide safe and controlled access to the elements of an array without modifying the original array.
`Span` is particularly useful for ensuring data integrity and avoiding borrowing issues when passing arrays between functions or when performing read-only operations.

> All methods provided by `Array` can also be used with `Span`, except for the `append()` method.
Expand All @@ -102,7 +112,8 @@ let my_span: Span<u32> = my_array.span();

## The Fixed Size `Array` Type

We write the values in a fixed-size array as a comma-separated list inside square brackets. The array’s type is written using square brackets with the type of each element, a semicolon, and then the number of elements in the array.
We write the values in a fixed-size array as a comma-separated list inside square brackets.
The array’s type is written using square brackets with the type of each element, a semicolon, and then the number of elements in the array.

```rust
let arr: [u64; 5] = [1, 2, 3, 4, 5];
Expand Down
11 changes: 9 additions & 2 deletions concepts/arrays/introduction.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Introduction

In Cairo, arrays are fundamental data structures designed to store collections of elements of the same type in a structured manner. Similar to lists in other programming languages, each element in an array is accessed by its index, allowing for efficient retrieval and manipulation.
In Cairo, arrays are fundamental data structures designed to store collections of elements of the same type in a structured manner.
Similar to lists in other programming languages, each element in an array is accessed by its index, allowing for efficient retrieval and manipulation.

Cairo arrays are immutable data structures. Elements can only be appended to the end or removed from the front of the array. This design ensures data integrity and stability, aligning with Cairo's approach to memory management. Arrays are initialized using `ArrayTrait::new()` and support type-specific declarations for element storage. Accessing elements can be done with `get()` or `at()` methods, as well as using the subscripting operator `arr[index]`. You can only remove elements from the front of an array by using the `pop_front()` function. These characteristics make Cairo arrays suitable for structured data storage and retrieval tasks.
Cairo arrays are immutable data structures.
Elements can only be appended to the end or removed from the front of the array.
This design ensures data integrity and stability, aligning with Cairo's approach to memory management.
Arrays are initialized using `ArrayTrait::new()` and support type-specific declarations for element storage.
Accessing elements can be done with `get()` or `at()` methods, as well as using the subscripting operator `arr[index]`.
You can only remove elements from the front of an array by using the `pop_front()` function.
These characteristics make Cairo arrays suitable for structured data storage and retrieval tasks.
17 changes: 12 additions & 5 deletions concepts/booleans/about.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# The Boolean Type

In Cairo, the Boolean type is essential for logical operations and conditional statements. Booleans in Cairo are one `felt252` in size, ensuring efficient use of space while maintaining the simplicity of true/false logic.
In Cairo, the Boolean type is essential for logical operations and conditional statements.
Booleans in Cairo are one `felt252` in size, ensuring efficient use of space while maintaining the simplicity of true/false logic.

The Boolean type in Cairo is specified using the keyword `bool`. This enables the declaration and manipulation of Boolean variables within the language. For instance, consider the following example:
The Boolean type in Cairo is specified using the keyword `bool`.
This enables the declaration and manipulation of Boolean variables within the language.
For instance, consider the following example:

```rust
fn main() {
Expand All @@ -11,9 +14,12 @@ fn main() {
}
```

In this example, two Boolean variables are declared. The variable `t` is assigned the value `true` and declared as a boolean type implicitly, while the variable `f` is explicitly annotated with the `bool` type and assigned the value `false`.
In this example, two Boolean variables are declared.
The variable `t` is assigned the value `true` and declared as a boolean type implicitly, while the variable `f` is explicitly annotated with the `bool` type and assigned the value `false`.

One important aspect to note is that when declaring a boolean variable in Cairo, it is mandatory to use either the `true` or `false` literals as the value. This means that integer literals, such as `0` or `1`, cannot be used as substitutes for `false` or `true`. The strict enforcement of this rule ensures type safety and prevents potential logical errors in smart contract development.
One important aspect to note is that when declaring a boolean variable in Cairo, it is mandatory to use either the `true` or `false` literals as the value.
This means that integer literals, such as `0` or `1`, cannot be used as substitutes for `false` or `true`.
The strict enforcement of this rule ensures type safety and prevents potential logical errors in smart contract development.

## Boolean Operators in Cairo

Expand All @@ -23,7 +29,8 @@ One important aspect to note is that when declaring a boolean variable in Cairo,

## Example Code

The following code snippet demonstrates how to use boolean types in Cairo. It shows the declaration of boolean variables, assignment of boolean expressions, and usage of assertions to verify the correctness of the boolean logic:
The following code snippet demonstrates how to use boolean types in Cairo.
It shows the declaration of boolean variables, assignment of boolean expressions, and usage of assertions to verify the correctness of the boolean logic:

```rust
fn main() {
Expand Down
22 changes: 16 additions & 6 deletions concepts/control-flow/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ These constructs are fundamental for implementing logic and iteration in Cairo.

## `if` Expressions

`if` expressions in Cairo allow you to control the flow of execution based on conditional logic. They follow a structure where code is executed depending on whether a boolean condition evaluates to `true` or `false`.
`if` expressions in Cairo allow you to control the flow of execution based on conditional logic.
They follow a structure where code is executed depending on whether a boolean condition evaluates to `true` or `false`.

```rust
fn main() {
Expand All @@ -22,7 +23,9 @@ fn main() {
}
```

This example demonstrates a simple `if` block in Cairo. The message `"It's hot outside!"` is printed only if the condition `temperature > 25` evaluates to `true`. If the condition is `false`, no code is executed, and the program continues.
This example demonstrates a simple `if` block in Cairo.
The message `"It's hot outside!"` is printed only if the condition `temperature > 25` evaluates to `true`.
If the condition is `false`, no code is executed, and the program continues.

```rust
fn main() {
Expand Down Expand Up @@ -81,10 +84,13 @@ fn main() {

## Loops

Loops are a fundamental construct that allow the repetition of code blocks, enabling efficient and controlled execution of tasks. Loops can iterate over a sequence or execute code repeatedly based on a condition. Cairo provides three primary loop flavors:
Loops are a fundamental construct that allow the repetition of code blocks, enabling efficient and controlled execution of tasks.
Loops can iterate over a sequence or execute code repeatedly based on a condition.
Cairo provides three primary loop flavors:

- **loop**: A basic loop that runs indefinitely unless explicitly stopped using a `break` statement.
- **while**: Continues to execute as long as a specified condition remains `true`. It stops when the condition becomes `false`.
- **while**: Continues to execute as long as a specified condition remains `true`.
It stops when the condition becomes `false`.
- **for**: Iterates over elements in a collection, such as arrays, executing code for each element.

### Repeating Code with `loop`
Expand All @@ -101,7 +107,10 @@ fn main() {

Executing this code will print `"again!"` indefinitely in the console until either the program runs out of gas or we stop it manually.

> Note: Cairo prevents us from running a program with infinite loops by including a gas meter. The gas meter is a mechanism that limits the amount of computation that can be done in a program. Gas is a unit of measurement that expresses the computation cost of an instruction. When the gas meter runs out, the program will stop.
> Note: Cairo prevents us from running a program with infinite loops by including a gas meter.
> The gas meter is a mechanism that limits the amount of computation that can be done in a program.
> Gas is a unit of measurement that expresses the computation cost of an instruction.
> When the gas meter runs out, the program will stop.
To break out of a loop, place the `break` keyword within the loop to tell the program when to stop executing the it.

Expand Down Expand Up @@ -141,7 +150,8 @@ Executing this program will not print the value of `i` when it is equal to `5`.

#### Returning Values from `loop`

You can return a value from a `loop` by using the `break` keyword followed by the value you want to return. This allows you to exit the `loop` and pass a result to the rest of your code.
You can return a value from a `loop` by using the `break` keyword followed by the value you want to return.
This allows you to exit the `loop` and pass a result to the rest of your code.

```rust
fn main() {
Expand Down
4 changes: 3 additions & 1 deletion concepts/control-flow/introduction.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Introduction

Control flow in Cairo, through constructs like `if` expressions and loops, allows developers to direct the execution of their programs based on conditional logic or repetitive tasks. `if` expressions enable branching based on whether conditions evaluate to `true` or `false`, while loops (`loop`, `while`, `for`) facilitate repeated execution of code blocks until specific criteria are met. These constructs are crucial for implementing logic, iteration, and handling multiple conditions concisely, making them essential tools for writing efficient and dynamic code in Cairo.
Control flow in Cairo, through constructs like `if` expressions and loops, allows developers to direct the execution of their programs based on conditional logic or repetitive tasks.
`if` expressions enable branching based on whether conditions evaluate to `true` or `false`, while loops (`loop`, `while`, `for`) facilitate repeated execution of code blocks until specific criteria are met.
These constructs are crucial for implementing logic, iteration, and handling multiple conditions concisely, making them essential tools for writing efficient and dynamic code in Cairo.
2 changes: 1 addition & 1 deletion concepts/dictionaries/.meta/config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"blurb": "<todo>",
"authors": [
"0xNeshi"
"<your_gh_username>"
],
"contributors": []
}
Loading

0 comments on commit 925e6af

Please sign in to comment.