Skip to content

Commit

Permalink
Merge branch 'main' into update-cairo-lang-dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
wawel37 authored Dec 17, 2024
2 parents e0706e5 + e049d15 commit e6d9bc3
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 45 deletions.
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[alias]
xtask = "run --quiet --package xtask --"
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ updates:
- package-ecosystem: "cargo"
directory: "/"
schedule:
interval: "weekly"
interval: "monthly"
groups:
cairo:
patterns:
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ CORELIB_PATH="/path/to/corelib/src" cargo test
To add a new test you can use the dev cli with:

```
cargo run --bin create_test <lint_name>
cargo xtask create-test --name "Your lint name" --group "Your lint group name"
```

### Manual instructions
Expand Down
12 changes: 8 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ resolver = "2"
members = [
"crates/cairo-lint-cli",
"crates/cairo-lint-core",
"crates/cairo-lint-dev",
"crates/cairo-lint-test-utils",
"xtask"
]

[workspace.package]
version = "0.1.0"
edition = "2021"
repository = "https://github.com/keep-starknet-strange/cairo-lint"
repository = "https://github.com/software-mansion/cairo-lint"
license-file = "LICENSE"

[workspace.dependencies]
Expand All @@ -30,7 +30,7 @@ ctor = "0.2.9"
paste = "1.0.15"
itertools = "0.13.0"
log = "0.4.22"
clap = "4.5.23"
clap = { version = "4.5.23", features = ["derive"]}
anyhow = "1.0.94"
smol_str = "0.2.2"
annotate-snippets = "0.11.5"
Expand Down
12 changes: 0 additions & 12 deletions crates/cairo-lint-dev/Cargo.toml

This file was deleted.

9 changes: 9 additions & 0 deletions xtask/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "xtask"
version = "1.0.0"
edition.workspace = true
publish = false

[dependencies]
anyhow.workspace = true
clap.workspace = true
36 changes: 12 additions & 24 deletions crates/cairo-lint-dev/src/main.rs → xtask/src/create_test.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
use clap::Parser;
use std::fs;
use std::io::{self, Write};
use std::path::{Path, PathBuf};

#[derive(Parser)]
pub struct Args {
#[arg(short, long)]
group: String,
#[arg(short, long)]
name: String,
}

fn create_new_test(lint_group: &str, lint_name: &str) -> io::Result<()> {
let test_content =
"//! > Test name\n\n//! > cairo_code\nfn main() {\n let a: Option<felt252> = \
Option::Some(1);\n}\n"
Option::Some(1);\n}\n"
.to_string();

let test_files_dir = PathBuf::from(format!(
Expand Down Expand Up @@ -41,29 +50,8 @@ fn create_new_test(lint_group: &str, lint_name: &str) -> io::Result<()> {
Ok(())
}

fn main() {
let lint_group = if let Some(arg1) = std::env::args().nth(1) {
arg1
} else {
println!("Enter the name of the lint group:");
let mut lint_group = String::new();
io::stdin()
.read_line(&mut lint_group)
.expect("Failed to read line");
lint_group.trim().to_string()
};
let lint_name = if let Some(arg1) = std::env::args().nth(2) {
arg1
} else {
println!("Enter the name of the lint group:");
let mut lint_name = String::new();
io::stdin()
.read_line(&mut lint_name)
.expect("Failed to read line");
lint_name.trim().to_string()
};

if let Err(e) = create_new_test(&lint_group, &lint_name) {
pub fn main(args: Args) {
if let Err(e) = create_new_test(&args.group, &args.name) {
eprintln!("Error creating test file: {}", e);
}
}
33 changes: 33 additions & 0 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use clap::Parser;

macro_rules! command {
($enum_name:ident ( $($module:ident,)+ )) => {
$(mod $module;)+

#[derive(::clap::Subcommand)]
#[allow(non_camel_case_types)]
enum $enum_name {
$($module(crate::$module::Args),)+
}

impl $enum_name {
fn main(self) {
match self {
$(Self::$module(args) => crate::$module::main(args),)+
}
}
}
}
}

command!(Command(create_test,));

#[derive(Parser)]
struct Args {
#[command(subcommand)]
command: Command,
}

fn main() {
Args::parse().command.main();
}

0 comments on commit e6d9bc3

Please sign in to comment.