<commit_before>#
# linter.py
# Linter for SublimeLinter3, a code checking framework for Sublime Text 3
#
# Written by <NAME>
# Copyright (c) 2015 <NAME>
#
# License: MIT
#

"""This module exports the jolint plugin class."""

from SublimeLinter.lint import Linter, util
import sublime
import os, platform
import codecs
import json

class JoLint(Linter):

    USER_SETTINGS = "SublimeLinter-jolint.sublime-settings"
    windows_default = "C:\jolie"
    nix_default = "/usr/lib/jolie"
    if( platform.system == "Windows" ):
        default_install = windows_default
    else:
        default_install = nix_default

    if os.environ.get( "JOLIE_HOME" ) is None:
        path = os.path.join( sublime.packages_path(), "SublimeLinter-jolint" )
        settings_file = os.path.join( path, USER_SETTINGS )
        if os.path.exists( path ):
            if os.path.isfile( settings_file ):
                with codecs.open( settings_file, 'r', 'UTF-8') as settings_content:
                    settings = json.loads( "".join( settings_content.readlines() ) )
                    if settings[ "JOLIE_HOME" ]:
                        os.environ[ "JOLIE_HOME" ] = settings[ "JOLIE_HOME" ]
            else:
                with codecs.open( settings_file, 'w', 'UTF-8' ) as settings_content:
                    settings_content.writelines( json.dumps( { "JOLIE_HOME" : default_install } ) )
                    sublime.message_dialog( "JOLIE_HOME not set and no settings file found.\n\n"
                                            "JOLIE_HOME set to the default value:\n\n" + default_install + "\n\n" + 
                                            "Settings file created at:\n\n" + settings_file + "\n\n"
                                            "change the path according to your Jolie installation" 
                                        )
    else :
        print("\"JOLIE_HOME\" is set to " + os.environ.get( "JOLIE_HOME" ) )

    """Provides an interface to jolint."""
    syntax = "jolie"
    cmd = "jolie --check @"
    regex = (
        r'^.+:(?P<line>\d+): error: (?P<message>.+)$'
    )
    multiline = True
    line_col_base = (1, 1)
    tempfile_suffix = None
    error_stream = util.STREAM_BOTH

    env = { "JOLIE_HOME" : os.environ[ "JOLIE_HOME" ] }
<commit_msg>moved check for environment into function<commit_after>#
# linter.py
# Linter for SublimeLinter3, a code checking framework for Sublime Text 3
#
# Written by <NAME>
# Copyright (c) 2015 <NAME>
#
# License: MIT
#

"""This module exports the jolint plugin class."""

from SublimeLinter.lint import Linter, util
import sublime
import os, platform
import codecs
import json

class JoLint(Linter):

    def checkEnvironment():
        USER_SETTINGS = "SublimeLinter-jolint.sublime-settings"
        windows_default = "C:\jolie"
        nix_default = "/usr/lib/jolie"
        if( platform.system == "Windows" ):
            default_install = windows_default
        else:
            default_install = nix_default

        if os.environ.get( "JOLIE_HOME" ) is None:
            path = os.path.join( sublime.packages_path(), "SublimeLinter-jolint" )
            settings_file = os.path.join( path, USER_SETTINGS )
            if os.path.exists( path ):
                if os.path.isfile( settings_file ):
                    with codecs.open( settings_file, 'r', 'UTF-8') as settings_content:
                        settings = json.loads( "".join( settings_content.readlines() ) )
                        if settings[ "JOLIE_HOME" ]:
                            os.environ[ "JOLIE_HOME" ] = settings[ "JOLIE_HOME" ]
                else:
                    with codecs.open( settings_file, 'w', 'UTF-8' ) as settings_content:
                        settings_content.writelines( json.dumps( { "JOLIE_HOME" : default_install } ) )
                        sublime.message_dialog( "JOLIE_HOME not set and no settings file found.\n\n"
                                                "JOLIE_HOME set to the default value:\n\n" + default_install + "\n\n" + 
                                                "Settings file created at:\n\n" + settings_file + "\n\n"
                                                "change the path according to your Jolie installation" 
                                            )
                        checkEnvironment()
        else :
            print("\"JOLIE_HOME\" is set to " + os.environ.get( "JOLIE_HOME" ) )

    sublime.message_dialog("Plugin activated")

    """Provides an interface to jolint."""
    syntax = "jolie"
    cmd = "jolie --check @"
    regex = (
        r'^.+:(?P<line>\d+): error: (?P<message>.+)$'
    )
    multiline = True
    line_col_base = (1, 1)
    tempfile_suffix = None
    error_stream = util.STREAM_BOTH

    checkEnvironment()
    env = { "JOLIE_HOME" : os.environ[ "JOLIE_HOME" ] }

{'fraction_non_alphanumeric': 0.11369294605809128, 'fraction_numerical': 0.004149377593360996, 'mean_word_length': 1.8937575030012004, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 15, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2577075', 'n_tokens_mistral': 1506, 'n_tokens_neox': 1456, 'n_words': 357}