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)
        )

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)
        )

Replace try..except with get_policy_option call
Replace try..except with get_policy_option call

  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)
  
+         config_dict = lint_context['config']
+         suppress_autoload = self.get_policy_option(config_dict, 'suppress_autoload', False)
-         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)
          )
  
Replace try..except with get_policy_option call
## Code 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)
        )

## Instruction:
Replace try..except with get_policy_option call
## Code 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)
        )
