from oelint_adv.cls_item import Variable
from oelint_adv.cls_rule import Rule


class VarInconSpaces(Rule):
    def __init__(self):
        super().__init__(id="oelint.vars.inconspaces",
                         severity="error",
                         message="<FOO>")

    def check(self, _file, stash):
        res = []
        items = stash.GetItemsFor(filename=_file, classifier=Variable.CLASSIFIER)
        for i in items:
            if " += " in i.Raw and i.VarValueStripped.startswith(" "):
                self.OverrideMsg("Assignment should be 'VAR += \"foo\"' not 'VAR += \" foo\"'")
                res += self.finding(i.Origin, i.InFileLine)
            if "_append " in i.Raw and not i.VarValueStripped.startswith(" "):
                self.OverrideMsg("Assignment should be 'VAR_append = \" foo\"' not 'VAR_append = \"foo\"'")
                res += self.finding(i.Origin, i.InFileLine)
        return res
