<commit_before>from vint.ast.node_type import NodeType
from vint.linting.level import Level
from vint.linting.policy.abstract_policy import AbstractPolicy
from vint.linting.policy_registry import register_policy
from vint.ast.plugin.scope_plugin import ExplicityOfScopeVisibility


@register_policy
class ProhibitImplicitScopeVariable(AbstractPolicy):
    def __init__(self):
        super(ProhibitImplicitScopeVariable, self).__init__()
        self.reference = 'Anti-pattern of vimrc (Scope of identifier)'
        self.level = Level.STYLE_PROBLEM


    def listen_node_types(self):
        return [NodeType.IDENTIFIER]


    def is_valid(self, identifier, lint_context):
        """ Whether the identifier has a scope prefix. """

        linter_config = lint_context['config']
        scope_plugin = lint_context['plugins']['scope']
        explicity = scope_plugin.get_explicity_of_scope_visibility(identifier)
        is_autoload = scope_plugin.is_autoload_identifier(identifier)

        try:
            suppress_autoload = linter_config['policies'][self.name]['suppress_autoload']
        except KeyError:
            suppress_autoload = False

        is_valid = (explicity is not ExplicityOfScopeVisibility.IMPLICIT or
                    is_autoload and suppress_autoload)

        if not is_valid:
            self._make_description(identifier, scope_plugin)

        return is_valid


    def _make_description(self, identifier, scope_plugin):
        self.description = 'Make the scope explicit like `{good_example}`'.format(
            good_example=scope_plugin.normalize_variable_name(identifier)
        )
<commit_msg>Replace try..except with get_policy_option call<commit_after>from vint.ast.node_type import NodeType
from vint.linting.level import Level
from vint.linting.policy.abstract_policy import AbstractPolicy
from vint.linting.policy_registry import register_policy
from vint.ast.plugin.scope_plugin import ExplicityOfScopeVisibility


@register_policy
class ProhibitImplicitScopeVariable(AbstractPolicy):
    def __init__(self):
        super(ProhibitImplicitScopeVariable, self).__init__()
        self.reference = 'Anti-pattern of vimrc (Scope of identifier)'
        self.level = Level.STYLE_PROBLEM


    def listen_node_types(self):
        return [NodeType.IDENTIFIER]


    def is_valid(self, identifier, lint_context):
        """ Whether the identifier has a scope prefix. """

        scope_plugin = lint_context['plugins']['scope']
        explicity = scope_plugin.get_explicity_of_scope_visibility(identifier)
        is_autoload = scope_plugin.is_autoload_identifier(identifier)

        config_dict = lint_context['config']
        suppress_autoload = self.get_policy_option(config_dict, 'suppress_autoload', False)

        is_valid = (explicity is not ExplicityOfScopeVisibility.IMPLICIT or
                    is_autoload and suppress_autoload)

        if not is_valid:
            self._make_description(identifier, scope_plugin)

        return is_valid


    def _make_description(self, identifier, scope_plugin):
        self.description = 'Make the scope explicit like `{good_example}`'.format(
            good_example=scope_plugin.normalize_variable_name(identifier)
        )

{'fraction_non_alphanumeric': 0.0739480198019802, 'fraction_numerical': 0.0, 'mean_word_length': 3.6923076923076925, 'pattern_counts': {'":': 0, '<': 3, '<?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': '10766', 'n_tokens_mistral': 928, 'n_tokens_neox': 900, 'n_words': 189}