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

Bump: Requirements #73

Merged
merged 1 commit into from
Sep 5, 2023
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
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repos:
- id: check-merge-conflict

- repo: https://github.com/pycqa/flake8
rev: 4.0.1
rev: 6.1.0
hooks:
- id: flake8
name: Check for PEP8 error on Python files
Expand Down Expand Up @@ -42,13 +42,13 @@ repos:
name: Check for changes when running isort on all python files

- repo: https://github.com/psf/black
rev: 23.3.0
rev: 23.7.0
hooks:
- id: black
name: Check for changes when running Black on all python files

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.991
rev: v1.5.1
hooks:
- id: mypy
args:
Expand Down
59 changes: 22 additions & 37 deletions j2lint/linter/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from __future__ import annotations

import json
from abc import ABC, abstractclassmethod, abstractmethod
from typing import Any
from abc import ABC, abstractmethod
from typing import Any, ClassVar, Literal

from rich.text import Text

Expand All @@ -19,6 +19,11 @@ class Rule(ABC):
functions.
"""

rule_id: ClassVar[str]
short_description: ClassVar[str]
description: ClassVar[str]
severity: ClassVar[Literal[None, "LOW", "MEDIUM", "HIGH"]]

def __init__(
self,
ignore: bool = False,
Expand All @@ -29,44 +34,24 @@ def __init__(
self.warn = warn if warn is not None else []
self.origin = origin

# Mandatory class attributes

# ignoring mypy issue as the BDFL said
# https://github.com/python/mypy/issues/1362
@property # type: ignore
@abstractclassmethod
def rule_id(cls) -> str: # sourcery skip: instance-method-first-arg-name
"""
The rule id like S0
"""

@property # type: ignore
@abstractclassmethod
def description(cls) -> str: # sourcery skip: instance-method-first-arg-name
"""
The rule description
"""

@property # type: ignore
@abstractclassmethod
def short_description(cls) -> str:
# sourcery skip: instance-method-first-arg-name
"""
The rule short_description
"""

@property # type: ignore
@abstractclassmethod
def severity(cls) -> str: # sourcery skip: instance-method-first-arg-name
"""
The rule severity
"""

def __init_subclass__(cls, *args: Any, **kwargs: Any) -> None:
super().__init_subclass__(**kwargs)
if cls.severity not in [None, "LOW", "MEDIUM", "HIGH"]:
# Mandatory class attributes
mandatory_attributes = [
"rule_id", # Like S0
"description",
"short_description",
"severity",
]
for attr in mandatory_attributes:
if not hasattr(cls, attr):
raise NotImplementedError(
f"Class {cls} is missing required class attribute {attr}"
)

if cls.severity not in ["LOW", "MEDIUM", "HIGH"]:
raise JinjaLinterError(
f"Rule {cls.rule_id}: severity must be in [None, 'LOW', 'MEDIUM', 'HIGH'], {cls.severity} was provided"
f"Rule {cls.rule_id}: severity must be in ['LOW', 'MEDIUM', 'HIGH'], {cls.severity} was provided"
)

def __repr__(self) -> str:
Expand Down
19 changes: 10 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,28 @@ classifiers = [
keywords = ["j2lint", "linter", "jinja", "lint"]
dependencies = [
"jinja2>=3.0",
"rich>=12.4.4",
"rich~=13.5.2",
]
requires-python = ">=3.8"

[project.optional-dependencies]
dev = [
"pre-commit",
"bumpver",
"pre-commit>=3.3.3",
"bumpver==2023.1126",
"tox>=4.10.0,<5.0.0",
]
test = [
"pytest",
"pytest-cov",
"pytest>=7.4.0",
"pytest-cov>=4.1.0",
]
lint = [
"black>=23.3.0",
"black>=23.7.0",
"isort[colors]>=5.12.0",
"pylint>=2.15.9",
"flake8>=4.0.1",
"pylint>=2.17.5",
"flake8==6.1.0",
]
type = [
"mypy==0.991",
"mypy==1.5.1",
]

[project.urls]
Expand Down