示例#1
0
    def process_files(self, files):
        """
        Run code checks with pep8.
        Only a single process is made for all files
        to save resources.
        """
        command = self.create_command()
        command += map(lambda f: docker.apply_base(f), files)

        output = docker.run('nodejs', command, source_dir=self.base_path)
        if not output:
            return False
        output = output.split("\n")
        filename = None
        # The output from remarklint is a unique format that looks like:
        #
        # >>> file.md
        # >>>   1:1-1:8 warning Some warning
        #
        # We inspect each line to determine if it is a file or warning.
        for line in output:
            if filename_pattern.match(line):
                # Remove the base path as remarklint is fed absolute paths.
                filename = docker.strip_base(line)
            else:
                match = warning_pattern.match(line)
                if match:
                    line = match.group('line')
                    text = match.group('text')
                    self.problems.add(filename, line, text)
示例#2
0
    def _process_output(self, output):
        """
        Process goodcheck json results.

        Where `output` is a line containing check results, formatted like:
            [{"rule_id":"<id>","path":"<filename>",
              "location":{"start_line":<line>,"start_column":<col>,
                          "end_line":<endline>,"end_column":<endcol>},
              "message":"<message>",
              "justifications":[]}]
        """
        try:
            results = json.loads(output)
        except ValueError:
            log.debug('Failed to load JSON data from goodcheck output %r',
                      output)
            results = []

        for result in results:
            filename = docker.strip_base(result['path'])
            comment = result['message']

            add_justifications = self.options.get(
                'add_justifications_to_comments', False)
            if (result['justifications'] and add_justifications):
                comment += "\n\n - " + "\n - ".join(result['justifications'])

            self.problems.add(filename,
                              line=int(result['location']['start_line']),
                              body=comment)
示例#3
0
    def process_files(self, files):
        """
        Run code checks with pep8.
        Only a single process is made for all files
        to save resources.
        """
        log.debug('Processing %s files with %s', files, self.name)
        command = self.create_command()
        command += map(lambda f: docker.apply_base(f), files)

        output = docker.run('nodejs', command, source_dir=self.base_path)
        if not output:
            return False
        output = output.split("\n")
        filename = None
        # The output from remarklint is a unique format that looks like:
        #
        # >>> file.md
        # >>>   1:1-1:8 warning Some warning
        #
        # We inspect each line to determine if it is a file or warning.
        for line in output:
            if filename_pattern.match(line):
                # Remove the base path as remarklint is fed absolute paths.
                filename = docker.strip_base(line)
            else:
                match = warning_pattern.match(line)
                if match:
                    line = match.group('line')
                    text = match.group('text')
                    self.problems.add(filename, line, text)
示例#4
0
    def process_files(self, files):
        """
        Run code checks with black.
        Only a single process is made for all files to save resources.
        """
        log.debug('Processing %s files with %s', files, self.name)
        command = self.create_command()
        command.append('--check')
        command += files

        output = docker.run('python3', command, source_dir=self.base_path)
        if not output:
            return False
        output = output.split("\n")

        effected_files = [
            '* ' + docker.strip_base(line.replace('would reformat ', ''))
            for line in output
            if line.startswith('would reformat')
        ]
        if len(effected_files):
            msg = (
                'The following files do not match the `black` styleguide:'
                '\n\n'
            )
            msg += "\n".join(effected_files)
            self.problems.add(IssueComment(msg))
示例#5
0
    def parse_output(self, output):
        """
        Pytype has is own output format that is not machine readable, so we use
        regex and string contains to munge it into something usable. The output looks like

        ```
        Computing dependencies
        Analyzing 1 sources with 0 local dependencies
        ninja: Entering directory `/src/.pytype'
        [1/1] check has_errors
        FAILED: /src/.pytype/pyi/has_errors.pyi
        pytype-single --imports_info /src/.pytype/imports/has_errors.imports ...
        File "../pytype/has_errors.py", line 5, in get_username: message text [attribute-error]
          In Optional[Match[str]]
        File "../pytype/has_errors.py", line 8, in <module>: message text: '1' [bad-slots]
        ```

        We use regex to slice out the file, line and message information.
        """
        message = ''
        lineno = 0
        filename = ''

        message_pattern = re.compile(
            r'File "(?P<file>[^"]+)",\s+line\s+(?P<line>\d+),[^:]+\:\s+(?P<message>.*)'
        )
        lines = output.split('\n')
        if len(lines) and lines[0].startswith('CRITICAL'):
            message = (
                u"Pytype failed with the following error:\n"
                "```\n"
                "{}\n"
                "```\n"
            )
            self.problems.add(IssueComment(message.format("\n".join(lines))))

        for line in output.split("\n"):
            # Some errors have continuations on subsequent lines
            if len(message) and not line.startswith('File'):
                message = message + ' ' + line.strip()
                continue
            if line.startswith('File '):
                # Starting a new message append to the error list.
                if filename and message:
                    self.problems.add(filename, lineno, message)
                    filename = ''
                    lineno = 0
                    message = ''

                matches = message_pattern.match(line)

                lineno = int(matches.group('line'))
                filename = docker.strip_base(matches.group('file'))
                message = matches.group('message')
        if filename and message:
            self.problems.add(filename, lineno, message)
