コード例 #1
0
  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.')
コード例 #2
0
    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.')
コード例 #3
0
    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.')
コード例 #4
0
ファイル: allPythonContent.py プロジェクト: Mondego/pyreco
  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.')
コード例 #5
0
  def run_rubocop(self, view):
    s = sublime.load_settings(SETTINGS_FILE)

    use_rvm = view.settings().get('check_for_rvm', s.get('check_for_rvm'))
    use_rbenv = view.settings().get('check_for_rbenv', s.get('check_for_rbenv'))
    cmd = view.settings().get('rubocop_command', s.get('rubocop_command'))
    rvm_path = view.settings().get('rvm_auto_ruby_path', s.get('rvm_auto_ruby_path'))
    rbenv_path = view.settings().get('rbenv_path', s.get('rbenv_path'))
    cfg_file = view.settings().get('rubocop_config_file', s.get('rubocop_config_file'))
    chdir = view.settings().get('rubocop_chdir', s.get('rubocop_chdir'))

    if cfg_file:
      cfg_file = FileTools.quote(cfg_file)

    runner = RubocopRunner(
      {
        'use_rbenv': use_rbenv,
        'use_rvm': use_rvm,
        'custom_rubocop_cmd': cmd,
        'rvm_auto_ruby_path': rvm_path,
        'rbenv_path': rbenv_path,
        'on_windows': sublime.platform() == 'windows',
        'rubocop_config_file': cfg_file,
        'chdir': chdir,
        'is_st2': sublime.version() < '3000'
      }
    )
    output = runner.run([view.file_name()], ['--format', 'emacs']).splitlines()

    return output
コード例 #6
0
    def run_rubocop(self, view):
        s = sublime.load_settings(SETTINGS_FILE)

        use_rvm = view.settings().get('check_for_rvm', s.get('check_for_rvm'))
        use_rbenv = view.settings().get('check_for_rbenv',
                                        s.get('check_for_rbenv'))
        cmd = view.settings().get('rubocop_command', s.get('rubocop_command'))
        rvm_path = view.settings().get('rvm_auto_ruby_path',
                                       s.get('rvm_auto_ruby_path'))
        rbenv_path = view.settings().get('rbenv_path', s.get('rbenv_path'))
        cfg_file = view.settings().get('rubocop_config_file',
                                       s.get('rubocop_config_file'))
        chdir = view.settings().get('rubocop_chdir', s.get('rubocop_chdir'))

        if cfg_file:
            cfg_file = FileTools.quote(cfg_file)

        runner = RubocopRunner({
            'use_rbenv': use_rbenv,
            'use_rvm': use_rvm,
            'custom_rubocop_cmd': cmd,
            'rvm_auto_ruby_path': rvm_path,
            'rbenv_path': rbenv_path,
            'on_windows': sublime.platform() == 'windows',
            'rubocop_config_file': cfg_file,
            'chdir': chdir,
            'is_st2': sublime.version() < '3000'
        })
        output = runner.run([view.file_name()],
                            ['--format', 'emacs']).splitlines()

        return output
コード例 #7
0
 def open_ruby_files(self):
   files = []
   views = self.view.window().views()
   for vw in views:
     if FileTools.is_ruby_file(vw):
       files.append(vw.file_name())
   return files
コード例 #8
0
 def open_ruby_files(self):
     files = []
     views = self.view.window().views()
     for vw in views:
         if FileTools.is_ruby_file(vw):
             files.append(vw.file_name())
     return files
コード例 #9
0
 def open_ruby_files(self):
   files = []
   views = self.view.window().views()
   for vw in views:
     file_path = vw.file_name()
     if FileTools.is_ruby_file(file_path):
       files.append(file_path)
   return files
コード例 #10
0
 def do_post_save_check(self, view):
   self.clear_marks(view)
   if not sublime.load_settings(SETTINGS_FILE).get('check_on_save'):
     return
   if not FileTools.is_ruby_file(view.file_name()):
     return
   results = self.run_rubocop(view.file_name())
   self.set_marks_by_results(view, results)
