def __init__(self, view, syntax):
        """Initialize and load GOPATH from settings if present."""
        Linter.__init__(self, view, syntax)

        self.gopath = view.settings().get("env")['GOPATH'] if view.settings().get("env")['GOPATH'] else self.get_view_settings().get('gopath') if self.get_view_settings().get('gopath') else os.environ.get('GOPATH')

        os.env = {'GOPATH':self.gopath}
Exemple #2
0
 def cmd(self):
     """Return a tuple with the command line to execute."""
     command = [self.executable_path, '-errors', '-quiet', '-utf8']
     if Linter.which('tidy5'):
         command[0] = Linter.which('tidy5')
     else:
         command[0] = Linter.which('tidy')
     return command
Exemple #3
0
    def __init__(self, view, syntax):
        """Initialize and load lc-community-server from settings if present."""

        Linter.__init__(self, view, syntax)

        self.livecode_path = self.get_view_settings().get(
            'livecode-server-path')
        self.explicit_vars = self.get_view_settings().get('explicitvars')
        self.livecodelint_path = os.path.dirname(__file__) + '/livecodelint.lc'
    def __init__(self, view, syntax):
        """Initialize and load GOPATH from settings if present."""
        Linter.__init__(self, view, syntax)

        gopath = self.get_view_settings().get('gopath')
        if gopath:
            if self.env:
                self.env['GOPATH'] = gopath
            else:
                self.env = {'GOPATH': gopath}
            print('sublimelinter: GOPATH={}'.format(self.env['GOPATH']))
        else:
            print('sublimelinter: using system GOPATH={}'.format(os.environ.get('GOPATH', '')))
    def __init__(self, view, syntax):
        """Override init to dynamically set config_file."""

        Linter.__init__(self, view, syntax)

        settings = self.get_view_settings()
        config_file_name = settings.get('config_file_name')
        aux_config_dirs = settings.get('aux_config_dirs')
        config_file_tuple = ('-configfile', config_file_name)

        for conf in aux_config_dirs:
            config_file_tuple += (conf, )

        self.config_file = config_file_tuple
Exemple #6
0
    def cmd(self):
        """Read cmd from inline settings."""
        settings = Linter.get_view_settings(self)

        if 'cmd' in settings:
            command = [settings.get('cmd')]
        else:
            command = [self.executable_path]

        if 'config_file' in settings:
            config_file = settings.get('config_file')
        else:
            config_file = _find_configuration_file(self.view.file_name())
            if not config_file:
                config_file = self.config_file

        command.append('fix')
        command.append('@')
        command.append('--dry-run')
        command.append('--diff')

        # Note: This option requires php-cs-fixer >= 2.7
        command.append('--diff-format=udiff')

        command.append('--using-cache=no')
        command.append('--no-ansi')
        command.append('--config=' + config_file)
        command.append('-vv')

        return command
Exemple #7
0
    def cmd(self):
        """Read cmd from inline settings."""
        settings = Linter.get_view_settings(self)

        if 'cmd' in settings:
            command = [settings.get('cmd')]
        else:
            command = [self.executable_path]

        if 'config_file' in settings:
            config_file = settings.get('config_file')
        else:
            config_file = self.config_file

        command.append('fix')
        command.append('@')
        command.append('--dry-run')
        command.append('--diff')
        command.append('--diff-format=udiff')
        command.append('--using-cache=no')
        command.append('--no-ansi')
        command.append('--config=' + config_file)
        command.append('-vv')

        return command
class HtmlTidy(Linter):
    """Provides an interface to tidy."""

    syntax = 'html'
    if Linter.which('tidy5'):
        cmd = 'tidy5 -errors -quiet -utf8'
    else:
        cmd = 'tidy -errors -quiet -utf8'
    regex = r'^line (?P<line>\d+) column (?P<col>\d+) - (?:(?P<error>Error)|(?P<warning>Warning)): (?P<message>.+)'
    error_stream = util.STREAM_STDERR
    def cmd(self):
        """Read cmd from inline settings."""
        settings = Linter.get_view_settings(self)

        if 'cmd' in settings:
            command = [settings.get('cmd')]
        else:
            command = [self.executable_path]

        command.append('--report=checkstyle')

        return command
Exemple #10
0
    def cmd(self):
        """Read cmd from inline settings."""
        settings = Linter.get_view_settings(self)

        if 'cmd' in settings:
            command = [settings.get('cmd')]
        else:
            command = [self.executable_path]

        command.append('--report=checkstyle')

        return command
Exemple #11
0
    def cmd(self):
        """Create the cmd."""
        settings = Linter.get_view_settings(self)

        # attempt to get the command from settings if it is present
        if 'cmd' in settings:
            command = [settings.get('cmd')]
        else:
            command = [self.executable_path]

        command.append('@')
        command.append('text')

        return command
