Skip to content

Commit

Permalink
Move ignore files out from the code
Browse files Browse the repository at this point in the history
Signed-off-by: Danil <deniallugo@gmail.com>
  • Loading branch information
Deniallugo committed Aug 28, 2024
1 parent f37b84a commit 0d42e6f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 30 deletions.
26 changes: 26 additions & 0 deletions etc/lint-config/ignore.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
files: [
"KeysWithPlonkVerifier.sol",
"TokenInit.sol",
".tslintrc.js",
".prettierrc.js"
]
dirs: [
"target",
"node_modules",
"volumes",
"build",
"dist",
".git",
"generated",
"grafonnet-lib",
"prettier-config",
"lint-config",
"cache",
"artifacts",
"typechain",
"binaryen",
"system-contracts",
"artifacts-zk",
"cache-zk",
"contracts/"
]
2 changes: 2 additions & 0 deletions zk_toolbox/Cargo.lock

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

2 changes: 2 additions & 0 deletions zk_toolbox/crates/zk_supervisor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ xshell.workspace = true
serde.workspace = true
clap-markdown.workspace = true
futures.workspace = true
types.workspace = true
serde_yaml.workspace = true
serde_json.workspace = true
1 change: 1 addition & 0 deletions zk_toolbox/crates/zk_supervisor/src/commands/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ async fn prettier(shell: Shell, target: Target, check: bool) -> anyhow::Result<(
let files = get_unignored_files(&shell, &target)?;

if files.is_empty() {
logger::info(format!("No files for {target} found"));
return Ok(());
}

Expand Down
41 changes: 11 additions & 30 deletions zk_toolbox/crates/zk_supervisor/src/commands/lint_utils.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,9 @@
use clap::ValueEnum;
use serde::{Deserialize, Serialize};
use strum::EnumIter;
use xshell::{cmd, Shell};

const IGNORED_DIRS: [&str; 18] = [
"target",
"node_modules",
"volumes",
"build",
"dist",
".git",
"generated",
"grafonnet-lib",
"prettier-config",
"lint-config",
"cache",
"artifacts",
"typechain",
"binaryen",
"system-contracts",
"artifacts-zk",
"cache-zk",
// Ignore directories with OZ and forge submodules.
"contracts/l1-contracts/lib",
];

const IGNORED_FILES: [&str; 4] = [
"KeysWithPlonkVerifier.sol",
"TokenInit.sol",
".tslintrc.js",
".prettierrc.js",
];
const IGNORE_FILE: &str = "etc/lint-config/ignore.yaml";

#[derive(Debug, ValueEnum, EnumIter, strum::Display, PartialEq, Eq, Clone, Copy)]
#[strum(serialize_all = "lowercase")]
Expand All @@ -42,14 +16,21 @@ pub enum Target {
Contracts,
}

#[derive(Deserialize, Serialize, Debug)]
struct IgnoredData {
files: Vec<String>,
dirs: Vec<String>,
}

pub fn get_unignored_files(shell: &Shell, target: &Target) -> anyhow::Result<Vec<String>> {
let mut files = Vec::new();
let ignored_files: IgnoredData = serde_yaml::from_str(&shell.read_file(IGNORE_FILE)?)?;
let output = cmd!(shell, "git ls-files --recurse-submodules").read()?;

for line in output.lines() {
let path = line.to_string();
if !IGNORED_DIRS.iter().any(|dir| path.contains(dir))
&& !IGNORED_FILES.contains(&path.as_str())
if !ignored_files.dirs.iter().any(|dir| path.contains(dir))
&& !ignored_files.files.contains(&path)
&& path.ends_with(&format!(".{}", target))
{
files.push(path);
Expand Down

0 comments on commit 0d42e6f

Please sign in to comment.