コード例 #11
0
 def open_ruby_files(self):
     files = []
     views = self.view.window().views()
     for vw in views:
         file_path = vw.file_name()
         if FileTools.is_ruby_file(file_path):
             files.append(file_path)
     return files
コード例 #12
0
  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)
コード例 #13
0
ファイル: allPythonContent.py プロジェクト: Mondego/pyreco
  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)
コード例 #14
0
    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)
コード例 #15
0
    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)
コード例 #16
0
    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)
コード例 #17
0
 def do_in_file_check(self, view):
     if not FileTools.is_ruby_file(view):
         return
     settings = sublime.load_settings(SETTINGS_FILE)
     mark_issues_in_view = settings.get('mark_issues_in_view')
     auto_correct_on_save = settings.get('auto_correct_on_save')
     cmd_args = ['--format', 'emacs']
     if auto_correct_on_save:
         cmd_args.append('-a')
     if mark_issues_in_view:
         self.clear_marks(view)
     if mark_issues_in_view or auto_correct_on_save:
         results = self.run_rubocop(view, cmd_args)
         if mark_issues_in_view:
             self.set_marks_by_results(view, results)
コード例 #18
0
 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
     }
   )
コード例 #19
0
 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(),
         }
     )
コード例 #20
0
  def run(self, edit):
    super(RubocopOpenAllOffensiveFilesCommand, self).run(edit)

    folders = self.view.window().folders()
    if len(folders) <= 0:
      sublime.status_message('RuboCop: No project folder available.')
      return

    folder = FileTools.quote(folders[0])

    # Run rubocop with file formatter
    file_list = self.runner.run([folder], ['--format files']).splitlines()

    for path in file_list:
      self.view.window().open_file(path.decode(locale.getpreferredencoding()))

    sublime.status_message('RuboCop: Opened ' + str(len(file_list)) + ' files.')
コード例 #21
0
  def run(self, edit):
    super(RubocopOpenAllOffensiveFilesCommand, self).run(edit)

    folders = self.view.window().folders()
    if len(folders) <= 0:
      sublime.status_message('RuboCop: No project folder available.')
      return

    folder = FileTools.quote(folders[0])

    # Run rubocop with file formatter
    file_list = self.runner.run([folder], ['--format files']).splitlines()

    for path in file_list:
      self.view.window().open_file(path.decode(locale.getpreferredencoding()))

    sublime.status_message('RuboCop: Opened ' + str(len(file_list)) + ' files.')
コード例 #22
0
 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()
     }
   )
コード例 #23
0
 def run_rubocop(self, path):
   s = sublime.load_settings(SETTINGS_FILE)
   use_rvm = s.get('check_for_rvm')
   use_rbenv = s.get('check_for_rbenv')
   cmd = s.get('rubocop_command')
   rvm_path = s.get('rvm_auto_ruby_path')
   rbenv_path = s.get('rbenv_path')
   cfg_file = s.get('rubocop_config_file')
   if cfg_file:
     cfg_file = FileTools.quote(cfg_file)
   runner = RubocopRunner(
     {
       'use_rbenv': use_rbenv,
       'use_rvm': use_rvm,
       'custom_rubocop_cmd': cmd,
       'rvm_auto_ruby_path': rvm_path,
       'rbenv_path': rbenv_path,
       'on_windows': sublime.platform() == 'windows',
       'rubocop_config_file': cfg_file
     }
   )
   output = runner.run(path, '--format emacs').splitlines()
   return output
コード例 #24
0
 def do_in_file_check(self, view):
   if not FileTools.is_ruby_file(view.file_name()):
     return
   mark = sublime.load_settings(SETTINGS_FILE).get('mark_issues_in_view')
   self.mark_issues(view, mark)