Skip to content

Commit 6f2fb95

Browse files
authored
fix(core): remove unused CoreResult type alias, standardize on LintResult (#477) (#520)
* fix(core): remove unused CoreResult type alias, standardize on LintResult (#477) CoreResult<T> was defined and re-exported but never used anywhere in the codebase. LintResult<T> is the established convention used in 40+ locations. Since LintError is already an alias for CoreError, both aliases resolved to the same type - CoreResult was pure dead code. Closes #477 * test(core): strengthen lint_result_is_sole_result_alias with functional assertions Replace trivially-true type_name checks with concrete Err construction using CoreError::Validation variants, verifying the LintResult<T> = Result<T, LintError> = Result<T, CoreError> chain end-to-end. * fix(core): address review feedback on CoreResult removal (#477) - Add CoreError to public_types_are_importable contract test - Replace panic! with unreachable! in test catch-all arm - Upgrade LintError alias comment to rustdoc (/// style) - Expand CHANGELOG migration note to clarify LintError/CoreError relationship * test(core): exhaustively match all CoreError variants in lint_result_is_sole_result_alias Replace wildcard arm with explicit File/Validation/Config arms so the match is truly exhaustive. A new CoreError variant will now cause a compile error in this test rather than silently passing. * docs: add LintError and LintResult to diagnostics.rs module description (#477) The diagnostics.rs entry in CLAUDE.md/AGENTS.md omitted LintError and LintResult, which are the primary public error types from that module. With CoreResult removed, LintResult is now the sole public Result alias - making this an appropriate time to document both types explicitly. * fix(core): address rustfmt formatting issues Reformat pub use statement in lib.rs and struct initialization in test to comply with cargo fmt standards.
1 parent a93b724 commit 6f2fb95

6 files changed

Lines changed: 52 additions & 7 deletions

File tree

AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ tests/fixtures/ # Test cases by category
6868
- `schemas/` - Type definitions (13 schemas: skill, hooks, agent, mcp, cline, roo, etc.)
6969
- `rules/` - Validators implementing Validator trait (25 validators)
7070
- `config.rs` - LintConfig, LintConfigBuilder, ConfigError, ToolVersions, SpecRevisions
71-
- `diagnostics.rs` - Diagnostic, Fix, DiagnosticLevel, ValidationOutcome
71+
- `diagnostics.rs` - Diagnostic, Fix, DiagnosticLevel, ValidationOutcome, LintError (= CoreError), LintResult
7272
- `eval.rs` - Rule efficacy evaluation (precision/recall/F1)
7373
- `file_types/` - FileType enum, detect_file_type(), FileTypeDetector trait, FileTypeDetectorChain
7474
- `file_utils.rs` - Safe file I/O (symlink rejection, size limits)

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3535
- **`MAX_REGEX_INPUT_SIZE` precise boundary tests**: 27 tests covering the exact 65536-byte limit for all 12 guarded regex functions across `markdown.rs`, `prompt.rs`, and `cross_platform.rs` - each function gets an at-limit (processed) and one-byte-over (rejected) test; also confirms `extract_imports` and `extract_markdown_links` are unrestricted (byte-scan/pulldown-cmark, not regex) (#457)
3636

3737
### Changed
38+
- **`CoreResult` type alias removed** (breaking): `CoreResult<T>` has been removed from the public API. Use `LintResult<T>` (i.e., `Result<T, LintError>`) instead. `LintError` is a public alias for `CoreError`; both remain exported. (#477)
3839
- **`__internal` module feature-gated**: The `__internal` module in `agnix-core` is now behind the `__internal` Cargo feature; it was previously unconditionally public which created semver obligations for internal items (#472)
3940
- **`normalize_line_endings` promoted to stable public API**: Accessible at the crate root (`agnix_core::normalize_line_endings`) without requiring the `__internal` feature (#472)
4041
- **Project-level validation extracted to `rules/project_level.rs`**: Extracted `run_project_level_checks`, `join_paths`, and associated unit tests from `pipeline.rs` into a new `rules/project_level.rs` module; adds 7 new unit tests for AGM-006, XP-004/005/006, and VER-001 behaviors (#474)

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ tests/fixtures/ # Test cases by category
6868
- `schemas/` - Type definitions (13 schemas: skill, hooks, agent, mcp, cline, roo, etc.)
6969
- `rules/` - Validators implementing Validator trait (25 validators)
7070
- `config.rs` - LintConfig, LintConfigBuilder, ConfigError, ToolVersions, SpecRevisions
71-
- `diagnostics.rs` - Diagnostic, Fix, DiagnosticLevel, ValidationOutcome
71+
- `diagnostics.rs` - Diagnostic, Fix, DiagnosticLevel, ValidationOutcome, LintError (= CoreError), LintResult
7272
- `eval.rs` - Rule efficacy evaluation (precision/recall/F1)
7373
- `file_types/` - FileType enum, detect_file_type(), FileTypeDetector trait, FileTypeDetectorChain
7474
- `file_utils.rs` - Safe file I/O (symlink rejection, size limits)

crates/agnix-core/src/diagnostics.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::path::PathBuf;
77
use thiserror::Error;
88

99
pub type LintResult<T> = Result<T, LintError>;
10-
pub type CoreResult<T> = Result<T, CoreError>;
1110

1211
/// An automatic fix for a diagnostic
1312
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -673,7 +672,11 @@ impl CoreError {
673672
}
674673
}
675674

676-
// Backward compatibility: LintError is now an alias for CoreError
675+
/// `LintError` is the canonical public name for [`CoreError`].
676+
///
677+
/// Both names are re-exported at the crate root. Internal code constructs
678+
/// variants via `CoreError`; public API surfaces and function signatures
679+
/// use `LintError` and [`LintResult`].
677680
pub type LintError = CoreError;
678681

679682
/// Outcome of validating a single file.

crates/agnix-core/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ pub mod validation;
8989

9090
pub use config::{ConfigWarning, FilesConfig, LintConfig, generate_schema};
9191
pub use diagnostics::{
92-
ConfigError, CoreError, CoreResult, Diagnostic, DiagnosticLevel, FileError, Fix,
93-
FixConfidenceTier, LintError, LintResult, RuleMetadata, ValidationError, ValidationOutcome,
92+
ConfigError, CoreError, Diagnostic, DiagnosticLevel, FileError, Fix, FixConfidenceTier,
93+
LintError, LintResult, RuleMetadata, ValidationError, ValidationOutcome,
9494
};
9595
pub use file_types::{FileType, detect_file_type};
9696
pub use file_types::{FileTypeDetector, FileTypeDetectorChain};

crates/agnix-core/tests/api_contract.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ fn public_types_are_importable() {
2828
let _ = std::any::type_name::<agnix_core::FilesConfig>();
2929
let _ = std::any::type_name::<agnix_core::ValidationOutcome>();
3030

31-
// LintResult type alias
31+
// Error types: CoreError is the concrete enum; LintError is its public alias.
32+
// Both are re-exported. CoreResult was removed in #477.
33+
let _ = std::any::type_name::<agnix_core::CoreError>();
34+
// LintResult type alias - the sole public Result alias.
3235
let _ = std::any::type_name::<agnix_core::LintResult<()>>();
3336

3437
// ValidatorFactory type alias
@@ -1136,3 +1139,41 @@ fn normalize_line_endings_lf_only_is_borrowed_and_zero_copy() {
11361139
"Cow::Borrowed must point to the original allocation"
11371140
);
11381141
}
1142+
1143+
// ============================================================================
1144+
// LintResult is the sole public Result alias (#477)
1145+
// ============================================================================
1146+
1147+
/// Verify that `LintResult<T>` is the sole public Result alias in agnix-core.
1148+
///
1149+
/// `CoreResult<T>` was removed in #477 because it was dead code - defined and
1150+
/// re-exported but never used anywhere in the codebase. `LintResult<T>` is the
1151+
/// established convention used across 40+ call sites.
1152+
#[test]
1153+
fn lint_result_is_sole_result_alias() {
1154+
use agnix_core::{CoreError, LintError, LintResult, ValidationError};
1155+
1156+
// LintResult<T> must accept Ok values.
1157+
let ok: LintResult<u32> = Ok(42);
1158+
assert_eq!(ok.unwrap(), 42);
1159+
1160+
// LintResult<T> must accept Err values constructed from a concrete CoreError variant.
1161+
// This verifies LintResult<T> = Result<T, LintError> = Result<T, CoreError> end-to-end.
1162+
let err: LintResult<u32> = Err(CoreError::Validation(ValidationError::TooManyFiles {
1163+
count: 9999,
1164+
limit: 1000,
1165+
}));
1166+
assert!(err.is_err());
1167+
1168+
// LintError and CoreError are type aliases for the same enum - constructing
1169+
// one variant via CoreError and matching through LintError must work.
1170+
let lint_err: LintError =
1171+
CoreError::Validation(ValidationError::TooManyFiles { count: 1, limit: 0 });
1172+
// Exhaustively match all three CoreError variants through the LintError alias.
1173+
// If a new CoreError variant is added, this match will fail to compile.
1174+
match lint_err {
1175+
LintError::File(_) => {}
1176+
LintError::Validation(_) => {}
1177+
LintError::Config(_) => {}
1178+
}
1179+
}

0 commit comments

Comments
 (0)