Skip to content

Commit 6f5f41f

Browse files
committed
Allow set encoding= in new files if a previous file used scriptencoding
1 parent 5b05880 commit 6f5f41f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

vint/linting/policy/prohibit_encoding_opt_after_scriptencoding.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,25 @@ class ProhibitEncodingOptionAfterScriptEncoding(AbstractPolicy):
1212
level = Level.WARNING
1313

1414
was_scriptencoding_found = False
15-
has_encoding_opt_after_scriptencoding = False
1615

1716

1817
def listen_node_types(self):
19-
return [NodeType.EXCMD]
18+
return [NodeType.EXCMD, NodeType.TOPLEVEL]
2019

2120

22-
def is_valid(self, excmd_node, lint_context):
21+
def is_valid(self, node, lint_context):
2322
""" Whether the specified node is valid.
2423
2524
This policy prohibits encoding option after scriptencoding.
2625
"""
2726

28-
cmd_str = excmd_node['str']
27+
if node['type'] == NodeType.TOPLEVEL.value:
28+
self.was_scriptencoding_found = False
29+
return True
30+
31+
assert node['type'] == NodeType.EXCMD.value
32+
33+
cmd_str = node['str']
2934

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

0 commit comments

Comments
 (0)