def check(self, _file, stash):
     res = []
     items = stash.GetItemsFor(filename=_file, classifier=Variable.CLASSIFIER,
                               attribute=Variable.ATTR_VAR)
     _all = stash.GetItemsFor(filename=_file)
     for i in items:
         _cleanvarname = i.VarName
         for pkg in get_valid_package_names(stash, _file, strippn=True):
             if not pkg:
                 continue  # pragma: no cover
             if _cleanvarname.endswith(pkg):
                 _cleanvarname = ''.join(
                     _cleanvarname.rsplit(pkg, 1))  # pragma: no cover
         if _cleanvarname in CONSTANTS.VariablesKnown:
             continue
         _used = False
         for a in _all:
             if a == i:
                 continue
             if '${{{a}}}'.format(a=i.VarName) in a.Raw or 'getVar("{a}"'.format(a=i.VarName) in a.Raw:
                 _used = True
                 break
         if _used:
             continue
         _bestmatch = self.get_best_match(
             _cleanvarname, CONSTANTS.VariablesKnown)
         if _bestmatch:
             res += self.finding(i.Origin, i.InFileLine,
                                 '\'{a}\' is unknown, maybe you meant \'{b}\''.format(
                                     a=_cleanvarname, b=_bestmatch))
     return res
Beispiel #2
0
    def check(self, _file, stash):
        res = []

        if self.is_lone_append(stash, _file):
            return res

        _packages = list(get_valid_package_names(stash, _file))
        items = stash.GetItemsFor(filename=_file,
                                  classifier=Variable.CLASSIFIER)
        for i in items:
            if i.VarName == 'inherit':
                continue
            if i.VarName in self.needles:
                _machine = []
                if i.GetMachineEntry():
                    _machine = [
                        i.GetMachineEntry(),
                        expand_term(stash, _file, i.GetMachineEntry())
                    ]
                if not _machine or not any(x in _packages for x in _machine):
                    res += self.finding(i.Origin,
                                        i.InFileLine,
                                        override_msg=self.Msg.replace(
                                            '{VAR}', i.VarName),
                                        appendix=i.VarName)
        return res
 def check(self, _file, stash):
     res = []
     items = stash.GetItemsFor(filename=_file,
                               classifier=Variable.CLASSIFIER,
                               attribute=Variable.ATTR_VAR)
     _all = stash.GetItemsFor(filename=_file)
     for i in items:
         _cleanvarname = i.VarName
         for pkg in get_valid_package_names(stash, _file, strippn=True):
             if not pkg:
                 continue
             if _cleanvarname.endswith(pkg):
                 _cleanvarname = ''.join(_cleanvarname.rsplit(pkg, 1))
         if _cleanvarname in get_known_vars():
             continue
         _used = False
         for a in _all:
             if a == i:
                 continue
             if "${{{}}}".format(
                     i.VarName) in a.Raw or "getVar(\"{}\"".format(
                         i.VarName) in a.Raw:
                 _used = True
                 break
         if _used:
             continue
         _bestmatch = self.get_best_match(_cleanvarname, get_known_vars())
         if _bestmatch:
             res += self.finding(
                 i.Origin, i.InFileLine,
                 "'{}' is unknown, maybe you mean '{}'".format(
                     _cleanvarname, _bestmatch))
     return res
Beispiel #4
0
 def check(self, _file, stash):
     res = []
     items = stash.GetItemsFor(filename=_file,
                               classifier=Variable.CLASSIFIER,
                               attribute=Variable.ATTR_VAR)
     _comp = stash.GetItemsFor(filename=_file,
                               classifier=Variable.CLASSIFIER,
                               attribute=Variable.ATTR_VAR,
                               attributeValue="COMPATIBLE_MACHINE")
     _packages = get_valid_package_names(stash, _file)
     _named_res = get_valid_named_resources(stash, _file)
     for i in items:
         _machine = i.GetMachineEntry()
         if not _machine:
             continue
         if _machine in _packages or _machine in _named_res or _machine in get_known_machines(
         ):
             continue
         if _comp and re.match("".join(x.VarValueStripped
                                       for x in _comp), _machine):
             continue
         res += self.finding(i.Origin,
                             i.InFileLine,
                             override_msg=self.Msg.format(
                                 i.VarName, _machine))
     return res
