Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
eugene-babichenko committed Jun 13, 2024
0 parents commit 777050e
Show file tree
Hide file tree
Showing 34 changed files with 1,987 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM alpine:latest
RUN apk add git cargo go npm \
&& go install github.com/evilmartians/lefthook@latest \
&& npm install -g prettier
ENV PATH=${PATH}:/root/go/bin
10 changes: 10 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "fixit",
"build": { "dockerfile": "Dockerfile" },
"postAttachCommand": "lefthook install",
"customizations": {
"vscode": {
"extensions": ["rust-lang.rust-analyzer", "esbenp.prettier-vscode"]
}
}
}
44 changes: 44 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
on:
push:

name: Tests

jobs:
tests:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: rustfmt, clippy
override: true

- name: Install Prettier
run: npm install -g prettier

- name: Run cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --check

- name: Run Prettier
run: prettier --check "**/*.{md,json,prettierrc}"

- name: Run cargo clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings

- name: Run tests
uses: actions-rs/cargo@v1
env:
RUST_BACKTRACE: 1
with:
command: test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tabWidth": 2,
"printWidth": 80,
"proseWrap": "always"
}
69 changes: 69 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Contributing guidelines

## Setting up development environment

The quickest way to start contributing is to use GitHub Codespaces (see
README.md).

You can just use a devcontainer included with this project.

If you do not want to use the devcontainer, you will need the following
dependencies:

- The Rust toolchain.
- Prettier for markdown formatting.
- lefthook for git pre-commit hooks (optional but advised).

## Markdown formatting

All markdown files should be formatted with:

prettier --prose-wrap always

## Adding new rules

A rule is a function that attempts to fix a command. To add a rule named
`rule_name` you need to add a file named `src/rules/rule_name.rs`. This file
should contain a `pub` function named `rule_name` with the following signature:

```rust
/// # Arguments
///
/// - `cmd` - tokenized command, e.g. (["git", "commit", "-m", "initial commit"])
/// - `error` - the output of the command.
fn rule_name(cmd: &[String], error: &str) -> T
```

Where `T` is any type implementing `IntoIterator<Item = Vec<String>>`. Normally,
this would be `Option<Vec<String>>` or `Vec<Vec<String>>`. `Vec<String>`
contains a command, e.g. `["git", "commit", "--amend"]`.

Then the name should be added to `src/rules/mod.rs` as an argument to the
`define_rules` macro.

## Adding shell support

Shells support should be added to `src/cmd/init.rs`. The code here is pretty
self-explanatory.

A couple notes on variables that go into generating the fix function:

- `executable` - the name of `fixit` executable.
- `name` - the name of the generated function.

All shell support functions should generally follow this pseudocode:

```
function {name}
last_command = get_last_command()
fixed_command = {executable} fix $last_command
if $fixed_command != ""
run($fixed_command)
add_to_history($fixed_command)
end
end
```

## Adding support for terminal emulators/multiplexers

See `src/get_text`. There is no specific guideline for this.
Loading

0 comments on commit 777050e

Please sign in to comment.