Skip to content

Commit

Permalink
fix(lint): Move ignore files out from the code (#2756)
Browse files Browse the repository at this point in the history
## What ❔

<!-- What are the changes this PR brings about? -->
<!-- Example: This PR adds a PR template to the repo. -->
<!-- (For bigger PRs adding more context is appreciated) -->

## Why ❔

<!-- Why are these changes done? What goal do they contribute to? What
are the principles behind them? -->
<!-- Example: PR templates ensure PR reviewers, observers, and future
iterators are in context about the evolution of repos. -->

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `zk fmt` and `zk lint`.

Signed-off-by: Danil <[email protected]>
  • Loading branch information
Deniallugo authored Aug 28, 2024
1 parent faefba2 commit bf03274
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 bf03274

Please sign in to comment.