From 3f722cb9043e6494d8f025df42cb0e57ca0ce8b0 Mon Sep 17 00:00:00 2001 From: 0xisk <0xisk@proton.me> Date: Tue, 15 Sep 2026 16:45:15 +0200 Subject: [PATCH] refactor(compact-lint): read the [lint] table of compact.toml One project, one config file. compact-deploy already owns `compact.toml`, so the linter moves its settings under a `[lint]` table there and `compact-lint.toml` goes away before anything ships. * The linter parses the whole document but deserialises only `lint`; every other table is another tool's and is ignored. A file with no `[lint]` table is a config error, no file at all keeps the built-in defaults. * The `version` key is dropped: tables are namespaced per tool and the deployer's file has none either. * A deployer test pins that its loader strips the `[lint]` table, so the two tools keep sharing the file without a schema change. --- crates/compact-lint/README.md | 53 +++++---- .../{compact-contracts.toml => compact.toml} | 32 +++--- crates/compact-lint/src/config.rs | 108 ++++++++++++------ crates/compact-lint/src/lib.rs | 4 +- crates/compact-lint/src/main.rs | 8 +- crates/compact-lint/tests/check.rs | 12 +- crates/compact-lint/tests/fill.rs | 4 +- crates/compact-lint/tests/fix.rs | 10 +- .../tests/fixtures/clean/compact.toml | 42 +++++++ .../compact.toml} | 18 +-- .../compact.toml} | 18 +-- .../compact.toml} | 18 +-- .../error-on-warnings/compact-lint.toml | 27 ----- .../compact.toml} | 18 +-- .../{compact-lint.toml => compact.toml} | 6 +- .../{compact-lint.toml => compact.toml} | 6 +- .../{compact-lint.toml => compact.toml} | 6 +- .../{compact-lint.toml => compact.toml} | 6 +- .../{compact-lint.toml => compact.toml} | 8 +- .../{compact-lint.toml => compact.toml} | 8 +- .../{compact-lint.toml => compact.toml} | 10 +- .../{compact-lint.toml => compact.toml} | 12 +- .../{compact-lint.toml => compact.toml} | 10 +- .../{compact-lint.toml => compact.toml} | 6 +- .../{compact-lint.toml => compact.toml} | 10 +- .../{compact-lint.toml => compact.toml} | 20 ++-- .../{compact-lint.toml => compact.toml} | 10 +- .../fixtures/forbidden-tag/compact-lint.toml | 27 ----- .../tests/fixtures/forbidden-tag/compact.toml | 27 +++++ .../max-diagnostics/compact-lint.toml | 27 ----- .../fixtures/max-diagnostics/compact.toml | 27 +++++ .../missing-constraints/compact-lint.toml | 27 ----- .../fixtures/missing-constraints/compact.toml | 27 +++++ .../fixtures/missing-doc/compact-lint.toml | 27 ----- .../tests/fixtures/missing-doc/compact.toml | 27 +++++ .../fixtures/missing-tag/compact-lint.toml | 27 ----- .../tests/fixtures/missing-tag/compact.toml | 27 +++++ .../fixtures/module-name/compact-lint.toml | 27 ----- .../tests/fixtures/module-name/compact.toml | 27 +++++ .../tests/fixtures/no-lint-table/compact.toml | 14 +++ .../parse/{compact-lint.toml => compact.toml} | 2 +- .../reporter-concise/compact-lint.toml | 27 ----- .../fixtures/reporter-concise/compact.toml | 27 +++++ .../reporter-github/compact-lint.toml | 27 ----- .../fixtures/reporter-github/compact.toml | 27 +++++ .../{compact-lint.toml => compact.toml} | 20 ++-- examples/fungible-token/compact.toml | 2 + .../src/config/compact-config.test.ts | 18 +++ packages/linter/README.md | 5 +- 49 files changed, 549 insertions(+), 434 deletions(-) rename crates/compact-lint/examples/{compact-contracts.toml => compact.toml} (70%) create mode 100644 crates/compact-lint/tests/fixtures/clean/compact.toml rename crates/compact-lint/tests/fixtures/{diagnostic-level/compact-lint.toml => constraints-format/compact.toml} (59%) rename crates/compact-lint/tests/fixtures/{clean/compact-lint.toml => constraints-placeholder/compact.toml} (59%) rename crates/compact-lint/tests/fixtures/{constraints-format/compact-lint.toml => diagnostic-level/compact.toml} (59%) delete mode 100644 crates/compact-lint/tests/fixtures/error-on-warnings/compact-lint.toml rename crates/compact-lint/tests/fixtures/{constraints-placeholder/compact-lint.toml => error-on-warnings/compact.toml} (59%) rename crates/compact-lint/tests/fixtures/fill-basic/{compact-lint.toml => compact.toml} (65%) rename crates/compact-lint/tests/fixtures/fill-compiler-fails/{compact-lint.toml => compact.toml} (65%) rename crates/compact-lint/tests/fixtures/fill-missing-source/{compact-lint.toml => compact.toml} (55%) rename crates/compact-lint/tests/fixtures/fill-no-compile/{compact-lint.toml => compact.toml} (65%) rename crates/compact-lint/tests/fixtures/fill-override/{compact-lint.toml => compact.toml} (68%) rename crates/compact-lint/tests/fixtures/fill-self/{compact-lint.toml => compact.toml} (56%) rename crates/compact-lint/tests/fixtures/fix-constraints/{compact-lint.toml => compact.toml} (52%) rename crates/compact-lint/tests/fixtures/fix-crlf/{compact-lint.toml => compact.toml} (63%) rename crates/compact-lint/tests/fixtures/fix-missing-tag/{compact-lint.toml => compact.toml} (57%) rename crates/compact-lint/tests/fixtures/fix-module-name/{compact-lint.toml => compact.toml} (60%) rename crates/compact-lint/tests/fixtures/fix-rename/{compact-lint.toml => compact.toml} (65%) rename crates/compact-lint/tests/fixtures/fix-skeleton/{compact-lint.toml => compact.toml} (62%) rename crates/compact-lint/tests/fixtures/fix-unfixable/{compact-lint.toml => compact.toml} (70%) delete mode 100644 crates/compact-lint/tests/fixtures/forbidden-tag/compact-lint.toml create mode 100644 crates/compact-lint/tests/fixtures/forbidden-tag/compact.toml delete mode 100644 crates/compact-lint/tests/fixtures/max-diagnostics/compact-lint.toml create mode 100644 crates/compact-lint/tests/fixtures/max-diagnostics/compact.toml delete mode 100644 crates/compact-lint/tests/fixtures/missing-constraints/compact-lint.toml create mode 100644 crates/compact-lint/tests/fixtures/missing-constraints/compact.toml delete mode 100644 crates/compact-lint/tests/fixtures/missing-doc/compact-lint.toml create mode 100644 crates/compact-lint/tests/fixtures/missing-doc/compact.toml delete mode 100644 crates/compact-lint/tests/fixtures/missing-tag/compact-lint.toml create mode 100644 crates/compact-lint/tests/fixtures/missing-tag/compact.toml delete mode 100644 crates/compact-lint/tests/fixtures/module-name/compact-lint.toml create mode 100644 crates/compact-lint/tests/fixtures/module-name/compact.toml create mode 100644 crates/compact-lint/tests/fixtures/no-lint-table/compact.toml rename crates/compact-lint/tests/fixtures/parse/{compact-lint.toml => compact.toml} (69%) delete mode 100644 crates/compact-lint/tests/fixtures/reporter-concise/compact-lint.toml create mode 100644 crates/compact-lint/tests/fixtures/reporter-concise/compact.toml delete mode 100644 crates/compact-lint/tests/fixtures/reporter-github/compact-lint.toml create mode 100644 crates/compact-lint/tests/fixtures/reporter-github/compact.toml rename crates/compact-lint/tests/fixtures/rules-levels/{compact-lint.toml => compact.toml} (64%) diff --git a/crates/compact-lint/README.md b/crates/compact-lint/README.md index b562ca5..813808c 100644 --- a/crates/compact-lint/README.md +++ b/crates/compact-lint/README.md @@ -2,7 +2,7 @@ Doc-comment linter for Compact sources. It parses `.compact` files with [`compact-tree-sitter`](../compact-tree-sitter), matches every declaration against the -per-kind template in `compact-lint.toml`, and prints one diagnostic per violation. `fix` +per-kind template in `compact.toml`, and prints one diagnostic per violation. `fix` rewrites the comments the repairable rules report. `fill-constraints` compiles the contracts and writes the measured `k` and `rows` into the annotations. @@ -25,11 +25,11 @@ compact-lint fill-constraints [PATHS]... [--config ] [--dry-run] [--no-com walking: `node_modules`, `target`, `dist`, `build`, `.git`. - No `PATHS` — the config's `include` globs are used instead. - `--config ` — use this config instead of searching upward for - `compact-lint.toml`. + `compact.toml`. - `--strict` — report `k=?` / `rows=?` placeholders as errors instead of warnings. Use it on release branches. - `--no-format` — skip the `compact format --check` pass. Required where the `compact` - binary is unavailable, CI included. Same effect as `format = "off"` in `[rules]`. + binary is unavailable, CI included. Same effect as `format = "off"` in `[lint.rules]`. - `--compact-bin ` — path to the `compact` binary. Also settable with `COMPACT_LINT_COMPACT_BIN`; the flag wins. @@ -89,10 +89,10 @@ Found 3 errors. - Every rule reports at a level: `error`, `warn`, `info`, or `off`. - `off` stops the rule running; its findings never reach the report or the counts. -- Set them in `[rules]`, keyed by rule id: +- Set them in `[lint.rules]`, keyed by rule id: ```toml -[rules] +[lint.rules] missing-doc = "error" constraints-placeholder = "warn" format = "off" @@ -110,7 +110,7 @@ Defaults: - `--strict` promotes `constraints-placeholder` to `error` for that run; a rule set to `off` stays off. -- An unknown key in `[rules]` is a config error. +- An unknown key in `[lint.rules]` is a config error. ## Exit codes @@ -300,36 +300,45 @@ Rule detail: ## Config -`compact-lint.toml`, searched for upward from the current directory. Every field is -optional; unknown fields are rejected. A config found by walking upward anchors the -`include` globs at its own directory; a config named with `--config` is a shareable -preset, so the globs stay anchored at the current directory. +`compact.toml`, searched for upward from the current directory. The linter reads its +`[lint]` table; every key below is a key of that table. + +- The file is shared with [`compact-deploy`](../../packages/deployer), which owns + `[profile]`, `[networks.*]`, `[wallet]` and `[contracts.*]` in the same file. +- Tables the linter does not own are ignored, so a deployer-only key is never a lint + error. +- Every field under `[lint]` is optional; an unknown one is rejected. +- A `compact.toml` with no `[lint]` table is a config error, exit `2`. No `compact.toml` + anywhere up the tree is not: the run uses the built-in defaults. +- A config found by walking upward anchors the `include` globs at its own directory; a + config named with `--config` is a shareable preset, so the globs stay anchored at the + current directory. ```toml -version = 1 +[lint] include = ["contracts/src/**/*.compact"] exclude = ["**/test/mocks/**", "**/archive/**"] -[constraints] +[lint.constraints] tag = "@constraints" compiler = "0.34.0" sources = ["{dir}/test/mocks/Mock{stem}.compact", "{parent}/test/mocks/Mock{stem}.compact"] self = ["**/presets/**"] -[constraints.overrides] +[lint.constraints.overrides] "contracts/src/utils/Utils.compact" = "contracts/src/utils/test/mocks/MockUtils.compact" -[tags] +[lint.tags] forbid = ["@return"] rename = { "@return" = "@returns" } -[fix] +[lint.fix] placeholder = "TODO" -[rules] +[lint.rules] constraints-placeholder = "warn" -[kinds.module] +[lint.kinds.module] docs = "exported" tags = ["@module", "@description"] ``` @@ -338,7 +347,6 @@ Defaults when no config file is found: | Key | Default | | --- | --- | -| `version` | `1`, the only version this build accepts | | `include` | `["**/*.compact"]` | | `exclude` | `[]` | | `constraints.tag` | `"@constraints"` | @@ -372,7 +380,7 @@ Defaults when no config file is found: - `constraints.overrides` keys and values are paths relative to the config's directory, or to the current directory when the config came from `--config`. -`examples/compact-contracts.toml` is the config for OpenZeppelin/compact-contracts. +`examples/compact.toml` is the config for OpenZeppelin/compact-contracts. ## Doc-comment model @@ -390,11 +398,12 @@ cargo test --workspace ``` `tests/fixtures//` holds one `check` case per rule plus a clean case: a -`compact-lint.toml`, the `.compact` sources, and `expected.txt`, the exact stdout with +`compact.toml`, the `.compact` sources, and `expected.txt`, the exact stdout with paths relative to the case directory. A case that also runs under a flag carries the -second expectation beside it, such as `expected-strict.txt`. +second expectation beside it, such as `expected-strict.txt`. The `clean` case carries +the deployer's tables too, and `no-lint-table` carries nothing else. -`tests/fixtures/fix-/` holds one `fix` case per rule: a `compact-lint.toml`, +`tests/fixtures/fix-/` holds one `fix` case per rule: a `compact.toml`, `before/`, `after/`, `expected.txt` for the write run and `expected-dry-run.txt` for the preview. The run copies `before/` into a temporary directory, so the fixtures are never rewritten in place. diff --git a/crates/compact-lint/examples/compact-contracts.toml b/crates/compact-lint/examples/compact.toml similarity index 70% rename from crates/compact-lint/examples/compact-contracts.toml rename to crates/compact-lint/examples/compact.toml index 6667f2a..9cf5ef5 100644 --- a/crates/compact-lint/examples/compact-contracts.toml +++ b/crates/compact-lint/examples/compact.toml @@ -1,25 +1,29 @@ # compact-lint config for OpenZeppelin/compact-contracts. -# Copy it to the repository root as compact-lint.toml. +# Copy it to the repository root as compact.toml. +# +# One project, one config file. compact-deploy's `[profile]`, `[networks.*]`, +# `[wallet]` and `[contracts.*]` tables live in this same file and the linter +# ignores them; see examples/fungible-token/compact.toml for their shape. -version = 1 +[lint] include = ["contracts/src/**/*.compact"] exclude = ["**/test/mocks/**", "**/archive/**"] # `@constraints` is the default; set `tag` to point the rule at another annotation. -[constraints] +[lint.constraints] tag = "@constraints" # Presets are contracts, so fill-constraints compiles them directly. Everything else is # measured through the mock beside it or in its parent, the default `sources` templates. self = ["**/presets/**"] -[tags] +[lint.tags] forbid = ["@return"] rename = { "@return" = "@returns" } # Every rule's default level, spelled out. Set one to "off" to stop it running, or to # "warn" / "info" to keep it out of the exit code. `check --strict` promotes # constraints-placeholder to "error" for that run. -# [rules] +# [lint.rules] # missing-doc = "error" # missing-tag = "error" # forbidden-tag = "error" @@ -32,29 +36,29 @@ rename = { "@return" = "@returns" } # parse = "error" # format = "error" -[kinds.module] +[lint.kinds.module] docs = "exported" tags = ["@module", "@description"] -[kinds.circuit] +[lint.kinds.circuit] tags = ["@description"] -[kinds.ledger] +[lint.kinds.ledger] tags = ["@description"] -[kinds.witness] +[lint.kinds.witness] docs = "all" tags = ["@description"] -[kinds.struct] +[lint.kinds.struct] tags = ["@description"] -[kinds.enum] +[lint.kinds.enum] tags = ["@description"] -[kinds.constructor] +[lint.kinds.constructor] docs = "none" -[kinds.contract] +[lint.kinds.contract] -[kinds.type] +[lint.kinds.type] diff --git a/crates/compact-lint/src/config.rs b/crates/compact-lint/src/config.rs index 46d6931..88dc643 100644 --- a/crates/compact-lint/src/config.rs +++ b/crates/compact-lint/src/config.rs @@ -1,4 +1,7 @@ -//! `compact-lint.toml`: discovery, parsing, and the built-in defaults. +//! `compact.toml`: discovery, parsing, and the built-in defaults. +//! +//! The file is shared with `compact-deploy`. The linter reads its `[lint]` table and +//! ignores every other one. use std::collections::BTreeMap; use std::path::{Path, PathBuf}; @@ -13,10 +16,7 @@ use crate::model::DeclKind; use crate::report::RuleId; /// The config file name searched for upward from the current directory. -pub const CONFIG_FILE_NAME: &str = "compact-lint.toml"; - -/// The only schema version this build understands. -pub const SUPPORTED_VERSION: u32 = 1; +pub const CONFIG_FILE_NAME: &str = "compact.toml"; #[derive(Debug, Error)] pub enum ConfigError { @@ -32,10 +32,8 @@ pub enum ConfigError { #[source] source: toml::de::Error, }, - #[error( - "config {path} is version {found}, but this build understands version {SUPPORTED_VERSION}" - )] - Version { path: PathBuf, found: u32 }, + #[error("{CONFIG_FILE_NAME} at {path} has no [lint] table")] + MissingLintTable { path: PathBuf }, #[error( "config {path} lists tag {tag:?}; tags are spelled with their `@`, like `@description`" )] @@ -236,11 +234,17 @@ impl Default for FixConfig { } } -/// A parsed `compact-lint.toml`, or the built-in defaults when no file was found. +/// The whole `compact.toml`. Tables other tools own are ignored, so the root rejects +/// nothing. +#[derive(Debug, Default, Deserialize)] +struct Document { + lint: Option, +} + +/// A parsed `[lint]` table, or the built-in defaults when no file was found. #[derive(Clone, Debug, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields, default)] pub struct Config { - pub version: u32, pub include: Vec, pub exclude: Vec, pub constraints: ConstraintsConfig, @@ -253,7 +257,6 @@ pub struct Config { impl Default for Config { fn default() -> Self { Self { - version: SUPPORTED_VERSION, include: vec!["**/*.compact".to_owned()], exclude: Vec::new(), constraints: ConstraintsConfig::default(), @@ -266,26 +269,24 @@ impl Default for Config { } impl Config { - /// Parses a config file and rejects a version this build does not implement. + /// Parses a config file's `[lint]` table. /// # Errors - /// Returns an error when the file is unreadable, malformed, or a future version. + /// Returns an error when the file is unreadable or malformed, or carries no `[lint]` + /// table. pub fn load(path: &Path) -> Result { let text = std::fs::read_to_string(path).map_err(|source| ConfigError::Read { path: path.to_owned(), source, })?; - let config: Self = toml::from_str(&text).map_err(|source| ConfigError::Parse { + let document: Document = toml::from_str(&text).map_err(|source| ConfigError::Parse { path: path.to_owned(), source, })?; - if config.version != SUPPORTED_VERSION { - return Err(ConfigError::Version { - path: path.to_owned(), - found: config.version, - }); - } + let config = document.lint.ok_or_else(|| ConfigError::MissingLintTable { + path: path.to_owned(), + })?; if let Some(tag) = config.tags().find(|tag| !tag.is_well_formed()) { return Err(ConfigError::Tag { @@ -365,7 +366,7 @@ fn glob_set(patterns: &[String], path: &Path) -> Result { }) } -/// Walks up from `start` looking for `compact-lint.toml`. +/// Walks up from `start` looking for `compact.toml`. #[must_use] pub fn discover(start: &Path) -> Option { for directory in start.ancestors() { @@ -379,7 +380,7 @@ pub fn discover(start: &Path) -> Option { #[cfg(test)] mod tests { - use super::{Config, DocsPolicy, SUPPORTED_VERSION}; + use super::{Config, DocsPolicy}; use crate::diagnostic::Level; use crate::doc::Tag; use crate::model::DeclKind; @@ -419,7 +420,6 @@ mod tests { fn defaults_require_docs_on_exported_declarations_only() { let config = Config::default(); - assert_eq!(config.version, SUPPORTED_VERSION); assert_eq!(config.constraints.tag, Tag::new("@constraints")); for kind in [DeclKind::Module, DeclKind::Circuit, DeclKind::Type] { assert_eq!(config.kinds.get(kind).docs, DocsPolicy::Exported); @@ -429,7 +429,7 @@ mod tests { #[test] fn omitted_tables_fall_back_to_defaults() { - let config: Config = toml::from_str("version = 1\n[kinds.witness]\ndocs = \"all\"\n") + let config: Config = toml::from_str("[kinds.witness]\ndocs = \"all\"\n") .expect("the snippet is valid config"); assert_eq!(config.kinds.witness.docs, DocsPolicy::All); @@ -439,17 +439,17 @@ mod tests { #[test] fn an_unknown_key_is_rejected() { - let error = toml::from_str::("verison = 1\n").expect_err("the key is misspelled"); + let error = toml::from_str::("inclued = []\n").expect_err("the key is misspelled"); - assert!(error.to_string().contains("verison"), "{error}"); + assert!(error.to_string().contains("inclued"), "{error}"); } #[test] fn a_tag_without_its_at_sign_is_rejected() { let dir = std::env::temp_dir().join(format!("compact-lint-config-{}", std::process::id())); std::fs::create_dir_all(&dir).expect("the temp dir is writable"); - let path = dir.join("compact-lint.toml"); - std::fs::write(&path, "[kinds.circuit]\ntags = [\"description\"]\n") + let path = dir.join("compact.toml"); + std::fs::write(&path, "[lint.kinds.circuit]\ntags = [\"description\"]\n") .expect("the config is writable"); let error = Config::load(&path).expect_err("the tag lacks its @"); @@ -476,9 +476,12 @@ mod tests { fn a_rename_target_without_its_at_sign_is_rejected() { let dir = std::env::temp_dir().join(format!("compact-lint-rename-{}", std::process::id())); std::fs::create_dir_all(&dir).expect("the temp dir is writable"); - let path = dir.join("compact-lint.toml"); - std::fs::write(&path, "[tags]\nrename = { \"@return\" = \"returns\" }\n") - .expect("the config is writable"); + let path = dir.join("compact.toml"); + std::fs::write( + &path, + "[lint.tags]\nrename = { \"@return\" = \"returns\" }\n", + ) + .expect("the config is writable"); let error = Config::load(&path).expect_err("the replacement lacks its @"); @@ -540,4 +543,45 @@ mod tests { assert!(error.to_string().contains("circiut"), "{error}"); } + + /// Writes `text` to a `compact.toml` of its own and returns what `load` made of it. + fn load_document(name: &str, text: &str) -> Result { + let dir = std::env::temp_dir().join(format!("compact-lint-{name}-{}", std::process::id())); + std::fs::create_dir_all(&dir).expect("the temp dir is writable"); + let path = dir.join("compact.toml"); + std::fs::write(&path, text).expect("the config is writable"); + + let loaded = Config::load(&path); + + std::fs::remove_dir_all(&dir).expect("the temp dir is removable"); + loaded + } + + #[test] + fn tables_another_tool_owns_are_ignored() { + let config = load_document( + "foreign", + "[profile]\ndefault_network = \"local\"\n\n[lint]\ninclude = [\"src/**/*.compact\"]\n", + ) + .expect("the deployer's tables are not the linter's business"); + + assert_eq!(config.include, ["src/**/*.compact"]); + } + + #[test] + fn a_file_without_a_lint_table_is_an_error() { + let error = load_document("no-lint", "[profile]\ndefault_network = \"local\"\n") + .expect_err("the file carries no [lint] table"); + + assert!(error.to_string().contains("has no [lint] table"), "{error}"); + } + + #[test] + fn a_typo_under_the_lint_table_is_still_rejected() { + let error = load_document("lint-typo", "[lint]\ninclued = []\n") + .expect_err("the key is misspelled"); + let source = std::error::Error::source(&error).expect("the parser named the key"); + + assert!(source.to_string().contains("inclued"), "{source}"); + } } diff --git a/crates/compact-lint/src/lib.rs b/crates/compact-lint/src/lib.rs index 1dd7e4b..c7302b0 100644 --- a/crates/compact-lint/src/lib.rs +++ b/crates/compact-lint/src/lib.rs @@ -1,8 +1,8 @@ //! Doc-comment linter for Compact sources. //! //! The crate parses `.compact` files with the bundled tree-sitter grammar, matches each -//! declaration against the per-kind doc-comment template in `compact-lint.toml`, and -//! yields one [`rules::Issue`] per violation. `check` renders an issue as a +//! declaration against the per-kind doc-comment template in `compact.toml`'s `[lint]` +//! table, and yields one [`rules::Issue`] per violation. `check` renders an issue as a //! [`diagnostic::Diagnostic`]; `fix` renders the repairable ones as an [`edit::Edit`]. //! `fill-constraints` takes the other path: [`measure`] compiles a contract and //! [`fill`] writes the measured values into the annotations that already exist. diff --git a/crates/compact-lint/src/main.rs b/crates/compact-lint/src/main.rs index 0d8ddba..c3f4949 100644 --- a/crates/compact-lint/src/main.rs +++ b/crates/compact-lint/src/main.rs @@ -40,7 +40,7 @@ struct Cli { #[derive(Debug, Subcommand)] enum Command { - /// Check doc comments against the per-kind templates in compact-lint.toml. + /// Check doc comments against the per-kind templates in compact.toml's [lint] table. Check(CheckArgs), /// Rewrite doc comments so the rules `fix` covers stop reporting. Fix(FixArgs), @@ -127,7 +127,7 @@ struct CheckArgs { /// Files or directories to check; defaults to the config's include globs. paths: Vec, - /// Config file to use instead of searching upward for compact-lint.toml. + /// Config file to use instead of searching upward for compact.toml. #[arg(long, value_name = "FILE")] config: Option, @@ -152,7 +152,7 @@ struct FixArgs { /// Files or directories to fix; defaults to the config's include globs. paths: Vec, - /// Config file to use instead of searching upward for compact-lint.toml. + /// Config file to use instead of searching upward for compact.toml. #[arg(long, value_name = "FILE")] config: Option, @@ -169,7 +169,7 @@ struct FillArgs { /// Files or directories to fill; defaults to the config's include globs. paths: Vec, - /// Config file to use instead of searching upward for compact-lint.toml. + /// Config file to use instead of searching upward for compact.toml. #[arg(long, value_name = "FILE")] config: Option, diff --git a/crates/compact-lint/tests/check.rs b/crates/compact-lint/tests/check.rs index ff96c60..230d656 100644 --- a/crates/compact-lint/tests/check.rs +++ b/crates/compact-lint/tests/check.rs @@ -228,7 +228,7 @@ fn an_explicit_path_replaces_the_include_globs() { #[test] fn an_explicit_config_anchors_discovery_at_the_working_directory() { - let config = case("clean").join("compact-lint.toml"); + let config = case("clean").join("compact.toml"); let output = binary() .current_dir(case("missing-doc")) .args(["check", "--no-format", "--colors=off", "--config"]) @@ -255,11 +255,19 @@ fn a_missing_compact_binary_exits_two_and_names_the_escape_hatch() { assert!(stderr.contains("--no-format"), "{stderr}"); } +#[test] +fn a_config_holding_only_another_tool_tables_exits_two() { + let (code, _, stderr) = run("no-lint-table", &[]); + + assert_eq!(code, EXIT_ERROR, "{stderr}"); + assert!(stderr.contains("has no [lint] table"), "{stderr}"); +} + #[test] fn an_unreadable_config_exits_two() { let output = binary() .current_dir(case("clean")) - .args(["check", "--no-format", "--config", "compact-lint.toml.nope"]) + .args(["check", "--no-format", "--config", "compact.toml.nope"]) .output() .expect("the binary ran"); diff --git a/crates/compact-lint/tests/fill.rs b/crates/compact-lint/tests/fill.rs index bbf3e24..a36dbd7 100644 --- a/crates/compact-lint/tests/fill.rs +++ b/crates/compact-lint/tests/fill.rs @@ -45,8 +45,8 @@ fn work(name: &str) -> TempDir { let root = case(name); std::fs::copy( - root.join("compact-lint.toml"), - directory.path().join("compact-lint.toml"), + root.join("compact.toml"), + directory.path().join("compact.toml"), ) .expect("the case has a config"); copy_tree(&root.join("before"), directory.path()); diff --git a/crates/compact-lint/tests/fix.rs b/crates/compact-lint/tests/fix.rs index 2d4e718..96c7693 100644 --- a/crates/compact-lint/tests/fix.rs +++ b/crates/compact-lint/tests/fix.rs @@ -1,6 +1,6 @@ //! `compact-lint fix` end to end, one fixture case per rule. //! -//! A case holds `compact-lint.toml`, `before/`, `after/`, `expected.txt` for the write +//! A case holds `compact.toml`, `before/`, `after/`, `expected.txt` for the write //! run and `expected-dry-run.txt` for the preview. The run works on a copy of `before/`, //! so the fixtures themselves are never rewritten. @@ -32,8 +32,8 @@ fn work(name: &str) -> TempDir { let root = case(name); std::fs::copy( - root.join("compact-lint.toml"), - directory.path().join("compact-lint.toml"), + root.join("compact.toml"), + directory.path().join("compact.toml"), ) .expect("the case has a config"); copy_tree(&root.join("before"), directory.path()); @@ -225,10 +225,10 @@ fn a_concise_run_prints_one_line_per_edit() { #[test] fn an_explicit_config_replaces_the_one_beside_the_sources() { let directory = work("rename"); - std::fs::remove_file(directory.path().join("compact-lint.toml")) + std::fs::remove_file(directory.path().join("compact.toml")) .expect("the copied config is removable"); - let config = case("rename").join("compact-lint.toml"); + let config = case("rename").join("compact.toml"); let output = binary() .current_dir(directory.path()) .args(["fix", "--colors=off", "--config"]) diff --git a/crates/compact-lint/tests/fixtures/clean/compact.toml b/crates/compact-lint/tests/fixtures/clean/compact.toml new file mode 100644 index 0000000..b55b8bc --- /dev/null +++ b/crates/compact-lint/tests/fixtures/clean/compact.toml @@ -0,0 +1,42 @@ +# compact-deploy's tables, here so the case proves the linter ignores them. +[profile] +default_network = "local" + +[networks.local] +network_id = "undeployed" +indexer = "http://127.0.0.1:8088/api/v4/graphql" +indexer_ws = "ws://127.0.0.1:8088/api/v4/graphql/ws" +node = "http://127.0.0.1:9944" +node_ws = "ws://127.0.0.1:9944" + +[contracts.Clean] +artifact = "Clean" +signing_key_file = "deploy/Clean.signingkey" + +[lint] +include = ["**/*.compact"] + +[lint.tags] +forbid = ["@return"] + +[lint.kinds.module] +tags = ["@module", "@description"] + +[lint.kinds.circuit] +tags = ["@description"] + +[lint.kinds.ledger] +tags = ["@description"] + +[lint.kinds.witness] +docs = "all" +tags = ["@description"] + +[lint.kinds.struct] +tags = ["@description"] + +[lint.kinds.enum] +tags = ["@description"] + +[lint.kinds.constructor] +docs = "none" diff --git a/crates/compact-lint/tests/fixtures/diagnostic-level/compact-lint.toml b/crates/compact-lint/tests/fixtures/constraints-format/compact.toml similarity index 59% rename from crates/compact-lint/tests/fixtures/diagnostic-level/compact-lint.toml rename to crates/compact-lint/tests/fixtures/constraints-format/compact.toml index 0813e24..01fa5a7 100644 --- a/crates/compact-lint/tests/fixtures/diagnostic-level/compact-lint.toml +++ b/crates/compact-lint/tests/fixtures/constraints-format/compact.toml @@ -1,27 +1,27 @@ -version = 1 +[lint] include = ["**/*.compact"] -[tags] +[lint.tags] forbid = ["@return"] -[kinds.module] +[lint.kinds.module] tags = ["@module", "@description"] -[kinds.circuit] +[lint.kinds.circuit] tags = ["@description"] -[kinds.ledger] +[lint.kinds.ledger] tags = ["@description"] -[kinds.witness] +[lint.kinds.witness] docs = "all" tags = ["@description"] -[kinds.struct] +[lint.kinds.struct] tags = ["@description"] -[kinds.enum] +[lint.kinds.enum] tags = ["@description"] -[kinds.constructor] +[lint.kinds.constructor] docs = "none" diff --git a/crates/compact-lint/tests/fixtures/clean/compact-lint.toml b/crates/compact-lint/tests/fixtures/constraints-placeholder/compact.toml similarity index 59% rename from crates/compact-lint/tests/fixtures/clean/compact-lint.toml rename to crates/compact-lint/tests/fixtures/constraints-placeholder/compact.toml index 0813e24..01fa5a7 100644 --- a/crates/compact-lint/tests/fixtures/clean/compact-lint.toml +++ b/crates/compact-lint/tests/fixtures/constraints-placeholder/compact.toml @@ -1,27 +1,27 @@ -version = 1 +[lint] include = ["**/*.compact"] -[tags] +[lint.tags] forbid = ["@return"] -[kinds.module] +[lint.kinds.module] tags = ["@module", "@description"] -[kinds.circuit] +[lint.kinds.circuit] tags = ["@description"] -[kinds.ledger] +[lint.kinds.ledger] tags = ["@description"] -[kinds.witness] +[lint.kinds.witness] docs = "all" tags = ["@description"] -[kinds.struct] +[lint.kinds.struct] tags = ["@description"] -[kinds.enum] +[lint.kinds.enum] tags = ["@description"] -[kinds.constructor] +[lint.kinds.constructor] docs = "none" diff --git a/crates/compact-lint/tests/fixtures/constraints-format/compact-lint.toml b/crates/compact-lint/tests/fixtures/diagnostic-level/compact.toml similarity index 59% rename from crates/compact-lint/tests/fixtures/constraints-format/compact-lint.toml rename to crates/compact-lint/tests/fixtures/diagnostic-level/compact.toml index 0813e24..01fa5a7 100644 --- a/crates/compact-lint/tests/fixtures/constraints-format/compact-lint.toml +++ b/crates/compact-lint/tests/fixtures/diagnostic-level/compact.toml @@ -1,27 +1,27 @@ -version = 1 +[lint] include = ["**/*.compact"] -[tags] +[lint.tags] forbid = ["@return"] -[kinds.module] +[lint.kinds.module] tags = ["@module", "@description"] -[kinds.circuit] +[lint.kinds.circuit] tags = ["@description"] -[kinds.ledger] +[lint.kinds.ledger] tags = ["@description"] -[kinds.witness] +[lint.kinds.witness] docs = "all" tags = ["@description"] -[kinds.struct] +[lint.kinds.struct] tags = ["@description"] -[kinds.enum] +[lint.kinds.enum] tags = ["@description"] -[kinds.constructor] +[lint.kinds.constructor] docs = "none" diff --git a/crates/compact-lint/tests/fixtures/error-on-warnings/compact-lint.toml b/crates/compact-lint/tests/fixtures/error-on-warnings/compact-lint.toml deleted file mode 100644 index 0813e24..0000000 --- a/crates/compact-lint/tests/fixtures/error-on-warnings/compact-lint.toml +++ /dev/null @@ -1,27 +0,0 @@ -version = 1 -include = ["**/*.compact"] - -[tags] -forbid = ["@return"] - -[kinds.module] -tags = ["@module", "@description"] - -[kinds.circuit] -tags = ["@description"] - -[kinds.ledger] -tags = ["@description"] - -[kinds.witness] -docs = "all" -tags = ["@description"] - -[kinds.struct] -tags = ["@description"] - -[kinds.enum] -tags = ["@description"] - -[kinds.constructor] -docs = "none" diff --git a/crates/compact-lint/tests/fixtures/constraints-placeholder/compact-lint.toml b/crates/compact-lint/tests/fixtures/error-on-warnings/compact.toml similarity index 59% rename from crates/compact-lint/tests/fixtures/constraints-placeholder/compact-lint.toml rename to crates/compact-lint/tests/fixtures/error-on-warnings/compact.toml index 0813e24..01fa5a7 100644 --- a/crates/compact-lint/tests/fixtures/constraints-placeholder/compact-lint.toml +++ b/crates/compact-lint/tests/fixtures/error-on-warnings/compact.toml @@ -1,27 +1,27 @@ -version = 1 +[lint] include = ["**/*.compact"] -[tags] +[lint.tags] forbid = ["@return"] -[kinds.module] +[lint.kinds.module] tags = ["@module", "@description"] -[kinds.circuit] +[lint.kinds.circuit] tags = ["@description"] -[kinds.ledger] +[lint.kinds.ledger] tags = ["@description"] -[kinds.witness] +[lint.kinds.witness] docs = "all" tags = ["@description"] -[kinds.struct] +[lint.kinds.struct] tags = ["@description"] -[kinds.enum] +[lint.kinds.enum] tags = ["@description"] -[kinds.constructor] +[lint.kinds.constructor] docs = "none" diff --git a/crates/compact-lint/tests/fixtures/fill-basic/compact-lint.toml b/crates/compact-lint/tests/fixtures/fill-basic/compact.toml similarity index 65% rename from crates/compact-lint/tests/fixtures/fill-basic/compact-lint.toml rename to crates/compact-lint/tests/fixtures/fill-basic/compact.toml index e5a81d8..2edfac9 100644 --- a/crates/compact-lint/tests/fixtures/fill-basic/compact-lint.toml +++ b/crates/compact-lint/tests/fixtures/fill-basic/compact.toml @@ -1,8 +1,8 @@ -version = 1 +[lint] exclude = ["**/test/mocks/**"] -[kinds.module] +[lint.kinds.module] tags = ["@module", "@description"] -[kinds.circuit] +[lint.kinds.circuit] tags = ["@description"] diff --git a/crates/compact-lint/tests/fixtures/fill-compiler-fails/compact-lint.toml b/crates/compact-lint/tests/fixtures/fill-compiler-fails/compact.toml similarity index 65% rename from crates/compact-lint/tests/fixtures/fill-compiler-fails/compact-lint.toml rename to crates/compact-lint/tests/fixtures/fill-compiler-fails/compact.toml index e5a81d8..2edfac9 100644 --- a/crates/compact-lint/tests/fixtures/fill-compiler-fails/compact-lint.toml +++ b/crates/compact-lint/tests/fixtures/fill-compiler-fails/compact.toml @@ -1,8 +1,8 @@ -version = 1 +[lint] exclude = ["**/test/mocks/**"] -[kinds.module] +[lint.kinds.module] tags = ["@module", "@description"] -[kinds.circuit] +[lint.kinds.circuit] tags = ["@description"] diff --git a/crates/compact-lint/tests/fixtures/fill-missing-source/compact-lint.toml b/crates/compact-lint/tests/fixtures/fill-missing-source/compact.toml similarity index 55% rename from crates/compact-lint/tests/fixtures/fill-missing-source/compact-lint.toml rename to crates/compact-lint/tests/fixtures/fill-missing-source/compact.toml index 584076c..e131424 100644 --- a/crates/compact-lint/tests/fixtures/fill-missing-source/compact-lint.toml +++ b/crates/compact-lint/tests/fixtures/fill-missing-source/compact.toml @@ -1,7 +1,7 @@ -version = 1 +[lint] -[kinds.module] +[lint.kinds.module] tags = ["@module", "@description"] -[kinds.circuit] +[lint.kinds.circuit] tags = ["@description"] diff --git a/crates/compact-lint/tests/fixtures/fill-no-compile/compact-lint.toml b/crates/compact-lint/tests/fixtures/fill-no-compile/compact.toml similarity index 65% rename from crates/compact-lint/tests/fixtures/fill-no-compile/compact-lint.toml rename to crates/compact-lint/tests/fixtures/fill-no-compile/compact.toml index e5a81d8..2edfac9 100644 --- a/crates/compact-lint/tests/fixtures/fill-no-compile/compact-lint.toml +++ b/crates/compact-lint/tests/fixtures/fill-no-compile/compact.toml @@ -1,8 +1,8 @@ -version = 1 +[lint] exclude = ["**/test/mocks/**"] -[kinds.module] +[lint.kinds.module] tags = ["@module", "@description"] -[kinds.circuit] +[lint.kinds.circuit] tags = ["@description"] diff --git a/crates/compact-lint/tests/fixtures/fill-override/compact-lint.toml b/crates/compact-lint/tests/fixtures/fill-override/compact.toml similarity index 68% rename from crates/compact-lint/tests/fixtures/fill-override/compact-lint.toml rename to crates/compact-lint/tests/fixtures/fill-override/compact.toml index 4f16f10..a903294 100644 --- a/crates/compact-lint/tests/fixtures/fill-override/compact-lint.toml +++ b/crates/compact-lint/tests/fixtures/fill-override/compact.toml @@ -1,11 +1,11 @@ -version = 1 +[lint] exclude = ["**/test/mocks/**"] -[constraints.overrides] +[lint.constraints.overrides] "src/utils/Utils.compact" = "src/utils/test/mocks/MockUtilities.compact" -[kinds.module] +[lint.kinds.module] tags = ["@module", "@description"] -[kinds.circuit] +[lint.kinds.circuit] tags = ["@description"] diff --git a/crates/compact-lint/tests/fixtures/fill-self/compact-lint.toml b/crates/compact-lint/tests/fixtures/fill-self/compact.toml similarity index 56% rename from crates/compact-lint/tests/fixtures/fill-self/compact-lint.toml rename to crates/compact-lint/tests/fixtures/fill-self/compact.toml index 8545132..d4c9f2f 100644 --- a/crates/compact-lint/tests/fixtures/fill-self/compact-lint.toml +++ b/crates/compact-lint/tests/fixtures/fill-self/compact.toml @@ -1,10 +1,10 @@ -version = 1 +[lint] -[constraints] +[lint.constraints] self = ["**/presets/**"] -[kinds.module] +[lint.kinds.module] tags = ["@module", "@description"] -[kinds.circuit] +[lint.kinds.circuit] tags = ["@description"] diff --git a/crates/compact-lint/tests/fixtures/fix-constraints/compact-lint.toml b/crates/compact-lint/tests/fixtures/fix-constraints/compact.toml similarity index 52% rename from crates/compact-lint/tests/fixtures/fix-constraints/compact-lint.toml rename to crates/compact-lint/tests/fixtures/fix-constraints/compact.toml index 832f4ee..0a6450a 100644 --- a/crates/compact-lint/tests/fixtures/fix-constraints/compact-lint.toml +++ b/crates/compact-lint/tests/fixtures/fix-constraints/compact.toml @@ -1,13 +1,13 @@ -version = 1 +[lint] include = ["**/*.compact"] -[constraints] +[lint.constraints] tag = "@constraints" -[kinds.module] +[lint.kinds.module] tags = ["@module", "@description"] -[kinds.circuit] +[lint.kinds.circuit] -[kinds.constructor] +[lint.kinds.constructor] docs = "none" diff --git a/crates/compact-lint/tests/fixtures/fix-crlf/compact-lint.toml b/crates/compact-lint/tests/fixtures/fix-crlf/compact.toml similarity index 63% rename from crates/compact-lint/tests/fixtures/fix-crlf/compact-lint.toml rename to crates/compact-lint/tests/fixtures/fix-crlf/compact.toml index 5e3068c..de1e948 100644 --- a/crates/compact-lint/tests/fixtures/fix-crlf/compact-lint.toml +++ b/crates/compact-lint/tests/fixtures/fix-crlf/compact.toml @@ -1,18 +1,18 @@ -version = 1 +[lint] include = ["**/*.compact"] -[tags] +[lint.tags] forbid = ["@return"] rename = { "@return" = "@returns" } -[kinds.module] +[lint.kinds.module] tags = ["@module", "@description"] -[kinds.circuit] +[lint.kinds.circuit] tags = ["@description"] -[kinds.ledger] +[lint.kinds.ledger] tags = ["@description"] -[kinds.constructor] +[lint.kinds.constructor] docs = "none" diff --git a/crates/compact-lint/tests/fixtures/fix-missing-tag/compact-lint.toml b/crates/compact-lint/tests/fixtures/fix-missing-tag/compact.toml similarity index 57% rename from crates/compact-lint/tests/fixtures/fix-missing-tag/compact-lint.toml rename to crates/compact-lint/tests/fixtures/fix-missing-tag/compact.toml index 3af7b21..a8f7e9a 100644 --- a/crates/compact-lint/tests/fixtures/fix-missing-tag/compact-lint.toml +++ b/crates/compact-lint/tests/fixtures/fix-missing-tag/compact.toml @@ -1,14 +1,14 @@ -version = 1 +[lint] include = ["**/*.compact"] -[kinds.module] +[lint.kinds.module] tags = ["@module", "@description"] -[kinds.circuit] +[lint.kinds.circuit] tags = ["@description"] -[kinds.ledger] +[lint.kinds.ledger] tags = ["@description"] -[kinds.constructor] +[lint.kinds.constructor] docs = "none" diff --git a/crates/compact-lint/tests/fixtures/fix-module-name/compact-lint.toml b/crates/compact-lint/tests/fixtures/fix-module-name/compact.toml similarity index 60% rename from crates/compact-lint/tests/fixtures/fix-module-name/compact-lint.toml rename to crates/compact-lint/tests/fixtures/fix-module-name/compact.toml index d404f25..bbc8338 100644 --- a/crates/compact-lint/tests/fixtures/fix-module-name/compact-lint.toml +++ b/crates/compact-lint/tests/fixtures/fix-module-name/compact.toml @@ -1,8 +1,8 @@ -version = 1 +[lint] include = ["**/*.compact"] -[kinds.module] +[lint.kinds.module] tags = ["@module", "@description"] -[kinds.constructor] +[lint.kinds.constructor] docs = "none" diff --git a/crates/compact-lint/tests/fixtures/fix-rename/compact-lint.toml b/crates/compact-lint/tests/fixtures/fix-rename/compact.toml similarity index 65% rename from crates/compact-lint/tests/fixtures/fix-rename/compact-lint.toml rename to crates/compact-lint/tests/fixtures/fix-rename/compact.toml index ad6ecc5..05f63b3 100644 --- a/crates/compact-lint/tests/fixtures/fix-rename/compact-lint.toml +++ b/crates/compact-lint/tests/fixtures/fix-rename/compact.toml @@ -1,15 +1,15 @@ -version = 1 +[lint] include = ["**/*.compact"] -[tags] +[lint.tags] forbid = ["@return"] rename = { "@return" = "@returns" } -[kinds.module] +[lint.kinds.module] tags = ["@module", "@description"] -[kinds.circuit] +[lint.kinds.circuit] tags = ["@description"] -[kinds.constructor] +[lint.kinds.constructor] docs = "none" diff --git a/crates/compact-lint/tests/fixtures/fix-skeleton/compact-lint.toml b/crates/compact-lint/tests/fixtures/fix-skeleton/compact.toml similarity index 62% rename from crates/compact-lint/tests/fixtures/fix-skeleton/compact-lint.toml rename to crates/compact-lint/tests/fixtures/fix-skeleton/compact.toml index 5fd3408..234ff29 100644 --- a/crates/compact-lint/tests/fixtures/fix-skeleton/compact-lint.toml +++ b/crates/compact-lint/tests/fixtures/fix-skeleton/compact.toml @@ -1,31 +1,31 @@ -version = 1 +[lint] include = ["**/*.compact"] -[fix] +[lint.fix] placeholder = "TODO" -[tags] +[lint.tags] forbid = ["@return"] rename = { "@return" = "@returns" } -[kinds.module] +[lint.kinds.module] tags = ["@module", "@description"] -[kinds.circuit] +[lint.kinds.circuit] tags = ["@description"] -[kinds.ledger] +[lint.kinds.ledger] tags = ["@description"] -[kinds.witness] +[lint.kinds.witness] docs = "all" tags = ["@description"] -[kinds.struct] +[lint.kinds.struct] tags = ["@description"] -[kinds.enum] +[lint.kinds.enum] tags = ["@description"] -[kinds.constructor] +[lint.kinds.constructor] docs = "none" diff --git a/crates/compact-lint/tests/fixtures/fix-unfixable/compact-lint.toml b/crates/compact-lint/tests/fixtures/fix-unfixable/compact.toml similarity index 70% rename from crates/compact-lint/tests/fixtures/fix-unfixable/compact-lint.toml rename to crates/compact-lint/tests/fixtures/fix-unfixable/compact.toml index 9bb3ab8..3e20ce9 100644 --- a/crates/compact-lint/tests/fixtures/fix-unfixable/compact-lint.toml +++ b/crates/compact-lint/tests/fixtures/fix-unfixable/compact.toml @@ -1,15 +1,15 @@ -version = 1 +[lint] include = ["**/*.compact"] # `@throws` is forbidden but has no replacement, so `fix` leaves it where it is. -[tags] +[lint.tags] forbid = ["@throws"] -[kinds.module] +[lint.kinds.module] tags = ["@module", "@description"] -[kinds.circuit] +[lint.kinds.circuit] tags = ["@description"] -[kinds.constructor] +[lint.kinds.constructor] docs = "none" diff --git a/crates/compact-lint/tests/fixtures/forbidden-tag/compact-lint.toml b/crates/compact-lint/tests/fixtures/forbidden-tag/compact-lint.toml deleted file mode 100644 index 0813e24..0000000 --- a/crates/compact-lint/tests/fixtures/forbidden-tag/compact-lint.toml +++ /dev/null @@ -1,27 +0,0 @@ -version = 1 -include = ["**/*.compact"] - -[tags] -forbid = ["@return"] - -[kinds.module] -tags = ["@module", "@description"] - -[kinds.circuit] -tags = ["@description"] - -[kinds.ledger] -tags = ["@description"] - -[kinds.witness] -docs = "all" -tags = ["@description"] - -[kinds.struct] -tags = ["@description"] - -[kinds.enum] -tags = ["@description"] - -[kinds.constructor] -docs = "none" diff --git a/crates/compact-lint/tests/fixtures/forbidden-tag/compact.toml b/crates/compact-lint/tests/fixtures/forbidden-tag/compact.toml new file mode 100644 index 0000000..01fa5a7 --- /dev/null +++ b/crates/compact-lint/tests/fixtures/forbidden-tag/compact.toml @@ -0,0 +1,27 @@ +[lint] +include = ["**/*.compact"] + +[lint.tags] +forbid = ["@return"] + +[lint.kinds.module] +tags = ["@module", "@description"] + +[lint.kinds.circuit] +tags = ["@description"] + +[lint.kinds.ledger] +tags = ["@description"] + +[lint.kinds.witness] +docs = "all" +tags = ["@description"] + +[lint.kinds.struct] +tags = ["@description"] + +[lint.kinds.enum] +tags = ["@description"] + +[lint.kinds.constructor] +docs = "none" diff --git a/crates/compact-lint/tests/fixtures/max-diagnostics/compact-lint.toml b/crates/compact-lint/tests/fixtures/max-diagnostics/compact-lint.toml deleted file mode 100644 index 0813e24..0000000 --- a/crates/compact-lint/tests/fixtures/max-diagnostics/compact-lint.toml +++ /dev/null @@ -1,27 +0,0 @@ -version = 1 -include = ["**/*.compact"] - -[tags] -forbid = ["@return"] - -[kinds.module] -tags = ["@module", "@description"] - -[kinds.circuit] -tags = ["@description"] - -[kinds.ledger] -tags = ["@description"] - -[kinds.witness] -docs = "all" -tags = ["@description"] - -[kinds.struct] -tags = ["@description"] - -[kinds.enum] -tags = ["@description"] - -[kinds.constructor] -docs = "none" diff --git a/crates/compact-lint/tests/fixtures/max-diagnostics/compact.toml b/crates/compact-lint/tests/fixtures/max-diagnostics/compact.toml new file mode 100644 index 0000000..01fa5a7 --- /dev/null +++ b/crates/compact-lint/tests/fixtures/max-diagnostics/compact.toml @@ -0,0 +1,27 @@ +[lint] +include = ["**/*.compact"] + +[lint.tags] +forbid = ["@return"] + +[lint.kinds.module] +tags = ["@module", "@description"] + +[lint.kinds.circuit] +tags = ["@description"] + +[lint.kinds.ledger] +tags = ["@description"] + +[lint.kinds.witness] +docs = "all" +tags = ["@description"] + +[lint.kinds.struct] +tags = ["@description"] + +[lint.kinds.enum] +tags = ["@description"] + +[lint.kinds.constructor] +docs = "none" diff --git a/crates/compact-lint/tests/fixtures/missing-constraints/compact-lint.toml b/crates/compact-lint/tests/fixtures/missing-constraints/compact-lint.toml deleted file mode 100644 index 0813e24..0000000 --- a/crates/compact-lint/tests/fixtures/missing-constraints/compact-lint.toml +++ /dev/null @@ -1,27 +0,0 @@ -version = 1 -include = ["**/*.compact"] - -[tags] -forbid = ["@return"] - -[kinds.module] -tags = ["@module", "@description"] - -[kinds.circuit] -tags = ["@description"] - -[kinds.ledger] -tags = ["@description"] - -[kinds.witness] -docs = "all" -tags = ["@description"] - -[kinds.struct] -tags = ["@description"] - -[kinds.enum] -tags = ["@description"] - -[kinds.constructor] -docs = "none" diff --git a/crates/compact-lint/tests/fixtures/missing-constraints/compact.toml b/crates/compact-lint/tests/fixtures/missing-constraints/compact.toml new file mode 100644 index 0000000..01fa5a7 --- /dev/null +++ b/crates/compact-lint/tests/fixtures/missing-constraints/compact.toml @@ -0,0 +1,27 @@ +[lint] +include = ["**/*.compact"] + +[lint.tags] +forbid = ["@return"] + +[lint.kinds.module] +tags = ["@module", "@description"] + +[lint.kinds.circuit] +tags = ["@description"] + +[lint.kinds.ledger] +tags = ["@description"] + +[lint.kinds.witness] +docs = "all" +tags = ["@description"] + +[lint.kinds.struct] +tags = ["@description"] + +[lint.kinds.enum] +tags = ["@description"] + +[lint.kinds.constructor] +docs = "none" diff --git a/crates/compact-lint/tests/fixtures/missing-doc/compact-lint.toml b/crates/compact-lint/tests/fixtures/missing-doc/compact-lint.toml deleted file mode 100644 index 0813e24..0000000 --- a/crates/compact-lint/tests/fixtures/missing-doc/compact-lint.toml +++ /dev/null @@ -1,27 +0,0 @@ -version = 1 -include = ["**/*.compact"] - -[tags] -forbid = ["@return"] - -[kinds.module] -tags = ["@module", "@description"] - -[kinds.circuit] -tags = ["@description"] - -[kinds.ledger] -tags = ["@description"] - -[kinds.witness] -docs = "all" -tags = ["@description"] - -[kinds.struct] -tags = ["@description"] - -[kinds.enum] -tags = ["@description"] - -[kinds.constructor] -docs = "none" diff --git a/crates/compact-lint/tests/fixtures/missing-doc/compact.toml b/crates/compact-lint/tests/fixtures/missing-doc/compact.toml new file mode 100644 index 0000000..01fa5a7 --- /dev/null +++ b/crates/compact-lint/tests/fixtures/missing-doc/compact.toml @@ -0,0 +1,27 @@ +[lint] +include = ["**/*.compact"] + +[lint.tags] +forbid = ["@return"] + +[lint.kinds.module] +tags = ["@module", "@description"] + +[lint.kinds.circuit] +tags = ["@description"] + +[lint.kinds.ledger] +tags = ["@description"] + +[lint.kinds.witness] +docs = "all" +tags = ["@description"] + +[lint.kinds.struct] +tags = ["@description"] + +[lint.kinds.enum] +tags = ["@description"] + +[lint.kinds.constructor] +docs = "none" diff --git a/crates/compact-lint/tests/fixtures/missing-tag/compact-lint.toml b/crates/compact-lint/tests/fixtures/missing-tag/compact-lint.toml deleted file mode 100644 index 0813e24..0000000 --- a/crates/compact-lint/tests/fixtures/missing-tag/compact-lint.toml +++ /dev/null @@ -1,27 +0,0 @@ -version = 1 -include = ["**/*.compact"] - -[tags] -forbid = ["@return"] - -[kinds.module] -tags = ["@module", "@description"] - -[kinds.circuit] -tags = ["@description"] - -[kinds.ledger] -tags = ["@description"] - -[kinds.witness] -docs = "all" -tags = ["@description"] - -[kinds.struct] -tags = ["@description"] - -[kinds.enum] -tags = ["@description"] - -[kinds.constructor] -docs = "none" diff --git a/crates/compact-lint/tests/fixtures/missing-tag/compact.toml b/crates/compact-lint/tests/fixtures/missing-tag/compact.toml new file mode 100644 index 0000000..01fa5a7 --- /dev/null +++ b/crates/compact-lint/tests/fixtures/missing-tag/compact.toml @@ -0,0 +1,27 @@ +[lint] +include = ["**/*.compact"] + +[lint.tags] +forbid = ["@return"] + +[lint.kinds.module] +tags = ["@module", "@description"] + +[lint.kinds.circuit] +tags = ["@description"] + +[lint.kinds.ledger] +tags = ["@description"] + +[lint.kinds.witness] +docs = "all" +tags = ["@description"] + +[lint.kinds.struct] +tags = ["@description"] + +[lint.kinds.enum] +tags = ["@description"] + +[lint.kinds.constructor] +docs = "none" diff --git a/crates/compact-lint/tests/fixtures/module-name/compact-lint.toml b/crates/compact-lint/tests/fixtures/module-name/compact-lint.toml deleted file mode 100644 index 0813e24..0000000 --- a/crates/compact-lint/tests/fixtures/module-name/compact-lint.toml +++ /dev/null @@ -1,27 +0,0 @@ -version = 1 -include = ["**/*.compact"] - -[tags] -forbid = ["@return"] - -[kinds.module] -tags = ["@module", "@description"] - -[kinds.circuit] -tags = ["@description"] - -[kinds.ledger] -tags = ["@description"] - -[kinds.witness] -docs = "all" -tags = ["@description"] - -[kinds.struct] -tags = ["@description"] - -[kinds.enum] -tags = ["@description"] - -[kinds.constructor] -docs = "none" diff --git a/crates/compact-lint/tests/fixtures/module-name/compact.toml b/crates/compact-lint/tests/fixtures/module-name/compact.toml new file mode 100644 index 0000000..01fa5a7 --- /dev/null +++ b/crates/compact-lint/tests/fixtures/module-name/compact.toml @@ -0,0 +1,27 @@ +[lint] +include = ["**/*.compact"] + +[lint.tags] +forbid = ["@return"] + +[lint.kinds.module] +tags = ["@module", "@description"] + +[lint.kinds.circuit] +tags = ["@description"] + +[lint.kinds.ledger] +tags = ["@description"] + +[lint.kinds.witness] +docs = "all" +tags = ["@description"] + +[lint.kinds.struct] +tags = ["@description"] + +[lint.kinds.enum] +tags = ["@description"] + +[lint.kinds.constructor] +docs = "none" diff --git a/crates/compact-lint/tests/fixtures/no-lint-table/compact.toml b/crates/compact-lint/tests/fixtures/no-lint-table/compact.toml new file mode 100644 index 0000000..e7d243d --- /dev/null +++ b/crates/compact-lint/tests/fixtures/no-lint-table/compact.toml @@ -0,0 +1,14 @@ +# compact-deploy's tables only: the file exists, the linter's table does not. +[profile] +default_network = "local" + +[networks.local] +network_id = "undeployed" +indexer = "http://127.0.0.1:8088/api/v4/graphql" +indexer_ws = "ws://127.0.0.1:8088/api/v4/graphql/ws" +node = "http://127.0.0.1:9944" +node_ws = "ws://127.0.0.1:9944" + +[contracts.Token] +artifact = "Token" +signing_key_file = "deploy/Token.signingkey" diff --git a/crates/compact-lint/tests/fixtures/parse/compact-lint.toml b/crates/compact-lint/tests/fixtures/parse/compact.toml similarity index 69% rename from crates/compact-lint/tests/fixtures/parse/compact-lint.toml rename to crates/compact-lint/tests/fixtures/parse/compact.toml index 56ee774..e7401e9 100644 --- a/crates/compact-lint/tests/fixtures/parse/compact-lint.toml +++ b/crates/compact-lint/tests/fixtures/parse/compact.toml @@ -1,2 +1,2 @@ -version = 1 +[lint] include = ["**/*.compact"] diff --git a/crates/compact-lint/tests/fixtures/reporter-concise/compact-lint.toml b/crates/compact-lint/tests/fixtures/reporter-concise/compact-lint.toml deleted file mode 100644 index 0813e24..0000000 --- a/crates/compact-lint/tests/fixtures/reporter-concise/compact-lint.toml +++ /dev/null @@ -1,27 +0,0 @@ -version = 1 -include = ["**/*.compact"] - -[tags] -forbid = ["@return"] - -[kinds.module] -tags = ["@module", "@description"] - -[kinds.circuit] -tags = ["@description"] - -[kinds.ledger] -tags = ["@description"] - -[kinds.witness] -docs = "all" -tags = ["@description"] - -[kinds.struct] -tags = ["@description"] - -[kinds.enum] -tags = ["@description"] - -[kinds.constructor] -docs = "none" diff --git a/crates/compact-lint/tests/fixtures/reporter-concise/compact.toml b/crates/compact-lint/tests/fixtures/reporter-concise/compact.toml new file mode 100644 index 0000000..01fa5a7 --- /dev/null +++ b/crates/compact-lint/tests/fixtures/reporter-concise/compact.toml @@ -0,0 +1,27 @@ +[lint] +include = ["**/*.compact"] + +[lint.tags] +forbid = ["@return"] + +[lint.kinds.module] +tags = ["@module", "@description"] + +[lint.kinds.circuit] +tags = ["@description"] + +[lint.kinds.ledger] +tags = ["@description"] + +[lint.kinds.witness] +docs = "all" +tags = ["@description"] + +[lint.kinds.struct] +tags = ["@description"] + +[lint.kinds.enum] +tags = ["@description"] + +[lint.kinds.constructor] +docs = "none" diff --git a/crates/compact-lint/tests/fixtures/reporter-github/compact-lint.toml b/crates/compact-lint/tests/fixtures/reporter-github/compact-lint.toml deleted file mode 100644 index 0813e24..0000000 --- a/crates/compact-lint/tests/fixtures/reporter-github/compact-lint.toml +++ /dev/null @@ -1,27 +0,0 @@ -version = 1 -include = ["**/*.compact"] - -[tags] -forbid = ["@return"] - -[kinds.module] -tags = ["@module", "@description"] - -[kinds.circuit] -tags = ["@description"] - -[kinds.ledger] -tags = ["@description"] - -[kinds.witness] -docs = "all" -tags = ["@description"] - -[kinds.struct] -tags = ["@description"] - -[kinds.enum] -tags = ["@description"] - -[kinds.constructor] -docs = "none" diff --git a/crates/compact-lint/tests/fixtures/reporter-github/compact.toml b/crates/compact-lint/tests/fixtures/reporter-github/compact.toml new file mode 100644 index 0000000..01fa5a7 --- /dev/null +++ b/crates/compact-lint/tests/fixtures/reporter-github/compact.toml @@ -0,0 +1,27 @@ +[lint] +include = ["**/*.compact"] + +[lint.tags] +forbid = ["@return"] + +[lint.kinds.module] +tags = ["@module", "@description"] + +[lint.kinds.circuit] +tags = ["@description"] + +[lint.kinds.ledger] +tags = ["@description"] + +[lint.kinds.witness] +docs = "all" +tags = ["@description"] + +[lint.kinds.struct] +tags = ["@description"] + +[lint.kinds.enum] +tags = ["@description"] + +[lint.kinds.constructor] +docs = "none" diff --git a/crates/compact-lint/tests/fixtures/rules-levels/compact-lint.toml b/crates/compact-lint/tests/fixtures/rules-levels/compact.toml similarity index 64% rename from crates/compact-lint/tests/fixtures/rules-levels/compact-lint.toml rename to crates/compact-lint/tests/fixtures/rules-levels/compact.toml index 4622830..02a0b35 100644 --- a/crates/compact-lint/tests/fixtures/rules-levels/compact-lint.toml +++ b/crates/compact-lint/tests/fixtures/rules-levels/compact.toml @@ -1,32 +1,32 @@ -version = 1 +[lint] include = ["**/*.compact"] -[tags] +[lint.tags] forbid = ["@return"] rename = { "@return" = "@returns" } -[kinds.module] +[lint.kinds.module] tags = ["@module", "@description"] -[kinds.circuit] +[lint.kinds.circuit] tags = ["@description"] -[kinds.ledger] +[lint.kinds.ledger] tags = ["@description"] -[kinds.witness] +[lint.kinds.witness] docs = "all" tags = ["@description"] -[kinds.struct] +[lint.kinds.struct] tags = ["@description"] -[kinds.enum] +[lint.kinds.enum] tags = ["@description"] -[kinds.constructor] +[lint.kinds.constructor] docs = "none" -[rules] +[lint.rules] missing-doc = "off" forbidden-tag = "warn" diff --git a/examples/fungible-token/compact.toml b/examples/fungible-token/compact.toml index 672d90a..85a6f57 100644 --- a/examples/fungible-token/compact.toml +++ b/examples/fungible-token/compact.toml @@ -46,3 +46,5 @@ signing_key_file = "deploy/TokenExample.signingkey" # them from here. The programmatic flow (`yarn deploy:*`) overrides # them inline via the `args:` field on `runDeploy()`. args = { module = "./deploy/TokenExample.args.mjs", export = "args" } + +# compact-lint reads a [lint] table from this same file; see crates/compact-lint/examples/compact.toml. diff --git a/packages/deployer/src/config/compact-config.test.ts b/packages/deployer/src/config/compact-config.test.ts index 2ef37c6..25d4a62 100644 --- a/packages/deployer/src/config/compact-config.test.ts +++ b/packages/deployer/src/config/compact-config.test.ts @@ -38,6 +38,24 @@ describe('CompactConfig', () => { expect(config.contract('Token').artifact).toBe('src/artifacts/Token/Token'); }); + it('ignores the [lint] table that compact-lint owns', async () => { + const dir = tmpRepo(`${MIN_VALID} +[lint] +include = ["contracts/src/**/*.compact"] + +[lint.rules] +missing-doc = "error" + +[lint.kinds.module] +docs = "exported" +tags = ["@module", "@description"] +`); + const config = await CompactConfig.load(undefined, dir); + expect(config.defaultNetwork).toBe('local'); + expect(config.network('local').network_id).toBe('undeployed'); + expect(config.contract('Token').artifact).toBe('src/artifacts/Token/Token'); + }); + it('should throw with the available set when a lookup misses', async () => { const dir = tmpRepo(MIN_VALID); const config = await CompactConfig.load(undefined, dir); diff --git a/packages/linter/README.md b/packages/linter/README.md index 6bf577b..226b482 100644 --- a/packages/linter/README.md +++ b/packages/linter/README.md @@ -16,8 +16,9 @@ yarn compact-linter check contracts/src yarn compact-linter fix --dry-run ``` -Commands, flags, exit codes and `compact-lint.toml` are documented in the -[crate README](../../crates/compact-lint/README.md). +Commands, flags, exit codes and the `[lint]` table of `compact.toml` are documented in +the [crate README](../../crates/compact-lint/README.md). `compact.toml` is the project's +one config file, shared with `compact-deploy`. ## Where the binary comes from