Skip to content

Vale has non-deterministic behavior #476

Closed

Description

@mrjerzy

It seems that vale, under certain condition produces a non-deterministic output. It sometimes finds an error, and sometimes not.

I prepared a small repository which allows to reproduce the behaviour

git clone https://github.com/mrjerzy/vale-error.git
cd vale-error
while true; do vale . ; done;

Running vale, sometimes finds an error, and sometimes not.
I run vale version 2.20.0, installed via nix package manager, on macOS Monterey 12.3.1. I can reproduce the same error with the official jdkato/vale Docker images back to image version v2.10.2. Version v2.9.1 does not recognise the .vale.ini syntax anymore.

Overview

I tried to create some style rules, which make sure that a series of words is always written in upper case, and has a dash inbetween.

I tried to define that this-is, this is, this - is will all be marked to be substituted by This-Is.
Further i want to achieve that a 3rd word Unexpected is added with a hyphen and is attached with a dash.

I defined following Rule:

extends: substitution
message: Use '%s' instead of '%s'
level: error
scope: [paragraph, sentence]
ignorecase: false
swap:
  '[tT]his[ -]*[iI]s': This-Is
  'This-Is[ -]*[uU]nexpected': This-Is-Unexpected

Further I added a file containing:

This-Is unexpected

According to the rule it should be substitited for This-Is-Unexpected.

When i run vale multiple time, vale sometimes reports an error, and sometimes not.

Bash Output

> while true; do vale . ; done;

✔ 0 errors, 0 warnings and 0 suggestions in 1 file.

 docs/overview.md
 1:1  error  Use 'This-Is-Unexpected'        Rules.Repositories 
             instead of 'This-Is                                
             unexpected'                                        

✖ 1 error, 0 warnings and 0 suggestions in 1 file.
✔ 0 errors, 0 warnings and 0 suggestions in 1 file.
✔ 0 errors, 0 warnings and 0 suggestions in 1 file.
✔ 0 errors, 0 warnings and 0 suggestions in 1 file.
✔ 0 errors, 0 warnings and 0 suggestions in 1 file.
✔ 0 errors, 0 warnings and 0 suggestions in 1 file.

 docs/overview.md
 1:1  error  Use 'This-Is-Unexpected'        Rules.Repositories 
             instead of 'This-Is                                
             unexpected'                                        

✖ 1 error, 0 warnings and 0 suggestions in 1 file.
✔ 0 errors, 0 warnings and 0 suggestions in 1 file.
✔ 0 errors, 0 warnings and 0 suggestions in 1 file.

 docs/overview.md
 1:1  error  Use 'This-Is-Unexpected'        Rules.Repositories 
             instead of 'This-Is                                
             unexpected'                                        

✖ 1 error, 0 warnings and 0 suggestions in 1 file.
✔ 0 errors, 0 warnings and 0 suggestions in 1 file.
✔ 0 errors, 0 warnings and 0 suggestions in 1 file.

The behaviour of vale is non-deterministic in that case.

I realised that this does not happen if i remove the first substitution rule.

Activity

  1. jdkato commented on Aug 27, 2022

    @jdkato
    Member

    It depends on the order in which the patterns are loaded: If the first one is loaded first, there's no alert since This-Is == This-Is. If the second one is loaded first, then there's an alert.

    The assumption is that once we find a match, we don't need to continue to try patterns. If you have overlapping patterns that should always be evaluated, then you should create two separate .yml files.


    Also, you should only add scope: paragraph or scope: sentence if the rule requires information from that scope (such as sentence length, for example) and they shouldn't be used together (it's just going to result in worse performance).

    In a case like this, the default scope: text is what should be used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions