Skip to content

Refactor DslTerminologyAnalyzer into parsing and validation components#8

Merged
Pressacco merged 4 commits into
mainfrom
copilot/refactor-dsl-terminology-analyzer
Nov 27, 2025
Merged

Refactor DslTerminologyAnalyzer into parsing and validation components#8
Pressacco merged 4 commits into
mainfrom
copilot/refactor-dsl-terminology-analyzer

Conversation

Copilot AI commented Nov 27, 2025

Copy link
Copy Markdown
Contributor

Extracts parsing and validation logic from DslTerminologyAnalyzer into testable components, enabling terminology-level unit tests without analyzer overhead.

New Components

  • TerminologyRule - Data model for blocked/preferred term pairs with case sensitivity
  • DslRuleParser - Static XML parser returning List<TerminologyRule>
  • TerminologyValidator - Validates identifiers against rules

API

// Parsing
var rules = DslRuleParser.Parse(xmlContent);

// Validation - returns null if valid, or the violated rule
var validator = new TerminologyValidator(rules);
var violation = validator.GetViolation("CustValue"); // returns rule blocking "Cust"

Tests

  • 19 tests for DslRuleParser (XML parsing scenarios)
  • 21 tests for TerminologyValidator (validation edge cases: MetaData/Metadata, FileName/Filename)

Existing analyzer-level tests unchanged.

Original prompt

Objective

Refactor the DslTerminologyAnalyzer into two parts to simplify testing and improve maintainability. The two components should be:

  1. Parsing Component: Responsible for parsing out symbols (e.g., variable names, field names, property names, etc.).
  2. Validation Component: Ensures the parsed symbols match the rules provided by the DSL XML.

Background & Context

Currently, Microsoft analyzer-level tests are used to validate the behavior of DslTerminologyAnalyzer. Although useful, such tests introduce unnecessary overhead and visual noise. A more structured approach would enable:

  1. Maintaining existing analyzer-level tests (already completed).
  2. Introducing terminology-level tests that focus on problematic keyword scenarios (e.g., handling keywords like Metadata, MetaData, Filename, FileName, etc.). This facilitates more modular and faster testing.

Key Deliverables

  • Refactor the existing DslTerminologyAnalyzer into two distinguishable components: a Parsing Component and a Validation Component.
  • Implement the necessary interfaces or plumbing to ensure these components can work together seamlessly.
  • Add terminology-level unit tests to ensure:
    • Symbols are parsed correctly.
    • Rules are applied appropriately to the parsed symbols.

This refactor should maintain backward compatibility with existing analyzer-level tests while streamlining the process for adding new terminology-level tests.

This pull request was created as a result of the following prompt from Copilot chat.

Objective

Refactor the DslTerminologyAnalyzer into two parts to simplify testing and improve maintainability. The two components should be:

  1. Parsing Component: Responsible for parsing out symbols (e.g., variable names, field names, property names, etc.).
  2. Validation Component: Ensures the parsed symbols match the rules provided by the DSL XML.

Background & Context

Currently, Microsoft analyzer-level tests are used to validate the behavior of DslTerminologyAnalyzer. Although useful, such tests introduce unnecessary overhead and visual noise. A more structured approach would enable:

  1. Maintaining existing analyzer-level tests (already completed).
  2. Introducing terminology-level tests that focus on problematic keyword scenarios (e.g., handling keywords like Metadata, MetaData, Filename, FileName, etc.). This facilitates more modular and faster testing.

Key Deliverables

  • Refactor the existing DslTerminologyAnalyzer into two distinguishable components: a Parsing Component and a Validation Component.
  • Implement the necessary interfaces or plumbing to ensure these components can work together seamlessly.
  • Add terminology-level unit tests to ensure:
    • Symbols are parsed correctly.
    • Rules are applied appropriately to the parsed symbols.

This refactor should maintain backward compatibility with existing analyzer-level tests while streamlining the process for adding new terminology-level tests.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI self-assigned this Nov 27, 2025
@Pressacco

Copy link
Copy Markdown
Member

Implements:
#4

@Pressacco

Copy link
Copy Markdown
Member

@copilot please don't over engineer this. The intent is to find a balance between:

  • readability
  • testability
  • and having a manageable number of classes

Copilot AI and others added 3 commits November 27, 2025 00:44
…components

- Add TerminologyRule model class to represent a single rule
- Add DslRuleParser for parsing DSL XML configuration
- Add TerminologyValidator for validating identifiers against rules
- Add ValidationResult to represent validation outcomes
- Update DslTerminologyAnalyzer to use the new components
- Add terminology-level unit tests for DslRuleParser (19 tests)
- Add terminology-level unit tests for TerminologyValidator (21 tests)

Co-authored-by: Pressacco <5507864+Pressacco@users.noreply.github.com>
- Remove ValidationResult class to reduce complexity
- Change Validate() to GetViolation() returning null for valid, or the violated rule
- Update DslTerminologyAnalyzer to use simplified API
- Update tests to use GetViolation() method

Co-authored-by: Pressacco <5507864+Pressacco@users.noreply.github.com>
Co-authored-by: Pressacco <5507864+Pressacco@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor DslTerminologyAnalyzer into parsing and validation components Refactor DslTerminologyAnalyzer into parsing and validation components Nov 27, 2025
Copilot AI requested a review from Pressacco November 27, 2025 00:54

Copilot AI commented Nov 27, 2025

Copy link
Copy Markdown
Contributor Author

@copilot please don't over engineer this. The intent is to find a balance between:

  • readability
  • testability
    ...

Addressed in 8576bb2. Simplified to just 3 classes: TerminologyRule (data model), DslRuleParser (static parser), and TerminologyValidator (with simple GetViolation() returning null or the violated rule). Removed the ValidationResult class to reduce complexity.

@Pressacco Pressacco marked this pull request as ready for review November 27, 2025 00:57
@Pressacco Pressacco merged commit 75f9c58 into main Nov 27, 2025
1 check passed
@Pressacco Pressacco deleted the copilot/refactor-dsl-terminology-analyzer branch November 27, 2025 00:57
@Pressacco

Copy link
Copy Markdown
Member

Implements:

#4

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.

2 participants