<reponame>un-noted/pre-commit-hooks
#!/usr/bin/env python
"""Wrapper script for oclint"""
#############################################################################
import os
import sys

from hooks.utils import ClangAnalyzerCmd


class OCLintCmd(ClangAnalyzerCmd):
    """Class for the OCLint command."""

    command = "oclint"
    lookbehind = "OCLint version "

    def __init__(self, args):
        super().__init__(self.command, self.lookbehind, args)
        self.parse_args(args)
        self.parse_ddash_args()

    def run(self):
        """Run OCLint and remove generated temporary files"""
        # Split text into an array of args that can be passed into oclint
        for filename in self.files:
            current_files = os.listdir(os.getcwd())
            self.run_command(filename)
            if self.returncode != 0:
                sys.stdout.buffer.write(self.stdout)
                self.returncode = 1
                sys.exit(self.returncode)
            self.parse_output()
            self.cleanup_files(current_files)

    def parse_output(self):
        """ oclint return code is usually wrong (github.com/oclint/oclint/issues/538)
        Figure out what it is based on stdout and return that instead
        """
        violations = b"FilesWithViolations=0" not in self.stdout
        compiler_errors = b"Compiler Errors" in self.stdout
        if violations or compiler_errors:
            output = self.stdout + self.stderr
            self.raise_error(b"OCLint Violations found", output)
        self.stdout = b""

    @staticmethod
    def cleanup_files(existing_files):
        """Delete the plist files that oclint generates."""
        new_files = os.listdir(os.getcwd())
        for filename in new_files:
            if filename not in existing_files and filename[-6:] == ".plist":
                os.remove(filename)


def main(argv=None):
    cmd = OCLintCmd(argv)
    cmd.run()


if __name__ == "__main__":
    main()

#!/usr/bin/env python
"""Wrapper script for oclint"""
#############################################################################
import os
import sys

from hooks.utils import ClangAnalyzerCmd


class OCLintCmd(ClangAnalyzerCmd):
    """Class for the OCLint command."""

    command = "oclint"
    lookbehind = "OCLint version "

    def __init__(self, args):
        super().__init__(self.command, self.lookbehind, args)
        self.parse_args(args)
        self.parse_ddash_args()

    def run(self):
        """Run OCLint and remove generated temporary files"""
        # Split text into an array of args that can be passed into oclint
        for filename in self.files:
            current_files = os.listdir(os.getcwd())
            self.run_command(filename)
            if self.returncode != 0:
                sys.stdout.buffer.write(self.stdout)
                self.returncode = 1
                sys.exit(self.returncode)
            self.parse_output()
            self.cleanup_files(current_files)

    def parse_output(self):
        """ oclint return code is usually wrong (github.com/oclint/oclint/issues/538)
        Figure out what it is based on stdout and return that instead
        """
        violations = b"FilesWithViolations=0" not in self.stdout
        compiler_errors = b"Compiler Errors" in self.stdout
        if violations or compiler_errors:
            output = self.stdout + self.stderr
            self.raise_error(b"OCLint Violations found", output)
        self.stdout = b""

    @staticmethod
    def cleanup_files(existing_files):
        """Delete the plist files that oclint generates."""
        new_files = os.listdir(os.getcwd())
        for filename in new_files:
            if filename not in existing_files and filename[-6:] == ".plist":
                os.remove(filename)


def main(argv=None):
    cmd = OCLintCmd(argv)
    cmd.run()


if __name__ == "__main__":
    main()
#!/usr/bin/env python Wrapper script for oclint ############################################################################# Class for the OCLint command. Run OCLint and remove generated temporary files # Split text into an array of args that can be passed into oclint oclint return code is usually wrong (github.com/oclint/oclint/issues/538)         Figure out what it is based on stdout and return that instead Delete the plist files that oclint generates.