示例#6
0
    def parse_output(self, output):
        """
        Pytype has is own output format that is not machine readable, so we use
        regex and string contains to munge it into something usable. The output looks like

        ```
        Computing dependencies
        Analyzing 1 sources with 0 local dependencies
        ninja: Entering directory `/src/.pytype'
        [1/1] check has_errors
        FAILED: /src/.pytype/pyi/has_errors.pyi
        pytype-single --imports_info /src/.pytype/imports/has_errors.imports ...
        File "../pytype/has_errors.py", line 5, in get_username: message text [attribute-error]
          In Optional[Match[str]]
        File "../pytype/has_errors.py", line 8, in <module>: message text: '1' [bad-slots]
        ```

        We use regex to slice out the file, line and message information.
        """
        message = ''
        lineno = 0
        filename = ''

        message_pattern = re.compile(
            r'File "(?P<file>[^"]+)",\s+line\s+(?P<line>\d+),[^:]+\:\s+(?P<message>.*)'
        )
        lines = output.split('\n')
        if len(lines) and lines[0].startswith('CRITICAL'):
            message = (u"Pytype failed with the following error:\n"
                       "```\n"
                       "{}\n"
                       "```\n")
            self.problems.add(IssueComment(message.format("\n".join(lines))))

        for line in output.split("\n"):
            # Some errors have continuations on subsequent lines
            if len(message) and not line.startswith('File'):
                message = message + ' ' + line.strip()
                continue
            if line.startswith('File '):
                # Starting a new message append to the error list.
                if filename and message:
                    self.problems.add(filename, lineno, message)
                    filename = ''
                    lineno = 0
                    message = ''

                matches = message_pattern.match(line)

                lineno = int(matches.group('line'))
                filename = docker.strip_base(matches.group('file'))
                message = matches.group('message')
        if filename and message:
            self.problems.add(filename, lineno, message)
示例#7
0
    def _parse_line(self, line):
        """
        foodcritic only generates results as stdout.
        Parse the output for real data.
        """
        parts = line.split(': ')

        filename = parts[2].split(':')[0].strip()
        filename = docker.strip_base(filename)

        line = int(parts[2].split(':')[1])
        message = ': '.join(parts[:2]).strip()
        return (filename, line, message)
示例#8
0
    def _parse_line(self, line):
        """
        foodcritic only generates results as stdout.
        Parse the output for real data.
        """
        log.debug('Line: %s' % line)
        parts = line.split(': ')

        filename = parts[2].split(':')[0].strip()
        filename = docker.strip_base(filename)

        line = int(parts[2].split(':')[1])
        message = ': '.join(parts[:2]).strip()
        return (filename, line, message)
示例#9
0
    def _process_output(self, output):
        """The checkstyle output from csslint is not
        reliable for large results so we use compact format which looks like:

        <filepath>: line 1 col 1, <message>
        """
        pattern = re.compile(r'^(?P<path>[^:]+):\s+line\s+(?P<line>\d+),'
                             r'(?:.*?),\s(?P<message>.*)')
        for line in output.splitlines():
            match = pattern.match(line)
            if not match:
                continue
            filename = docker.strip_base(match.group('path'))
            line = int(match.group('line'))
            message = match.group('message').strip()
            self.problems.add(filename, line, message)
示例#10
0
    def _process_output(self, output):
        """The checkstyle output from csslint is not
        reliable for large results so we use compact format which looks like:

        <filepath>: line 1 col 1, <message>
        """
        pattern = re.compile(
                r'^(?P<path>[^:]+):\s+line\s+(?P<line>\d+),'
                r'(?:.*?),\s(?P<message>.*)'
        )
        for line in output.splitlines():
            match = pattern.match(line)
            if not match:
                continue
            filename = docker.strip_base(match.group('path'))
            line = int(match.group('line'))
            message = match.group('message').strip()
            self.problems.add(filename, line, message)
示例#11
0
    def process_files(self, files):
        """
        Run code checks with black.
        Only a single process is made for all files to save resources.
        """
        command = self.create_command()
        command.append('--check')
        command += files

        output = docker.run('python3', command, source_dir=self.base_path)
        if not output:
            return False
        output = output.split("\n")

        effected_files = [
            '* ' + docker.strip_base(line.replace('would reformat ', ''))
            for line in output if line.startswith('would reformat')
        ]
        if len(effected_files):
            msg = ('The following files do not match the `black` styleguide:'
                   '\n\n')
            msg += "\n".join(effected_files)
            self.problems.add(IssueComment(msg))
示例#12
0
 def test_strip_base(self):
     self.assertEqual('some/thing.py',
                      docker.strip_base('/src/some/thing.py'))
     self.assertEqual('some/thing.py', docker.strip_base('some/thing.py'))
     self.assertEqual('some/src/thing.py',
                      docker.strip_base('some/src/thing.py'))
示例#13
0
def test_strip_base():
    eq_('some/thing.py', docker.strip_base('/src/some/thing.py'))
    eq_('some/thing.py', docker.strip_base('some/thing.py'))
    eq_('some/src/thing.py', docker.strip_base('some/src/thing.py'))
示例#14
0
 def test_strip_base(self):
     self.assertEqual('some/thing.py',
                      docker.strip_base('/src/some/thing.py'))
     self.assertEqual('some/thing.py', docker.strip_base('some/thing.py'))
     self.assertEqual('some/src/thing.py',
                      docker.strip_base('some/src/thing.py'))