<commit_before>import sublime
import sublime_plugin
import re

from .gotools_util import Buffers
from .gotools_util import GoBuffers
from .gotools_util import Logger
from .gotools_util import ToolRunner
from .gotools_settings import GoToolsSettings

class GotoolsFormatOnSave(sublime_plugin.EventListener):
  def on_pre_save(self, view):
    if not GoBuffers.is_go_source(view): return
    if not GoToolsSettings.get().format_on_save: return
    view.run_command('gotools_format')

class GotoolsFormat(sublime_plugin.TextCommand):
  def is_enabled(self):
    return GoBuffers.is_go_source(self.view)

  def run(self, edit):
    command = ""
    args = []
    if GoToolsSettings.get().format_backend == "gofmt":
      command = "gofmt"
      args = ["-e", "-s"]
    elif GoToolsSettings.get().format_backend in ["goimports", "both"] :
      command = "goimports"
      args = ["-e"]

    stdout, stderr, rc = ToolRunner.run(command, args, stdin=Buffers.buffer_text(self.view))

    # Clear previous syntax error marks
    self.view.erase_regions("mark")

    if rc == 2:
      # Show syntax errors and bail
      self.show_syntax_errors(stderr)
      return

    if rc != 0:
      # Ermmm...
      Logger.log("unknown gofmt error (" + str(rc) + ") stderr:\n" + stderr)
      return

    if GoToolsSettings.get().format_backend == "both":
      command = "gofmt"
      args = ["-e", "-s"]
      stdout, stderr, rc = self.runner.run(command, args, stdin=stdout.encode('utf-8'))

    # Clear previous syntax error marks
    self.view.erase_regions("mark")

    if rc == 2:
      # Show syntax errors and bail
      self.show_syntax_errors(stderr)
      return

    if rc != 0:<commit_msg>Fix 'both' fmt backend setting<commit_after>import sublime
import sublime_plugin
import re

from .gotools_util import Buffers
from .gotools_util import GoBuffers
from .gotools_util import Logger
from .gotools_util import ToolRunner
from .gotools_settings import GoToolsSettings

class GotoolsFormatOnSave(sublime_plugin.EventListener):
  def on_pre_save(self, view):
    if not GoBuffers.is_go_source(view): return
    if not GoToolsSettings.get().format_on_save: return
    view.run_command('gotools_format')

class GotoolsFormat(sublime_plugin.TextCommand):
  def is_enabled(self):
    return GoBuffers.is_go_source(self.view)

  def run(self, edit):
    command = ""
    args = []
    if GoToolsSettings.get().format_backend == "gofmt":
      command = "gofmt"
      args = ["-e", "-s"]
    elif GoToolsSettings.get().format_backend in ["goimports", "both"] :
      command = "goimports"
      args = ["-e"]

    stdout, stderr, rc = ToolRunner.run(command, args, stdin=Buffers.buffer_text(self.view))

    # Clear previous syntax error marks
    self.view.erase_regions("mark")

    if rc == 2:
      # Show syntax errors and bail
      self.show_syntax_errors(stderr)
      return

    if rc != 0:
      # Ermmm...
      Logger.log("unknown gofmt error (" + str(rc) + ") stderr:\n" + stderr)
      return

    if GoToolsSettings.get().format_backend == "both":
      command = "gofmt"
      args = ["-e", "-s"]
      stdout, stderr, rc = ToolRunner.run(command, args, stdin=stdout.encode('utf-8'))

    # Clear previous syntax error marks
    self.view.erase_regions("mark")

    if rc == 2:
      # Show syntax errors and bail
      self.show_syntax_errors(stderr)
      return

    if rc != 0:
{'fraction_non_alphanumeric': 0.11790780141843972, 'fraction_numerical': 0.002955082742316785, 'mean_word_length': 3.3176020408163267, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5065316', 'n_tokens_mistral': 1120, 'n_tokens_neox': 1081, 'n_words': 271}