Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow set encoding= in new files if a previous file used scriptencoding #364

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions vint/linting/policy/prohibit_abbreviation_option.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ class ProhibitAbbreviationOption(AbstractPolicy):
reference = ':help option-summary'
level = Level.STYLE_PROBLEM

was_scriptencoding_found = False
has_encoding_opt_after_scriptencoding = False


def listen_node_types(self):
return [NodeType.EXCMD, NodeType.OPTION]
Expand Down
15 changes: 11 additions & 4 deletions vint/linting/policy/prohibit_encoding_opt_after_scriptencoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,27 @@ class ProhibitEncodingOptionAfterScriptEncoding(AbstractPolicy):
level = Level.WARNING

was_scriptencoding_found = False
has_encoding_opt_after_scriptencoding = False


def listen_node_types(self):
return [NodeType.EXCMD]
return [NodeType.EXCMD, NodeType.TOPLEVEL]


def is_valid(self, excmd_node, lint_context):
def is_valid(self, node, lint_context):
""" Whether the specified node is valid.

This policy prohibits encoding option after scriptencoding.
"""

cmd_str = excmd_node['str']
node_type = NodeType(node['type'])

if node_type is NodeType.TOPLEVEL:
self.was_scriptencoding_found = False
return True

assert node_type is NodeType.EXCMD

cmd_str = node['str']

if re.match(r':*scripte', cmd_str):
self.was_scriptencoding_found = True
Expand Down