-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
62 lines (52 loc) · 1.8 KB
/
utils.py
File metadata and controls
62 lines (52 loc) · 1.8 KB
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
58
59
60
61
62
import sys, os, sublime, subprocess, shlex;
RUBY_SYNTAX_FILES = [
'Ruby.sublime-syntax',
'Ruby on Rails.sublime-syntax',
'RSpec.sublime-syntax'
]
class Utils(object):
@staticmethod
def get_ruby_executable():
p=subprocess.Popen(" if [ -f $HOME/.rvm/bin/rvm-auto-ruby ]; then echo $HOME/.rvm/bin/rvm-auto-ruby; fi", stdout=subprocess.PIPE, shell=True)
out, err = p.communicate()
return out.decode('utf-8').rstrip()
@staticmethod
def is_ruby_file(settings):
syntax_file = settings.get('syntax')
if syntax_file == None:
return False
for syntax in RUBY_SYNTAX_FILES:
if syntax_file.endswith(syntax):
return True
return False
@staticmethod
def current_project_folder():
project = sublime.active_window().project_data()
project_base_path = os.path.dirname(sublime.active_window().project_file_name() or '')
if not (project is None):
if 'folders' in project:
folders = project['folders']
if len(folders) > 0:
first_folder = folders[0]
if 'path' in first_folder:
path = first_folder['path']
return (path if os.path.isabs(path) else os.path.join(project_base_path, path)) or ''
return ''
@staticmethod
def get_marks(view, offense_dict):
marks = []
for line in offense_dict.keys():
pt = view.text_point(line - 1, 0)
marks.append(view.line(pt))
return marks
@staticmethod
def get_offense_diff(rubocop_offenses, diff_line_numbers):
diff_offenses = {}
for offense in rubocop_offenses:
line = int(offense['location']['line'])
if line in diff_line_numbers:
if diff_offenses.get(line) != None:
diff_offenses[line].append(offense['message'])
else:
diff_offenses[line] = [offense['message']]
return diff_offenses