<commit_before>#!/usr/bin/env python3
from whalelinter.app                import App
from whalelinter.dispatcher         import Dispatcher
from whalelinter.commands.command   import Command
from whalelinter.commands.apt       import Apt


@Dispatcher.register(token='run', command='cd')
class Cd(Command):
    def __init__(self, **kwargs):
        App._collecter.throw(2002, self.line)
        return False


@Dispatcher.register(token='run', command='rm')
class Rm(Command):
    def __init__(self, **kwargs):
        if (
            '-rf' in kwargs.get('args') or
            '-fr' in kwargs.get('args') or
            ('-r' in kwargs.get('args') and '-f' in kwargs.get('args'))
            ) and ('/var/lib/apt/lists' in kwargs.get('args')):

            if (int(Apt._has_been_used) < int(kwargs.get('lineno'))):
                Apt._has_been_used = 0<commit_msg>Enhance flags detection with regex when trying to remove apt cache<commit_after>#!/usr/bin/env python3
import re

from whalelinter.app                import App
from whalelinter.dispatcher         import Dispatcher
from whalelinter.commands.command   import Command
from whalelinter.commands.apt       import Apt


@Dispatcher.register(token='run', command='cd')
class Cd(Command):
    def __init__(self, **kwargs):
        App._collecter.throw(2002, self.line)
        return False


@Dispatcher.register(token='run', command='rm')
class Rm(Command):
    def __init__(self, **kwargs):
        rf_flags_regex    = re.compile("(-.*[rRf].+-?[rRf]|-[rR]f|-f[rR])")
        rf_flags          = True if [i for i in kwargs.get('args') if rf_flags_regex.search(i)] else False
        cache_path_regex  = re.compile("/var/lib/apt/lists(\/\*?)?")
        cache_path        = True if [i for i in kwargs.get('args') if cache_path_regex.search(i)] else False

        if rf_flags and cache_path:
            if (int(Apt._has_been_used) < int(kwargs.get('lineno'))):
                Apt._has_been_used = 0
{'fraction_non_alphanumeric': 0.13789581205311544, 'fraction_numerical': 0.006128702757916241, 'mean_word_length': 2.811284046692607, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '794090', 'n_tokens_mistral': 654, 'n_tokens_neox': 624, 'n_words': 145}