Exemple #12
0
    def cmd(self):
        """Create the cmd."""
        settings = Linter.get_view_settings(self)

        # attempt to get the command from settings if it is present
        if 'cmd' in settings:
            command = [settings.get('cmd')]
        else:
            command = [self.executable_path]

        command.append('@')
        command.append('text')

        return command
    def __init__(self, view, syntax):
        """Initialize and load GOPATH from settings if present."""
        Linter.__init__(self, view, syntax)

        if not self.env:
            self.env = {}

        gopath = self.get_view_settings().get('gopath')
        if gopath:
            self.env['GOPATH'] = gopath
            print('sublimelinter: (custom) GOPATH={}'.format(
                self.env['GOPATH']))
        else:
            print('sublimelinter: (system) GOPATH={}'.format(
                os.environ.get('GOPATH', '')))

        goroot = self.get_view_settings().get('goroot')
        if goroot:
            self.env['GOROOT'] = goroot
            print('sublimelinter: (custom) GOROOT={}'.format(
                self.env['GOROOT']))
        else:
            print('sublimelinter: (system) GOROOT={}'.format(
                os.environ.get('GOROOT', '')))
    def cmd(self):
        """Read cmd from inline settings."""
        settings = Linter.get_view_settings(self)

        if 'cmd' in settings:
            command = [settings.get('cmd')]
        else:
            command = [self.executable_path]

        command.append('fix')
        command.append('@')
        command.append('--diff')
        command.append('--format=xml')
        command.append('-vv')

        return command
    def cmd(self):
        """Read cmd from inline settings."""
        settings = Linter.get_view_settings(self)

        if 'cmd' in settings:
            command = [settings.get('cmd')]
        else:
            command = [self.executable_path]

        command.append('fix')
        command.append('@')
        command.append('--diff')
        command.append('--format=xml')
        command.append('-vv')

        return command
Exemple #16
0
    def cmd(self):
        """Read cmd from inline settings."""
        settings = Linter.get_view_settings(self)

        if 'cmd' in settings:
            command = [settings.get('cmd')]
        else:
            command = [self.executable_path]

        command.append('-l')
        command.append('-n')
        command.append('-d')
        command.append('display_errors=On')
        command.append('-d')
        command.append('log_errors=Off')

        return command
Exemple #17
0
    def cmd(self):
        """Create the command."""
        settings = Linter.get_view_settings(self)

        # Default arguments
        cmd = ['makensis']

        linter_args = settings.get('args') or []
        strict = settings.get('strict') or False
        preprocess_mode = settings.get('preprocess_mode')
        preprocess_mode = "-{}".format(preprocess_mode) if str(
            preprocess_mode).upper() in ('PPO', 'SAFEPPO') else False

        cmd = cmd + linter_args

        # Set verbosity
        verbose_flags = [
            '-V0', '-V1', '-V2', '-V4', '-V4', '/V0', '/V1', '/V2', '/V4',
            '/V4'
        ]
        if not any(x in cmd for x in verbose_flags):
            cmd.append('-V2')

        # Is strict mode?
        strict_flags = ['-WX', '/WX']
        if strict and not any(x in cmd for x in strict_flags):
            cmd.append('-WX')

        # Is PPO mode?
        ppo_flags = ['-PPO', '-SAFEPPO', '/PPO', '/SAFEPPO']
        if preprocess_mode and any(x in preprocess_mode for x in ppo_flags):
            cmd.append(preprocess_mode)
            cmd.append("${file}")
        else:
            cmd.append("${file}")

            # Don't write installer
            if platform == 'win32':
                out_file = 'OutFile NUL'
            else:
                out_file = 'OutFile /dev/null/'

            cmd.append('-X' + out_file)

        return cmd
    def cmd(self):
        """Read cmd from inline settings."""
        settings = Linter.get_view_settings(self)

        if 'cmd' in settings:
            logger.warning('The setting `cmd` has been deprecated. '
                           'Use `executable` instead.')
            command = [settings.get('cmd')]
        else:
            command = ['php']

        command.append('-l')
        command.append('-n')
        command.append('-d')
        command.append('display_errors=On')
        command.append('-d')
        command.append('log_errors=Off')

        return command
Exemple #19
0
    def cmd(self):
        """Read cmd from inline settings."""
        settings = Linter.get_view_settings(self)

        if 'cmd' in settings:
            logger.warning('The setting `cmd` has been deprecated. '
                           'Use `executable` instead.')
            command = [settings.get('cmd')]
        else:
            command = ['php']

        command.append('-l')
        command.append('-n')
        command.append('-d')
        command.append('display_errors=On')
        command.append('-d')
        command.append('log_errors=Off')

        return command
