def load_config(self): s = sublime.load_settings(SETTINGS_FILE) use_rvm = s.get('check_for_rvm') use_rbenv = s.get('check_for_rbenv') self.rubocop_command = s.get('rubocop_command') rvm_auto_ruby_path = s.get('rvm_auto_ruby_path') rbenv_path = s.get('rbenv_path') runner = RubocopRunner(use_rbenv, use_rvm, self.rubocop_command, rvm_auto_ruby_path, rbenv_path) self.rubocop_command = runner.command_string() + ' {options} {path}'
class RubocopCommand(sublime_plugin.TextCommand): def run(self, edit): self.load_config() def load_config(self): s = sublime.load_settings(SETTINGS_FILE) cfg_file = s.get('rubocop_config_file') if cfg_file: cfg_file = FileTools.quote(cfg_file) self.runner = RubocopRunner( { 'use_rbenv': s.get('check_for_rbenv'), 'use_rvm': s.get('check_for_rvm'), 'custom_rubocop_cmd': s.get('rubocop_command'), 'rvm_auto_ruby_path': s.get('rvm_auto_ruby_path'), 'rbenv_path': s.get('rbenv_path'), 'on_windows': (sublime.platform() == 'windows'), 'rubocop_config_file': cfg_file } ) def used_options(self): return '' def run_rubocop_on(self, path, file_list=False): if not path: return if not file_list: # Single item to check. quoted_file_path = FileTools.quote(path) working_dir = os.path.dirname(path) else: # Multiple files to check. working_dir = '.' quoted_file_path = '' for file in path: quoted_file_path += FileTools.quote(file) + ' ' rubocop_cmd = self.runner.command_string( quoted_file_path, self.used_options() ) self.run_shell_command(rubocop_cmd, working_dir) def run_shell_command(self, command, working_dir='.'): if not command: return self.view.window().run_command('exec', { 'cmd': [command], 'shell': True, 'working_dir': working_dir, 'file_regex': r"^([^:]+):([0-9]*)", })
class RubocopCommand(sublime_plugin.TextCommand): def run(self, edit): self.load_config() def load_config(self): s = sublime.load_settings(SETTINGS_FILE) use_rvm = s.get('check_for_rvm') use_rbenv = s.get('check_for_rbenv') self.rubocop_command = s.get('rubocop_command') rvm_auto_ruby_path = s.get('rvm_auto_ruby_path') rbenv_path = s.get('rbenv_path') self.runner = RubocopRunner(use_rbenv, use_rvm, self.rubocop_command, rvm_auto_ruby_path, rbenv_path) self.rubocop_command = self.runner.command_string( ) + ' {options} {path}' def used_options(self): return '' def command_with_options(self): return self.rubocop_command.replace('{options}', self.used_options()) def run_rubocop_on(self, path, file_list=False): if not path: return if not file_list: # Single item to check. quoted_file_path = FileTools.quote(path) working_dir = os.path.dirname(quoted_file_path) else: # Multiple files to check. working_dir = '.' quoted_file_path = '' for file in path: quoted_file_path += FileTools.quote(file) + ' ' cop_command = self.command_with_options() rubocop_cmd = cop_command.replace('{path}', quoted_file_path) self.run_shell_command(rubocop_cmd, working_dir) def run_shell_command(self, command, working_dir='.'): if not command: return self.view.window().run_command( 'exec', { 'cmd': [command], 'shell': True, 'working_dir': working_dir, 'file_regex': r"^([^:]+):([0-9]*)", })
class RubocopCommand(sublime_plugin.TextCommand): def run(self, edit): self.load_config() def load_config(self): s = sublime.load_settings(SETTINGS_FILE) use_rvm = s.get('check_for_rvm') use_rbenv = s.get('check_for_rbenv') self.rubocop_command = s.get('rubocop_command') rvm_auto_ruby_path = s.get('rvm_auto_ruby_path') rbenv_path = s.get('rbenv_path') self.runner = RubocopRunner(use_rbenv, use_rvm, self.rubocop_command, rvm_auto_ruby_path, rbenv_path) self.rubocop_command = self.runner.command_string() + ' {options} {path}' def used_options(self): return '' def command_with_options(self): return self.rubocop_command.replace('{options}', self.used_options()) def run_rubocop_on(self, path, file_list=False): if not path: return if not file_list: # Single item to check. quoted_file_path = FileTools.quote(path) working_dir = os.path.dirname(quoted_file_path) else: # Multiple files to check. working_dir = '.' quoted_file_path = '' for file in path: quoted_file_path += FileTools.quote(file) + ' ' cop_command = self.command_with_options() rubocop_cmd = cop_command.replace('{path}', quoted_file_path) self.run_shell_command(rubocop_cmd, working_dir) def run_shell_command(self, command, working_dir='.'): if not command: return self.view.window().run_command('exec', { 'cmd': [command], 'shell': True, 'working_dir': working_dir, 'file_regex': r"^([^:]+):([0-9]*)", })
class RubocopCommand(sublime_plugin.TextCommand): def run(self, edit): self.load_config() def load_config(self): s = sublime.load_settings(SETTINGS_FILE) cfg_file = s.get('rubocop_config_file') if cfg_file: cfg_file = FileTools.quote(cfg_file) self.runner = RubocopRunner({ 'use_rbenv': s.get('check_for_rbenv'), 'use_rvm': s.get('check_for_rvm'), 'custom_rubocop_cmd': s.get('rubocop_command'), 'rvm_auto_ruby_path': s.get('rvm_auto_ruby_path'), 'rbenv_path': s.get('rbenv_path'), 'on_windows': self.on_windows(), 'rubocop_config_file': cfg_file, 'is_st2': self.is_st2() }) def on_windows(self): return sublime.platform() == 'windows' def is_st2(self): return int(sublime.version()) < 3000 def is_st3(self): return int(sublime.version()) >= 3000 def used_options(self): return [] def current_project_folder(self): if self.is_st3(): 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 '' else: folders = sublime.active_window().folders() if (not (folders is None)) and (len(folders) > 0): return folders[0] return '' def run_rubocop_on(self, pathlist): if len(pathlist) == 0: return working_dir = self.current_project_folder() quoted_paths = [] for path in pathlist: quoted_paths.append(FileTools.quote(path)) rubocop_cmd = self.runner.command_string(quoted_paths, self.used_options()) self.run_shell_command(rubocop_cmd, working_dir) def run_shell_command(self, command, working_dir): self.view.window().run_command( 'exec', { 'cmd': command, 'shell': True, 'working_dir': working_dir, 'file_regex': r"^(.*):(\d*):(\d*): (.: .*$)" })
class RubocopCommand(sublime_plugin.TextCommand): def run(self, edit): self.load_config() def load_config(self): s = sublime.load_settings(SETTINGS_FILE) cfg_file = s.get('rubocop_config_file') if cfg_file: cfg_file = FileTools.quote(cfg_file) self.runner = RubocopRunner( { 'use_rbenv': s.get('check_for_rbenv'), 'use_rvm': s.get('check_for_rvm'), 'custom_rubocop_cmd': s.get('rubocop_command'), 'rvm_auto_ruby_path': s.get('rvm_auto_ruby_path'), 'rbenv_path': s.get('rbenv_path'), 'on_windows': self.on_windows(), 'rubocop_config_file': cfg_file, 'is_st2': self.is_st2() } ) def on_windows(self): return sublime.platform() == 'windows' def is_st2(self): return int(sublime.version()) < 3000 def is_st3(self): return int(sublime.version()) >= 3000 def used_options(self): return [] def current_project_folder(self): if self.is_st3(): 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 '' else: folders = sublime.active_window().folders() if (not (folders is None)) and (len(folders) > 0): return folders[0] return '' def run_rubocop_on(self, pathlist): if len(pathlist) == 0: return working_dir = self.current_project_folder() quoted_paths = [] for path in pathlist: quoted_paths.append(FileTools.quote(path)) rubocop_cmd = self.runner.command_string( quoted_paths, self.used_options() ) self.run_shell_command(rubocop_cmd, working_dir) def run_shell_command(self, command, working_dir): self.view.window().run_command('exec', { 'cmd': command, 'shell': True, 'working_dir': working_dir, 'file_regex': r"^(.*):(\d*):(\d*): (.: .*$)" })
class RubocopCommand(sublime_plugin.TextCommand): def run(self, edit): self.load_config() def load_config(self): s = sublime.load_settings(SETTINGS_FILE) cfg_file = s.get("rubocop_config_file") if cfg_file: cfg_file = FileTools.quote(cfg_file) self.runner = RubocopRunner( { "use_rbenv": s.get("check_for_rbenv"), "use_rvm": s.get("check_for_rvm"), "custom_rubocop_cmd": s.get("rubocop_command"), "rvm_auto_ruby_path": s.get("rvm_auto_ruby_path"), "rbenv_path": s.get("rbenv_path"), "on_windows": self.on_windows(), "rubocop_config_file": cfg_file, "is_st2": self.is_st2(), } ) def on_windows(self): return sublime.platform() == "windows" def is_st2(self): return int(sublime.version()) < 3000 def is_st3(self): return int(sublime.version()) >= 3000 def used_options(self): return [] def current_project_folder(self): if self.is_st3(): project = sublime.active_window().project_data() 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: return first_folder["path"] or "" else: folders = sublime.active_window().folders() if (not (folders is None)) and (len(folders) > 0): return folders[0] return "" def run_rubocop_on(self, pathlist): if len(pathlist) == 0: return working_dir = self.current_project_folder() quoted_paths = [] for path in pathlist: quoted_paths.append(FileTools.quote(path)) rubocop_cmd = self.runner.command_string(quoted_paths, self.used_options()) self.run_shell_command(rubocop_cmd, working_dir) def run_shell_command(self, command, working_dir): self.view.window().run_command( "exec", {"cmd": command, "shell": True, "working_dir": working_dir, "file_regex": r"^(.*):(\d*):\d*: .: .*$"}, )