Beispiel #5
0
 def check(self, _file, stash):
     res = []
     items = stash.GetItemsFor(filename=_file,
                               classifier=Function.CLASSIFIER,
                               attribute=Function.ATTR_FUNCNAME)
     _comp = stash.GetItemsFor(filename=_file,
                               classifier=Variable.CLASSIFIER,
                               attribute=Variable.ATTR_VAR,
                               attributeValue="COMPATIBLE_MACHINE")
     _packages = get_valid_package_names(stash, _file)
     _valid_funcs = [
         'pkg_preinst', 'pkg_postinst', 'pkg_prerm', 'pkg_postrm'
     ]
     for b in ['pkg_preinst', 'pkg_postinst', 'pkg_prerm', 'pkg_postrm']:
         _valid_funcs += [
             "{}-{}".format(b, p) for p in _packages
             if p.strip() and p != INLINE_BLOCK
         ]
     for i in items:
         _machine = i.GetMachineEntry()
         if not _machine or _machine in get_known_machines():
             continue
         if i.FuncName in _valid_funcs:
             continue
         if _machine in ["ptest"]:
             # known exceptions
             continue
         if _comp and re.match("".join(x.VarValueStripped
                                       for x in _comp), _machine):
             continue
         res += self.finding(i.Origin,
                             i.InFileLine,
                             override_msg=self.Msg.format(
                                 i.FuncName, _machine))
     return res
Beispiel #6
0
    def check(self, _file, stash):
        res = []
        items = stash.GetItemsFor(filename=_file,
                                  classifier=Variable.CLASSIFIER,
                                  attribute=Variable.ATTR_VAR)
        _comp = stash.GetItemsFor(filename=_file,
                                  classifier=Variable.CLASSIFIER,
                                  attribute=Variable.ATTR_VAR,
                                  attributeValue='COMPATIBLE_MACHINE')
        _comp = ''.join(x.VarValueStripped for x in _comp)
        _packages = get_valid_package_names(stash, _file)
        _named_res = get_valid_named_resources(stash, _file)
        for i in items:
            _distro = []
            if i.GetDistroEntry():
                _distro = [
                    i.GetDistroEntry(),
                    expand_term(stash, _file, i.GetDistroEntry())
                ]
            if any(x in _packages for x in _distro) or any(
                    x in _named_res for x in _distro):  # pragma: no cover
                continue  # pragma: no cover
            if any(x in CONSTANTS.DistrosKnown for x in _distro):
                continue

            _machine = []
            if i.GetMachineEntry():
                _machine = [
                    i.GetMachineEntry(),
                    expand_term(stash, _file, i.GetMachineEntry())
                ]
            if not _machine:
                continue
            if any(x in _packages for x in _machine):
                continue
            if any(x in _named_res for x in _machine):
                continue
            if any(x in CONSTANTS.MachinesKnown for x in _machine):
                continue
            if _comp:
                if any(re.match(_comp, x) for x in _machine):
                    continue
            res += self.finding(i.Origin,
                                i.InFileLine,
                                override_msg=self.Msg.format(a=i.VarName,
                                                             b=_machine[0]))
        return res
    def check(self, _file, stash):
        res = []

        _packages = get_valid_package_names(stash, _file)
        items = stash.GetItemsFor(filename=_file,
                                  classifier=Variable.CLASSIFIER)
        for i in items:
            if i.VarName == "inherit":
                continue
            if i.VarName in self.needles:
                _machine = i.GetMachineEntry()
                if not _machine or _machine not in _packages:
                    res += self.finding(i.Origin,
                                        i.InFileLine,
                                        override_msg=self.Msg.replace(
                                            "{VAR}", i.VarName),
                                        appendix=i.VarName)
        return res
Beispiel #8
0
    def check(self, _file, stash):
        res = []
        items = stash.GetItemsFor(filename=_file,
                                  classifier=Function.CLASSIFIER,
                                  attribute=Function.ATTR_FUNCNAME)
        _comp = stash.GetItemsFor(filename=_file,
                                  classifier=Variable.CLASSIFIER,
                                  attribute=Variable.ATTR_VAR,
                                  attributeValue='COMPATIBLE_MACHINE')
        _packages = get_valid_package_names(stash, _file)
        _valid_funcs = [
            'pkg_preinst', 'pkg_postinst', 'pkg_prerm', 'pkg_postrm'
        ]
        for b in ['pkg_preinst', 'pkg_postinst', 'pkg_prerm', 'pkg_postrm']:
            _valid_funcs += [
                '{a}-{b}'.format(a=b, b=p) for p in _packages
                if p.strip() and p != INLINE_BLOCK
            ]
        for i in items:
            _distro = i.GetDistroEntry()
            if _distro in CONSTANTS.DistrosKnown:
                continue

            _machine = i.GetMachineEntry()
            if not _machine or _machine in CONSTANTS.MachinesKnown:
                continue
            if i.FuncName in _valid_funcs:
                continue
            if _machine in ['ptest']:
                # known exceptions
                continue
            if _comp and re.match(''.join(x.VarValueStripped
                                          for x in _comp), _machine):
                continue
            res += self.finding(i.Origin,
                                i.InFileLine,
                                override_msg=self.Msg.format(func=i.FuncName,
                                                             machine=_machine,
                                                             distro=_distro))
        return res