Exemple #20
0
    def split_match(self, match):
        """Extract and return values from match."""
        match, line, col, error, warning, message, near = (
            super().split_match(match))

        if message:
            return match, line, col, error, warning, message, near

        # Is strict mode?
        settings = Linter.get_view_settings(self)
        if settings.get('strict') is True:
            error = warning

        warnMessage = str(match.groupdict()["warnMessage"])
        warnLine = match.groupdict()["warnLine"]

        if warnMessage and warnLine:
            message = warnMessage
            line = int(warnLine) - 1

        return match, line, col, error, warning, message, near
Exemple #21
0
 def __init__(self, view, settings):
     linters.Megacheck.__init__(self)
     Linter.__init__(self, view, settings)
Exemple #22
0
 def __init__(self, view, settings):
     linters.Govet.__init__(self)
     Linter.__init__(self, view, settings)
Exemple #23
0
    def run(self, cmd, code):
        """Override the default run command to inject preprocessor step."""
        # print('=== BEGIN LINTER DEBUG ===')
        # print('ORIGINAL_CODE:')
        # o_lines = code.splitlines(False)
        # o_n = 0
        # for o_l in o_lines:
        #    print('{0} |{1}'.format(get_auto_padding(o_n), o_l))
        #    o_n += 1

        mcpp_path = find_mcpp()
        # if mcpp_path is not None else Linter.communicate(self,cmd,code)
        if mcpp_path is not None:
            # Capture mcpp output and store into a variable
            opt = '-W0'
            mcpp_output = Linter.communicate(self, mcpp_path + " " + opt, code)
            lines = mcpp_output.splitlines(False)
            line_number = 0
            OutputTuple = namedtuple(
                'OutputTuple', 'mcpp_in_line\
                                                     orig_line\
                                                     file')
            preproc_bank = []
            # print('MCPP Output:')
            for line in lines:
                # print('{0} |{1}'.format(get_auto_padding(line_number), line))
                if (line.startswith('#line')):
                    message = line.split(' ')
                    # print('message:{0}'.format(message))
                    preproc_bank.append(
                        OutputTuple(mcpp_in_line=line_number,
                                    orig_line=int(message[1]),
                                    file=message[2]))
                line_number += 1
            code = mcpp_output
            # print("DEBUG:: preproc_bank: {0}".format(preproc_bank[2]))

        linter_result = Linter.communicate(self, cmd, code)
        # print("DEBUG:: LINTER_OUT output:\n{0}".format(linter_result))
        if mcpp_path is not None:
            # Go through every error and replace the line number (from the
            # inlined file) with the one from the script we fed the
            # precompiler, to restore the link between the error and the code
            # inside the editor so that we can properly show linting visual
            # hints.
            linter_output_lines = linter_result.splitlines(False)
            # print('LINTER_OUT:{0}'.format(linter_output_lines))
            # Get line at which the current file was inserted
            # TODO: make sure multi-include works
            fixed_output_lines = []
            p = re.compile('^\s*(ERROR|WARN)\:\:\s\(\s*(\d*)\.*$')
            for iter_line in linter_output_lines:
                # print('LINE:[{0}]'.format(iter_line))
                if iter_line.startswith("TOTAL::") is False:
                    tokens = iter_line.split(',')
                    # print('Tokens:[{0}]'.format(tokens))
                    token = tokens[0]
                    # print("Token:{0}".format(token))
                    number = int(p.match(token).group(2).strip())
                    # print("number: '{0}'".format(number))
                    offset = getLastOffset(preproc_bank, number)
                    # print("Offset: {0}".format(offset))
                    tokminoff = str(number - int(offset))
                    # print("Token - offset: {0}".format(tokminoff))
                    new_line = re.sub(str(number), tokminoff, iter_line)
                    # print("New Line: {0}".format(new_line))
                    fixed_output_lines.append(new_line)
                    continue
                else:
                    fixed_output_lines.append(iter_line)

            # print("New Lines: {0}".format(fixed_output_lines))
            # Transform back into a string
            linter_result = "".join(str(x) + "\n" for x in fixed_output_lines)

        # print("DEBUG:: Linter output: {0}".format(linter_result))
        # print('=== END LINTER DEBUG ===')
        return linter_result
