vale icon indicating copy to clipboard operation
vale copied to clipboard

Bug Report: Conditional/Occurrence Rules Report False Negatives

Open ww2283 opened this issue 2 months ago • 0 comments

Check for existing issues

  • [x] Completed

Environment

Environment

  • Vale version: 3.12.0
  • Operating system: macOS 15.7.1
  • Installation method: brew install

Describe the bug / provide steps to reproduce it

Bug Description

Conditional and occurrence extension rules report false negatives when checking content that clearly satisfies the rule criteria. The rules correctly detect patterns in isolated test files but fail when applied through .vale.ini configuration sections.

Expected Behavior

Rules should correctly detect patterns present in the content:

  • RequireDataSource (conditional rule): Should PASS when content contains "Using our existing dataset"
  • MethodEmphasis (occurrence rule): Should count 4 keyword matches ("systematic", "method"×2, "analyze")

Actual Behavior

Rules report false negatives:

  • RequireDataSource: Reports ERROR claiming pattern is missing, despite being present in content
  • MethodEmphasis: Reports count=0 or count=1, despite 4 matches being present

Minimal Reproducible Example

1. Vale Configuration (.vale.ini)

StylesPath = tests/styles
MinAlertLevel = warning

[*.md]
BasedOnStyles = Base, TestStyle

2. Conditional Rule (tests/styles/TestStyle/RequireDataSource.yml)

extends: conditional
message: "Section 1 must acknowledge existing dataset. Use phrasing like 'Using our existing dataset'."
level: error
scope: paragraph
first: '\bSection 1:'
second: 'Using our existing dataset'

3. Occurrence Rule (tests/styles/TestStyle/MethodEmphasis.yml)

extends: occurrence
message: "Section 1 should mention 'method', 'analyze', or 'systematic' at least twice (current: %d)"
level: warning
scope: paragraph
ignorecase: true
min: 2
max: 999
tokens:
  - method
  - analyze
  - systematic

4. Test Content (test.md)

**Section 1: Identify and analyze patterns in the dataset.**

Using our existing dataset of approximately 5,000 records, this section will apply and refine a systematic method to analyze key patterns and prioritize the most important findings for further investigation. This method integrates multiple data sources to generate a comprehensive list of actionable insights.

**Deliverable:** A ranked list of 30-50 high-priority findings with supporting evidence.

Steps to Reproduce

  1. Create directory structure:

    test-vale-bug/
    ├── .vale.ini
    ├── test.md
    └── tests/styles/TestStyle/
        ├── RequireDataSource.yml
        └── MethodEmphasis.yml
    
  2. Run Vale:

    vale test.md
    

Actual Output

test.md
 3:1  error    Section 1 must acknowledge existing dataset...  TestStyle.RequireDataSource
 3:1  warning  Section 1 should mention... (current: 0)        TestStyle.MethodEmphasis

✖ 1 error, 1 warning and 0 suggestions in 1 file.

Expected Output

Both rules should pass (no errors/warnings) because:

  1. Line 3 contains "Using our existing dataset" (satisfies RequireDataSource)
  2. Paragraph contains "systematic", "method" (×2), "analyze" = 4 matches (satisfies MethodEmphasis min: 2)

Additional Notes

Manual Verification

Running grep confirms the patterns are present:

$ grep -n "Using our existing dataset" test.md
3:Using our existing dataset of approximately 5,000 records...

$ grep -oiE '(method|analyze|systematic)' test.md | wc -l
4

Pattern Variations Tested

The bug persists across multiple .vale.ini section patterns:

  • [*.md] (simplest extension pattern) ❌
  • [test*.md] (filename pattern) ❌
  • [src/*.md] (path-prefixed pattern) ❌

Working Workaround

Rules work correctly when testing isolated snippets in different directories, suggesting the issue is with how Vale processes files matched through .vale.ini configuration sections when using conditional/occurrence extensions.

Impact

This bug prevents reliable use of conditional and occurrence rules for automated content validation in documentation/writing workflows. Users cannot trust that passing Vale checks means criteria are actually satisfied.

ww2283 avatar Oct 15 '25 14:10 ww2283