"""jinja_template_no_tabs_rule.py - Rule class to check the file does not use tabs
                                for indentation.
"""
from __future__ import annotations

import re
from typing import Any

from j2lint.linter.error import LinterError
from j2lint.linter.rule import Rule


class JinjaTemplateNoTabsRule(Rule):
    """Rule class to check the file does not use tabs for indentation."""

    rule_id = "S5"
    description = "Indentation should not use tabulation but 4 spaces"
    short_description = "jinja-statements-no-tabs"
    severity = "LOW"

    regex = re.compile(r"\t+")

    def __init__(self, ignore: bool = False, warn: list[Any] | None = None) -> None:
        super().__init__()

    def checktext(self, filename: str, text: str) -> list[LinterError]:
        raise NotImplementedError

    def checkline(self, filename: str, line: str, line_no: int) -> list[LinterError]:
        """Checks if the given line matches the error regex

        Args:
            line (string): a single line from the file

        Returns:
            list[LinterError]: the list of LinterError generated by this rule
        """
        matches = self.regex.search(line)
        return [LinterError(line_no, line, filename, self)] if matches else []