Exemple #24
0
    def __init__(self, view, syntax):
        Linter.__init__(self, view, syntax)

        if not self.env:
            self.env = {}
        self.env.update(utils.get_env())
    def run(self, cmd, code):
        """Override the default run command to inject preprocessor step."""
        # print('=== BEGIN LINTER DEBUG ===')
        # print('ORIGINAL_CODE:')
        # o_lines = code.splitlines(False)
        # o_n = 0
        # for o_l in o_lines:
        #     print('{0} |{1}'.format(get_auto_padding(o_n), o_l))
        #     o_n += 1

        mcpp_path = find_mcpp()
        # if mcpp_path is not None else Linter.communicate(self,cmd,code)
        if mcpp_path is not None:
            opt = '-W0'
            mcpp_output = Linter.communicate(self, (mcpp_path, opt), code)
            lines = mcpp_output.splitlines(False)
            line_number = 0
            OutputTuple = namedtuple(
                'OutputTuple', 'mcpp_in_line\
                                                     orig_line\
                                                     file')
            MCPPMessage = namedtuple(
                'MCPPMessage', 'source\
                                                     line\
                                                     message')
            preproc_bank = []
            # print('MCPP Output:')
            mcpp_messages = []
            for line in lines:
                # print('{0} |{1}'.format(get_auto_padding(line_number), line))
                if (line.startswith('#line')):
                    message = line.split(' ')
                    # print('message:{0}'.format(message))
                    preproc_bank.append(
                        OutputTuple(
                            mcpp_in_line=line_number,
                            orig_line=int(message[1]),
                            file=message[2]))

                elif (line.startswith('<stdin>:')):
                    # Capture mcpp output and store into a variable
                    message = line.split(':')
                    mcpp_messages.append(
                        MCPPMessage(
                            source=message[0],
                            line=message[1],
                            message=message[3]))
                line_number += 1
            # print("DEBUG:: preproc_bank: {0}".format(preproc_bank[0]))
            linter_result = Linter.communicate(self, cmd, mcpp_output)
            # print("DEBUG:: LINTER_OUT output:\n{0}".format(linter_result))

            # Go through every error and replace the line number (from the
            # inlined file) with the one from the script we fed the
            # precompiler, to restore the link between the error and the code
            # inside the editor so that we can properly show linting visual
            # hints.
            linter_output_lines = linter_result.splitlines(False)
            # print('LINTER_OUT:{0}'.format(linter_output_lines))
            # Get line at which the current file was inserted
            # TODO: make sure multi-include works
            fixed_output_lines = []
            p = re.compile(r"^\s*?(ERROR|WARN)\:\:\s\(\s*(\d*)\.*$")
            for iter_line in linter_output_lines:
                # print('LINE:[{0}]'.format(iter_line))
                if iter_line.startswith("TOTAL::") is False:
                    tokens = iter_line.split(',')
                    # print('Tokens:[{0}]'.format(tokens))
                    rres = p.match(tokens[0])
                    if rres is not None:
                        number = int(rres.group(2))
                        # print("number: '{0}'".format(number))
                        result = getLastOffset(preproc_bank, number)
                        offset = result[0]
                        # print("Offset: {0}".format(offset))
                        # tokminoff = str(number - int(offset))
                        tokminoff = str(number - int(offset))
                        new_line = re.sub(str(number), tokminoff, iter_line)
                        # print("result[1]="+result[1])
                        if result[1] != '"<stdin>"':
                            index = getLastStdin(preproc_bank, number)
                            new_number = preproc_bank[
                                index + 1].mcpp_in_line + 1  # noqa: E501
                            offset = getLastOffset(preproc_bank, new_number)[0]
                            tokminoff = str(new_number - int(offset))
                            token_match = rres.group(1)
                            new_line = '{0}:: ({1:>3},  1): in file {2}: {3}'\
                                .format(token_match,
                                        tokminoff,
                                        result[1],
                                        new_line)
                        fixed_output_lines.append(new_line)
                    else:
                        continue
                    continue
                else:
                    fixed_output_lines.append(iter_line)

            # print("New Lines: {0}".format(fixed_output_lines))
            # Transform back into a string
            # Add messages from MCPP first
            mcpp_msg_out = ""
            for this_tuple in mcpp_messages:
                mcpp_msg_out += "ERROR:: ({0},1): {1}\n"\
                    .format(this_tuple.line, this_tuple.message)
            # print("MCPP:\n{0}".format(mcpp_msg_out))
            linter_result = mcpp_msg_out
            linter_result += "".join(str(x) + "\n" for x in fixed_output_lines)

            print("LINTER:\n" + linter_result)
        else:
            linter_result = Linter.communicate(self, cmd, code)

        # print("DEBUG:: Linter output: {0}".format(linter_result))
        # print('=== END LINTER DEBUG ===')
        return linter_result
Exemple #26
0
    def lint(self, code, view_has_changed):
        result = Linter.lint(self, code, view_has_changed)

        print('inside shellcheck')

        return result
    def __init__(self, view, syntax):
        """Initialize and load lc-community-server from settings if present."""

        Linter.__init__(self, view, syntax)