<commit_before>import sublime
import sublime_plugin
import os
import subprocess
import threading
import re


class DartLint(sublime_plugin.EventListener):
    def __init__(self, *args, **kwargs):
        sublime_plugin.EventListener.__init__(self, *args, **kwargs)
        print("Dart lint active.")

    def on_post_save(self, view):
        fileName = view.file_name()
        isDart = fileName.find('.dart')

        if isDart == -1:
            return

        print("Dart lint: Running dartanalyzer on ", fileName)
        # run dartanalyzer in its own thread
        RunDartanalyzer(view, fileName)


def RunDartanalyzer(view, fileName):
    settings = view.settings()
    dartsdk_path = settings.get('dartsdk_path')

    if dartsdk_path:
        DartLintThread(view.window(), dartsdk_path, fileName).start()


class DartLintThread(threading.Thread):
    def __init__(self, window, dartsdk_path, fileName):
        super(DartLintThread, self).__init__()
        self.daemon = True
        self.window = window
        self.dartsdk_path = dartsdk_path
        self.fileName = fileName

    def get_startupinfo(self):
        if IsWindows():
            startupinfo = subprocess.STARTUPINFO()
            startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
            startupinfo.wShowWindow = subprocess.SW_HIDE
            return startupinfo
        return subprocess.STARTUPINFO()

    def run(self):
        # working_directory = os.path.dirname(self.fileName)
        analyzer_path = os.path.join(self.dartsdk_path, 'bin', 'dartanalyzer')
        if IsWindows():
            analyzer_path += '.bat'

        print('\ndartanalyzer %s\n' % self.fileName)
        proc = subprocess.Popen([analyzer_path, self.fileName],
                                stdout=subprocess.PIPE)
        while not proc.poll():
            # Wait for it...
            pass

        pattern = re.compile(r'^(?:((?P<error>(\[error\]))|(?P<warning>(\[warning\]))))\s(?P<message>.*)\s\((?P<file>.*)\,\sline\s(?P<line>\d*)\, col\s(?P<col>\d*)')

        lines = proc.stdout.read().decode("utf-8").split('\n')

        lines_out = ''
        for line in lines:
            line_groups = pattern.match(line)

            if line_groups is not None:
                if line_groups.group('file') != self.fileName:
                    # output is for a different file
                    continue
                if line_groups.group('error'):
                    lines_out += 'Error '
                elif line_groups.group('warning'):
                    lines_out += 'Warning '
                lines_out += 'on line %s, col %s: %s\n' % (line_groups.group('line'), line_groups.group('col'), line_groups.group('message'))

        self.output = lines_out
        print(self.output)
        # annoying: sublime.message_dialog(self.output)
        # Output to a popup
        # Mark the gutter
        # Underline Errors / Warnings


def IsWindows():
    return sublime.platform() == 'windows'<commit_msg>lol how about now<commit_after>import sublime
import sublime_plugin
import os
import subprocess
import threading
import re


class DartLint(sublime_plugin.EventListener):
    def __init__(self, *args, **kwargs):
        sublime_plugin.EventListener.__init__(self, *args, **kwargs)
        print("Dart lint active.")

    def on_post_save(self, view):
        fileName = view.file_name()
        isDart = fileName.find('.dart')

        if isDart == -1:
            return

        print("Dart lint: Running dartanalyzer on ", fileName)
        # run dartanalyzer in its own thread
        RunDartanalyzer(view, fileName)


def RunDartanalyzer(view, fileName):
    settings = view.settings()
    dartsdk_path = settings.get('dartsdk_path')

    if dartsdk_path:
        DartLintThread(view.window(), dartsdk_path, fileName).start()


class DartLintThread(threading.Thread):
    def __init__(self, window, dartsdk_path, fileName):
        super(DartLintThread, self).__init__()
        self.daemon = True
        self.window = window
        self.dartsdk_path = dartsdk_path
        self.fileName = fileName

    def get_startupinfo(self):
        if IsWindows():
            startupinfo = subprocess.STARTUPINFO()
            startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
            startupinfo.wShowWindow = subprocess.SW_HIDE
            return startupinfo
        return subprocess.STARTUPINFO()

    def run(self):
        # working_directory = os.path.dirname(self.fileName)
        analyzer_path = os.path.join(self.dartsdk_path, 'bin', 'dartanalyzer')
        if IsWindows():
            analyzer_path += '.bat'

        print('\ndartanalyzer %s\n' % self.fileName)
        proc = subprocess.Popen([analyzer_path, self.fileName],
                                stdout=subprocess.PIPE)
        while not proc.poll():
            # Wait for it...
            pass

        msg_pattern = re.compile(
            r'^(?:((?P<error>(\[error\]))|(?P<warning>(\[warning\]))))\s(?P<message>.*)\s\((?P<file>.*)\,\sline\s(?P<line>\d*)\, col\s(?P<col>\d*)')
        culprit_pattern = re.compile(
            r'^.+\'(?:(?P<culprit>(.+)))\'')

        # TODO: use proper locale instead of "utf-8"
        lines = proc.stdout.read().decode("utf-8").split('\n')

        # Collect data needed to generate error messages
        lint_data = []
        lines_out = ''
        for line in lines:
            line_out = ''
            line_data = {}
            line_groups = msg_pattern.match(line)

            if line_groups is not None:
                if line_groups.group('file') != self.fileName:
                    # output is for a different file
                    continue
                if line_groups.group('error'):
                    line_out += 'Error '
                    line_data['type'] = 'error'
                elif line_groups.group('warning'):
                    line_out += 'Warning '
                    line_data['type'] = 'warning'
                line_out += 'on line %s, col %s: %s\n' % \
                    (line_groups.group('line'),
                     line_groups.group('col'),
                     line_groups.group('message'))

                line_data['col'] = line_groups.group('col')
                line_data['line'] = line_groups.group('line')
                line_data['msg'] = line_groups.group('message')
                line_data['lint_out'] = line_out
                line_data['culprit'] = ''

                # Get the culprit:
                culp_group = culprit_pattern.match(line_groups.group('message'))
                if culp_group is not None:
                    line_data['culprit'] = culp_group.group('culprit')

                lines_out += line_out
                lint_data.append(line_data)

        if lines_out is '':
            self.output = 'No errors.'
        else:
            self.output = lines_out

        print(lint_data)

        print('\n' + self.output)
        # annoying: sublime.message_dialog(self.output)
        # Output to a popup
        # Mark the gutter
        # Underline Errors / Warnings


def IsWindows():
    return sublime.platform() == 'windows'
{'fraction_non_alphanumeric': 0.12366797532249019, 'fraction_numerical': 0.0007010656197420079, 'mean_word_length': 2.06006006006006, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, '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': '6455229', 'n_tokens_mistral': 2158, 'n_tokens_neox': 2070, 'n_words': 426}