diff --git a/chasten/checks.py b/chasten/checks.py index 4b3e5de0..6e1d2b54 100644 --- a/chasten/checks.py +++ b/chasten/checks.py @@ -81,13 +81,13 @@ def check_match_count( if min_value is not None and max_value is not None: return is_in_closed_interval(count, min_value, max_value) # at this point, only one of the values might not be None - # if min_value is not None, then confirm that it is less than or equal + # if min_value is not None, then confirm that it is greater than or equal if min_value is not None: - if count <= min_value: + if count >= min_value: return True - # if max_value is not None, then confirm that it is greater than or equal + # if max_value is not None, then confirm that it is less than or equal if max_value is not None: - if count >= max_value: + if count <= max_value: return True # if none of those conditions were true, then the count is not # between the minimum and the maximum value, inclusively diff --git a/chasten/results.py b/chasten/results.py index fd6eecad..d56b9101 100644 --- a/chasten/results.py +++ b/chasten/results.py @@ -3,10 +3,11 @@ import uuid from datetime import datetime from pathlib import Path -from typing import List, Union +from typing import List, Optional, Union from pyastgrep import search as pyastgrepsearch # type: ignore from pydantic import BaseModel +from pydantic.types import conint from chasten import debug @@ -67,8 +68,8 @@ class Check(BaseModel): id: str name: str description: str = "" - min: Union[None, int] = 0 - max: Union[None, int] = 0 + min: Optional[conint(ge=0)] = 0 # type: ignore + max: Optional[conint(ge=0)] = 0 # type: ignore pattern: str passed: bool matches: list[Match] = [] diff --git a/chasten/validate.py b/chasten/validate.py index f393df64..41f4d739 100644 --- a/chasten/validate.py +++ b/chasten/validate.py @@ -48,19 +48,43 @@ "anyOf": [ { "type": "object", - "properties": {"min": {"type": "integer"}}, + "properties": { + "min": { + "anyOf": [ + {"type": "integer"}, + {"type": "null"}, + ] + } + }, "required": ["min"], }, { "type": "object", - "properties": {"max": {"type": "integer"}}, + "properties": { + "max": { + "anyOf": [ + {"type": "integer"}, + {"type": "null"}, + ] + } + }, "required": ["max"], }, { "type": "object", "properties": { - "min": {"type": "integer"}, - "max": {"type": "integer"}, + "min": { + "anyOf": [ + {"type": "integer"}, + {"type": "null"}, + ] + }, + "max": { + "anyOf": [ + {"type": "integer"}, + {"type": "null"}, + ] + }, }, "required": ["min", "max"], },