def run(self, edit): super(RubocopAutoCorrectCommand, self).run(edit) cancel_op = self.user_wants_to_cancel() if cancel_op: return view = self.view path = view.file_name() quoted_file_path = FileTools.quote(path) if view.is_read_only(): sublime.message_dialog('RuboCop: Unable to run auto correction on a read only buffer.') return # Inform user about unsaved contents of current buffer if view.is_dirty(): warn_msg = 'RuboCop: The curent buffer is modified. Save the file and continue?' cancel_op = not sublime.ok_cancel_dialog(warn_msg) if cancel_op: return else: view.run_command('save') RubocopEventListener.instance().clear_marks(view) quoted_file_path = FileTools.quote(path) # Run rubocop with auto-correction self.runner.run(quoted_file_path, '-a') sublime.status_message('RuboCop: Auto correction done.')
def run(self, edit): super(RubocopAutoCorrectCommand, self).run(edit) cancel_op = self.user_wants_to_cancel() if cancel_op: return view = self.view path = view.file_name() quoted_file_path = FileTools.quote(path) if view.is_read_only(): sublime.message_dialog( 'RuboCop: Unable to run auto correction on a read only buffer.' ) return # Inform user about unsaved contents of current buffer if view.is_dirty(): warn_msg = 'RuboCop: The curent buffer is modified. Save the file and continue?' cancel_op = not sublime.ok_cancel_dialog(warn_msg) if cancel_op: return else: view.run_command('save') RubocopEventListener.instance().clear_marks(view) quoted_file_path = FileTools.quote(path) # Run rubocop with auto-correction self.runner.run([quoted_file_path], ['-a']) sublime.status_message('RuboCop: Auto correction done.')
def run(self, edit): super(RubocopAutoCorrectCommand, self).run(edit) cancel_op = self.warning_msg() if cancel_op: return view = self.view path = view.file_name() quoted_file_path = FileTools.quote(path) if view.is_read_only(): sublime.message_dialog( 'RuboCop: Unable to run auto correction on a read only buffer.' ) return # Inform user about unsaved contents of current buffer if view.is_dirty(): warn_msg = 'RuboCop: The curent buffer is modified. Save the file and continue?' cancel_op = not sublime.ok_cancel_dialog(warn_msg) if cancel_op: return else: view.run_command('save') RubocopEventListener.instance().clear_marks(view) # Copy the current file to a temp file content = view.substr(sublime.Region(0, view.size())) f = tempfile.NamedTemporaryFile() try: self.write_to_file(f, content, view) f.flush() # Create path for possible config file in the source directory quoted_file_path = FileTools.quote(path) config_opt = '-c ' + os.path.dirname( quoted_file_path) + '/.rubocop.yml' print(config_opt) # Run rubocop with auto-correction on temp file self.runner.run(f.name, '-a ' + config_opt) # Read contents of file f.seek(0) content = self.read_from_file(f, view) # Overwrite buffer contents rgn = sublime.Region(0, view.size()) view.replace(edit, rgn, content) finally: # TempFile will be deleted here f.close() sublime.status_message('RuboCop: Auto correction done.')
def run(self, edit): super(RubocopAutoCorrectCommand, self).run(edit) cancel_op = self.warning_msg() if cancel_op: return view = self.view path = view.file_name() quoted_file_path = FileTools.quote(path) if view.is_read_only(): sublime.message_dialog('RuboCop: Unable to run auto correction on a read only buffer.') return # Inform user about unsaved contents of current buffer if view.is_dirty(): warn_msg = 'RuboCop: The curent buffer is modified. Save the file and continue?' cancel_op = not sublime.ok_cancel_dialog(warn_msg) if cancel_op: return else: view.run_command('save') RubocopEventListener.instance().clear_marks(view) # Copy the current file to a temp file content = view.substr(sublime.Region(0, view.size())) f = tempfile.NamedTemporaryFile() try: self.write_to_file(f, content, view) f.flush() # Create path for possible config file in the source directory quoted_file_path = FileTools.quote(path) config_opt = '-c ' + os.path.dirname(quoted_file_path) + '/.rubocop.yml' print(config_opt) # Run rubocop with auto-correction on temp file self.runner.run(f.name, '-a ' + config_opt) # Read contents of file f.seek(0) content = self.read_from_file(f, view) # Overwrite buffer contents rgn = sublime.Region(0, view.size()) view.replace(edit, rgn, content) finally: # TempFile will be deleted here f.close() sublime.status_message('RuboCop: Auto correction done.')
def pause(self): s = sublime.load_settings(SETTINGS_FILE) mark_issues_in_view = s.get('mark_issues_in_view') s.set('mark_issues_in_view', not mark_issues_in_view) sublime.save_settings(SETTINGS_FILE) RubocopEventListener.instance().update_marks()