This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
DevSkimConditionals.py
57 lines (45 loc) · 1.79 KB
/
DevSkimConditionals.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""
Copyright (c) 2017 Microsoft. All rights reserved.
Licensed under the MIT License. See LICENSE.txt in the project root for license information.
DevSkim Sublime Text Plugin
https://github.com/Microsoft/DevSkim-Sublime-Plugin
"""
import logging
try:
import sublime
except Exception:
print("Unable to import Sublime Text modules. DevSkim must be run within Sublime Text.")
import sys
sys.exit(1)
logger = logging.getLogger()
def condition__line_match_all(**kwargs):
"""Are all elements of targets substrings of line?"""
line = kwargs.get('line')
targets = kwargs.get('value')
logger.debug('condition__line_match_all({%s}, {%s})', line, targets)
line = line.lower()
return all([t.lower() in line for t in targets])
def condition__line_match_any(**kwargs):
"""Are any elements of value substrings of line?"""
line = kwargs.get('line')
targets = kwargs.get('value')
logger.debug('condition__line_match_any({%s}, {%s})', line, targets)
line = line.lower()
return any([t.lower() in line for t in targets])
def condition__line_match_none(**kwargs):
"""Are none of the elements of targets substrings of line?"""
line = kwargs.get('line')
targets = kwargs.get('value')
logger.debug('condition__line_match_any({%s}, {%s})', line, targets)
return not condition__line_match_any(**kwargs)
def condition__match_prefix_any(**kwargs):
"""Are any of the targets a prefix to the matched region?"""
match_start = kwargs.get('match_start')
targets = kwargs.get('value')
view = kwargs.get('view')
match_region = kwargs.get('match_region')
for target in targets:
region = sublime.Region(match_region.a - len(target), match_start)
if view.substr(region).lower() == target.lower():
return True
return False