Skip to content

feat(CM0001): warn when alcops.json cannot be fully loaded - #512

Merged
Arthurvdv merged 5 commits into
mainfrom
feat/cm0001-configuration-load-diagnostic
Sep 4, 2026
Merged

feat(CM0001): warn when alcops.json cannot be fully loaded#512
Arthurvdv merged 5 commits into
mainfrom
feat/cm0001-configuration-load-diagnostic

Conversation

@Arthurvdv

Copy link
Copy Markdown
Member

Closes #328

What

A found-but-broken alcops.json no longer fails silently. A new diagnostic CM0001 (Warning, enabled by default) reports:

  • the file exists but cannot be read (I/O or permission error) → defaults + warning
  • the file contains malformed JSON (syntax error, wrong types, unknown enum values) → defaults + warning
  • the file is valid but contains unknown top-level settings (typo'd names) → recognized settings still apply, one warning per unknown key (case-insensitive, $schema allowlisted)

No file at all still means silent defaults. The malformed→defaults fallback contract is unchanged — the diagnostic is purely additive.

How

  • ALCopsSettingsProvider now caches an ALCopsSettingsLoadResult (settings + SettingsLoadFailures). GetSettings is a thin wrapper, so the seven existing call sites are untouched. The failure taxonomy (Unreadable/Invalid/UnknownSetting + free-text detail) leaves room for the remote-configuration failure modes deferred here by feat: support remote ALCops configuration #500.
  • The analyzer is hosted in ALCops.Common.dll itself — one diagnostic instead of six per-cop duplicates. This is loader-safe: every documented install path already lists ALCops.Common.dll as an analyzer reference, alc discovers analyzers purely by the [DiagnosticAnalyzer] attribute, and the v1.0.0 breaks under alc (AL compiler): AL1003 — cops can't instantiate because ALCops.Common is not resolved from the Analyzers folder #389 AL1003 trap only applies to types whose base class lives in a sibling DLL — this analyzer derives directly from the SDK DiagnosticAnalyzer. (Microsoft ships the same pattern in Microsoft.Dynamics.Nav.Analyzers.Common.dll.)
  • Reporting via RegisterCompilationAction at Location.None (alcops.json is not part of the compilation; VS Code surfaces it against app.json). Cached failures re-report every compilation; no accumulator, no instance state.
  • The unknown-key scan is top-level only and reflection-derived from ALCopsSettings properties, so new settings extend it automatically. Nested typos remain covered by the JSON schema in editors.
  • IFileSystem.Exists (verified present at the AL 12 interface floor) distinguishes not-found from unreadable; GetAbsolutePath is deliberately avoided (absent at that floor). The previously unwrapped physical File.ReadAllText (an AD0001 path) is now handled.

Behavior change

An app-folder alcops.json that exists but cannot be read no longer silently falls through to a parent-directory configuration — the app-level file was intended to win, so ALCops uses defaults and reports CM0001 instead.

Verification

  • dotnet test ALCops.sln — 1,670 passed (16 new: 10 provider-level, 6 analyzer-level via a manual CompilationWithAnalyzers harness, since RoslynTestKit's marker asserts can't match Location.None)
  • All seven projects build clean for netstandard2.1;net8.0;net10.0 with -p:ContinuousIntegrationBuild=true
  • dotnet format --verify-no-changes clean
  • Docs pages for the new common section are in a companion alcops.dev PR

🤖 Generated with Claude Code

Arthurvdv and others added 3 commits September 4, 2026 14:39
ALCopsSettingsProvider now records why a found alcops.json was not
applied - unreadable file, malformed JSON, or unknown top-level
settings - in an ALCopsSettingsLoadResult, and the new CM0001 analyzer
hosted in ALCops.Common.dll reports each failure per compilation at
Location.None. Malformed/unreadable files still fall back to defaults;
unknown keys warn while all recognized settings keep applying.

Behavior change: an app-folder alcops.json that exists but cannot be
read no longer falls through to a parent-directory configuration.

Closes #328

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Provider tests exercise malformed JSON, unknown keys (incl. $schema
allowlist and case-insensitivity), unreadable virtual files via a
ThrowingFileSystem double, and failure caching. Analyzer tests use a
manual Compilation + CompilationWithAnalyzers harness because
RoslynTestKit's marker asserts cannot match Location.None. The shared
Conventions tests are re-enabled now that Common ships an analyzer.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Arthurvdv and others added 2 commits September 4, 2026 16:40
Comments now explain the loader mechanism instead of citing issue
numbers, and GetVirtualSource loses the catch(ArgumentException) around
Path.Combine, which stopped validating path characters in .NET Core 2.1.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ule doc

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Arthurvdv
Arthurvdv merged commit de516c4 into main Sep 4, 2026
55 checks passed
@Arthurvdv
Arthurvdv deleted the feat/cm0001-configuration-load-diagnostic branch September 4, 2026 14:50
Arthurvdv added a commit to ALCops/alcops.dev that referenced this pull request Sep 4, 2026
Adds the Common analyzers section for the cross-cutting diagnostics
hosted in ALCops.Common.dll, with the CM0001 rule page (failure modes,
what still applies, Location.None note, $schema allowlist).

Companion to ALCops/Analyzers#512 (issue #328).

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Emit diagnostic warning when alcops.json is found but cannot be parsed

1 participant