Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change some files to match the rest of the project #3310

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions docs/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,9 @@ The following **208** rules are applied by this linter:

| Rule ID | Title | Description | Config<br />(Name:Type:Default) | Source | Tags |
| -------- | ----- | ----------- | ---------- | ------ | ---- |
| [E0000<a name="E0000"></a>](../src/cfnlint/rules/ParseError.py) | Parsing error found when parsing the template | Checks for JSON/YAML formatting errors in your template | | [Source](https://github.com/aws-cloudformation/cfn-python-lint) | `base` |
| [E0001<a name="E0001"></a>](../src/cfnlint/rules/TransformError.py) | Error found when transforming the template | Errors found when performing transformation on the template | | [Source](https://github.com/aws-cloudformation/cfn-python-lint) | `base`,`transform` |
| [E0002<a name="E0002"></a>](../src/cfnlint/rules/RuleError.py) | Error processing rule on the template | Errors found when processing a rule on the template | | [Source](https://github.com/aws-cloudformation/cfn-python-lint) | `base`,`rule` |
| [E0000<a name="E0000"></a>](../src/cfnlint/rules/ParseError.py) | Parsing error found when parsing the template | Checks for JSON/YAML formatting errors in your template | | [Source](https://github.com/aws-cloudformation/cfn-python-lint) | `base` |
| [E0001<a name="E0001"></a>](../src/cfnlint/rules/TransformError.py) | Error found when transforming the template | Errors found when performing transformation on the template | | [Source](https://github.com/aws-cloudformation/cfn-python-lint) | `base`,`transform` |
| [E0002<a name="E0002"></a>](../src/cfnlint/rules/RuleError.py) | Error processing rule on the template | Errors found when processing a rule on the template | | [Source](https://github.com/aws-cloudformation/cfn-python-lint) | `base`,`rule` |
| [E0000<a name="E0000"></a>](../src/cfnlint/rules/errors/parse.py) | Parsing error found when parsing the template | Checks for JSON/YAML formatting errors in your template | | [Source](https://github.com/aws-cloudformation/cfn-python-lint) | `base` |
| [E0001<a name="E0001"></a>](../src/cfnlint/rules/errors/transform.py) | Error found when transforming the template | Errors found when performing transformation on the template | | [Source](https://github.com/aws-cloudformation/cfn-python-lint) | `base`,`transform` |
| [E0002<a name="E0002"></a>](../src/cfnlint/rules/errors/rule.py) | Error processing rule on the template | Errors found when processing a rule on the template | | [Source](https://github.com/aws-cloudformation/cfn-python-lint) | `base`,`rule` |
| [E1001<a name="E1001"></a>](../src/cfnlint/rules/jsonschema/JsonSchema.py) | Basic CloudFormation Template Configuration | Making sure the basic CloudFormation template components are properly configured | sections:string: | [Source](https://github.com/aws-cloudformation/cfn-python-lint) | `base` |
| [E1002<a name="E1002"></a>](../src/cfnlint/rules/templates/LimitSize.py) | Validate if a template size is too large | Check the size of the template is less than the upper limit | | [Source](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cloudformation-limits.html) | `limits` |
| [E1003<a name="E1003"></a>](../src/cfnlint/rules/templates/LimitDescription.py) | Validate the max size of a description | Check if the size of the template description is less than the upper limit | | [Source](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cloudformation-limits.html) | `description`,`limits` |
Expand Down
6 changes: 2 additions & 4 deletions src/cfnlint/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
SPDX-License-Identifier: MIT-0
"""

from __future__ import annotations

from typing import TYPE_CHECKING, Any, List, Protocol, Union

if TYPE_CHECKING:
from cfnlint.rules._Rule import RuleMatch
from cfnlint.rules import RuleMatch

RuleMatches = List["RuleMatch"]
Path = List[Union[str, int]]


class CheckValueFn(Protocol):
def __call__(self, value: Any, path: Path, **kwargs: Any) -> list[RuleMatch]: ...
def __call__(self, value: Any, path: Path, **kwargs: Any) -> List["RuleMatch"]: ...
8 changes: 4 additions & 4 deletions src/cfnlint/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
def lint(
s: str,
rules: RulesCollection | None = None,
regions: List[str] | None = None,
regions: list[str] | None = None,
config: ManualArgs | None = None,
) -> List[Match]:
) -> list[Match]:
"""Validate a string template using the specified rules and regions.

Parameters
Expand All @@ -30,7 +30,7 @@ def lint(
the template string
rules : RulesCollection
The rules to run against s
regions : List[str]
regions : list[str]
The regions to test against s

Returns
Expand Down Expand Up @@ -64,7 +64,7 @@ def lint(
return list(runner.validate_template(None, template))


def lint_all(s: str) -> List[Match]:
def lint_all(s: str) -> list[Match]:
"""Validate a string template against all regions and rules.

Parameters
Expand Down
64 changes: 32 additions & 32 deletions src/cfnlint/conditions/_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
SPDX-License-Identifier: MIT-0
"""

from typing import Any, Dict, List, Mapping, Optional, Sequence, Union
from __future__ import annotations

from typing import Any, Dict, Mapping, Sequence, Union

from sympy import And, Not, Or, Symbol
from sympy.logic.boolalg import BooleanFunction
Expand All @@ -19,13 +21,13 @@ class Condition:
"""The generic class to represent any type of Condition"""

def __init__(self) -> None:
self._fn_equals: Optional[Equal] = None
self._condition: Optional[Union[ConditionList, ConditionNamed]] = None
self._fn_equals: Equal | None = None
self._condition: ConditionList | ConditionNamed | None = None

def _init_condition(
self,
condition: _CONDITION,
all_conditions: Dict[str, dict],
all_conditions: dict[str, dict],
) -> None:
if len(condition) == 1:
for k, v in condition.items():
Expand All @@ -50,13 +52,13 @@ def _init_condition(
raise ValueError("Condition value must be an object of length 1")

@property
def equals(self) -> List[Equal]:
def equals(self) -> list[Equal]:
"""Returns a Sequence of the Equals that make up the Condition

Args: None

Returns:
Union[Sequence[EqualParameter], Sequence[Equal]]:
Sequence[EqualParameter] | Sequence[Equal] | None:
The Equal that are part of the condition
"""
if self._fn_equals:
Expand All @@ -65,13 +67,11 @@ def equals(self) -> List[Equal]:
return self._condition.equals
return []

def build_cnf(
self, params: Dict[str, Symbol]
) -> Optional[Union[BooleanFunction, Symbol]]:
def build_cnf(self, params: dict[str, Symbol]) -> BooleanFunction | Symbol | None:
"""Build a SymPy CNF based on the provided params

Args:
params Dict[str, Symbol]: params is a dict that represents
params dict[str, Symbol]: params is a dict that represents
the hash of an Equal and the SymPy Symbols

Returns:
Expand All @@ -98,24 +98,24 @@ class ConditionList(Condition):
"""

def __init__(
self, conditions: Sequence[_CONDITION], all_conditions: Dict[str, dict]
self, conditions: Sequence[_CONDITION], all_conditions: dict[str, dict]
) -> None:
super().__init__()
self._conditions: List[ConditionUnnammed] = []
self._conditions: list[ConditionUnnammed] = []
self._prefix_path: str = ""
for condition in conditions:
self._conditions.append(ConditionUnnammed(condition, all_conditions))

@property
def equals(self) -> List[Equal]:
def equals(self) -> list[Equal]:
"""Returns a List of the Equals that make up the Condition

Args: None

Returns:
List[Equal]: The Equal that are part of the condition
list[Equal]: The Equal that are part of the condition
"""
equals: List[Equal] = []
equals: list[Equal] = []
for condition in self._conditions:
equals.extend(condition.equals)
return equals
Expand All @@ -125,20 +125,20 @@ class ConditionAnd(ConditionList):
"""Represents the logic specific to an And Condition"""

def __init__(
self, conditions: Sequence[_CONDITION], all_conditions: Dict[str, dict]
self, conditions: Sequence[_CONDITION], all_conditions: dict[str, dict]
) -> None:
super().__init__(conditions, all_conditions)
self._prefix_path = "Fn::And"

def build_cnf(self, params: Dict[str, Symbol]) -> BooleanFunction:
def build_cnf(self, params: dict[str, Symbol]) -> BooleanFunction:
"""Build a SymPy CNF solver based on the provided params
Args:
params Dict[str, Symbol]: params is a dict that represents
params dict[str, Symbol]: params is a dict that represents
the hash of an Equal and the SymPy Symbols
Returns:
BooleanFunction: An And SymPy BooleanFunction
"""
conditions: List[Any] = []
conditions: list[Any] = []
for child in self._conditions:
conditions.append(child.build_cnf(params))

Expand All @@ -153,17 +153,17 @@ class ConditionNot(ConditionList):
"""Represents the logic specific to an Not Condition"""

def __init__(
self, conditions: Sequence[_CONDITION], all_conditions: Dict[str, dict]
self, conditions: Sequence[_CONDITION], all_conditions: dict[str, dict]
) -> None:
super().__init__(conditions, all_conditions)
self._prefix_path = "Fn::Not"
if len(conditions) != 1:
raise ValueError("Condition length must be 1")

def build_cnf(self, params: Dict[str, Symbol]) -> BooleanFunction:
def build_cnf(self, params: dict[str, Symbol]) -> BooleanFunction:
"""Build a SymPy CNF solver based on the provided params
Args:
params Dict[str, Symbol]: params is a dict that represents
params dict[str, Symbol]: params is a dict that represents
the hash of an Equal and the SymPy Symbol
Returns:
BooleanFunction: A Not SymPy BooleanFunction
Expand All @@ -179,20 +179,20 @@ class ConditionOr(ConditionList):
"""Represents the logic specific to an Or Condition"""

def __init__(
self, conditions: Sequence[_CONDITION], all_conditions: Dict[str, dict]
self, conditions: Sequence[_CONDITION], all_conditions: dict[str, dict]
) -> None:
super().__init__(conditions, all_conditions)
self._prefix_path = "Fn::Or"

def build_cnf(self, params: Dict[str, Symbol]) -> BooleanFunction:
def build_cnf(self, params: dict[str, Symbol]) -> BooleanFunction:
"""Build a SymPy CNF solver based on the provided params
Args:
params Dict[str, Symbol]: params is a dict that represents
params dict[str, Symbol]: params is a dict that represents
the hash of an Equal and the SymPy Symbols
Returns:
BooleanFunction: An Or SymPy BooleanFunction
"""
conditions: List[Any] = []
conditions: list[Any] = []
for child in self._conditions:
conditions.append(child.build_cnf(params))
return Or(*conditions)
Expand All @@ -205,7 +205,7 @@ def _test(self, scenarios: Mapping[str, str]) -> bool:
class ConditionUnnammed(Condition):
"""Represents an unnamed condition which is basically a nested Equals"""

def __init__(self, condition: Any, all_conditions: Dict[str, dict]) -> None:
def __init__(self, condition: Any, all_conditions: dict[str, dict]) -> None:
super().__init__()
if isinstance(condition, dict):
self._init_condition(condition, all_conditions)
Expand All @@ -216,7 +216,7 @@ def __init__(self, condition: Any, all_conditions: Dict[str, dict]) -> None:
class ConditionNamed(Condition):
"""The parent condition that directly represents a named condition in a template"""

def __init__(self, name: str, all_conditions: Dict[str, dict]) -> None:
def __init__(self, name: str, all_conditions: dict[str, dict]) -> None:
super().__init__()
condition = all_conditions.get(name)
if isinstance(condition, dict):
Expand All @@ -225,20 +225,20 @@ def __init__(self, name: str, all_conditions: Dict[str, dict]) -> None:
else:
raise ValueError(f"Condition {name} must have a value that is an object")

def build_true_cnf(self, params: Dict[str, Symbol]) -> Any:
def build_true_cnf(self, params: dict[str, Symbol]) -> Any:
"""Build a SymPy CNF for a True based scenario
Args:
params Dict[str, Symbol]: params is a dict that represents
params dict[str, Symbol]: params is a dict that represents
the hash of an Equal and the SymPy Symbols
Returns:
Any: A SymPy CNF clause
"""
return self.build_cnf(params)

def build_false_cnf(self, params: Dict[str, Symbol]) -> Any:
def build_false_cnf(self, params: dict[str, Symbol]) -> Any:
"""Build a SymPy CNF for a False based scenario
Args:
params Dict[str, Symbol]: params is a dict that represents
params dict[str, Symbol]: params is a dict that represents
the hash of an Equal and the SymPy CNF Symbols
Returns:
Any: A Not SymPy CNF clause
Expand Down
24 changes: 12 additions & 12 deletions src/cfnlint/conditions/_equals.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
SPDX-License-Identifier: MIT-0
"""

from __future__ import annotations

import json
import logging
from typing import Any, Dict, List, Mapping, Tuple, Union
from typing import Any, Mapping, Tuple

from cfnlint.conditions._utils import get_hash

Expand All @@ -28,12 +30,12 @@ def __eq__(self, __o: Any):

class Equal:
hash: str
_left: Union[EqualParameter, str]
_right: Union[EqualParameter, str]
_is_static: Union[bool, None]
_left: EqualParameter | str
_right: EqualParameter | str
_is_static: bool | None
_is_region: Tuple[bool, str]

def __init__(self, equal: List[Union[str, dict]]) -> None:
def __init__(self, equal: list[str | dict]) -> None:
self._is_static = None
if isinstance(equal, list) and len(equal) == 2:
# sort to keep consistancy from random ordering
Expand Down Expand Up @@ -63,34 +65,32 @@ def __init__(self, equal: List[Union[str, dict]]) -> None:
return
raise ValueError("Equals has to be a list of two values")

def _init_parameter(
self, parameter: Union[Dict, str]
) -> Union[EqualParameter, str]:
def _init_parameter(self, parameter: dict[str, Any] | str) -> EqualParameter | str:
if isinstance(parameter, dict):
return EqualParameter(parameter)
return str(parameter)

@property
def is_static(self) -> Union[bool, None]:
def is_static(self) -> bool | None:
"""Returns a boolean value if the result is always True or False or None if
it isn't a static boolean

Args: None

Returns:
Union[bool, None]: None if the equals can be True or False or True/False if
bool | None: None if the equals can be True or False or True/False if
the equals will always return the same result
"""
return self._is_static

@property
def parameters(self) -> List[EqualParameter]:
def parameters(self) -> list[EqualParameter]:
"""Returns a List of the EqualParameter that make up the Condition

Args: None

Returns:
List[Equal]: A list of the left and right equal parameters if they are
list[Equal]: A list of the left and right equal parameters if they are
of type EqualParameter
"""
params = []
Expand Down
Loading
Loading