How to use pre-commit - 8 common examples

To help you get started, we’ve selected a few pre-commit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github asottile / git-code-debt / pre-commit.py View on Github external
return []

    def fix_file(self, file):
        '''Implement to fix the file.'''
        raise NotImplementedError

    def run(self):
        '''Runs the process to fix the files. Returns True if nothign to fix.'''
        print '%s...' % self.name
        all_files = self.get_all_files()
        for file in all_files:
            print 'Fixing %s' % file
            self.fix_file(file)
        return not all_files

class FixTrailingWhitespace(FixAllBase):
    name = 'Trimming trailing whitespace'
    matching_files_command = '%s | xargs egrep -l "[[:space:]]$"' % ALL_FILES

    def fix_file(self, file):
        subprocess.check_call(['sed', '-i', '-e', 's/[[:space:]]*$//', file])

class FixLineEndings(FixAllBase):
    name = 'Fixing line endings'
    matching_files_command = "%s | xargs egrep -l $'\\r'\\$" % ALL_FILES

    def fix_file(self, file):
        subprocess.check_call(['dos2unix', file])
        subprocess.check_call(['mac2unix', file])

FIXERS = [
    FixTrailingWhitespace,
github pre-commit / pre-commit / pre-commit.py View on Github external
'''Runs the process to fix the files. Returns True if nothign to fix.'''
        print '%s...' % self.name
        all_files = self.get_all_files()
        for file in all_files:
            print 'Fixing %s' % file
            self.fix_file(file)
        return not all_files

class FixTrailingWhitespace(FixAllBase):
    name = 'Trimming trailing whitespace'
    matching_files_command = '%s | xargs egrep -l "[[:space:]]$"' % ALL_FILES

    def fix_file(self, file):
        subprocess.check_call(['sed', '-i', '-e', 's/[[:space:]]*$//', file])

class FixLineEndings(FixAllBase):
    name = 'Fixing line endings'
    matching_files_command = "%s | xargs egrep -l $'\\r'\\$" % ALL_FILES

    def fix_file(self, file):
        subprocess.check_call(['dos2unix', file])
        subprocess.check_call(['mac2unix', file])

FIXERS = [
    FixTrailingWhitespace,
    FixLineEndings,
]

def run_tests():
    passed = True
    for test in TESTS:
        run_test = get_git_config('hooks.%s' % test.config)
github pre-commit / pre-commit / pre-commit.py View on Github external
return []

    def fix_file(self, file):
        '''Implement to fix the file.'''
        raise NotImplementedError

    def run(self):
        '''Runs the process to fix the files. Returns True if nothign to fix.'''
        print '%s...' % self.name
        all_files = self.get_all_files()
        for file in all_files:
            print 'Fixing %s' % file
            self.fix_file(file)
        return not all_files

class FixTrailingWhitespace(FixAllBase):
    name = 'Trimming trailing whitespace'
    matching_files_command = '%s | xargs egrep -l "[[:space:]]$"' % ALL_FILES

    def fix_file(self, file):
        subprocess.check_call(['sed', '-i', '-e', 's/[[:space:]]*$//', file])

class FixLineEndings(FixAllBase):
    name = 'Fixing line endings'
    matching_files_command = "%s | xargs egrep -l $'\\r'\\$" % ALL_FILES

    def fix_file(self, file):
        subprocess.check_call(['dos2unix', file])
        subprocess.check_call(['mac2unix', file])

FIXERS = [
    FixTrailingWhitespace,
github asottile / git-code-debt / pre-commit.py View on Github external
'''Runs the process to fix the files. Returns True if nothign to fix.'''
        print '%s...' % self.name
        all_files = self.get_all_files()
        for file in all_files:
            print 'Fixing %s' % file
            self.fix_file(file)
        return not all_files

class FixTrailingWhitespace(FixAllBase):
    name = 'Trimming trailing whitespace'
    matching_files_command = '%s | xargs egrep -l "[[:space:]]$"' % ALL_FILES

    def fix_file(self, file):
        subprocess.check_call(['sed', '-i', '-e', 's/[[:space:]]*$//', file])

class FixLineEndings(FixAllBase):
    name = 'Fixing line endings'
    matching_files_command = "%s | xargs egrep -l $'\\r'\\$" % ALL_FILES

    def fix_file(self, file):
        subprocess.check_call(['dos2unix', file])
        subprocess.check_call(['mac2unix', file])

FIXERS = [
    FixTrailingWhitespace,
    FixLineEndings,
]

def run_tests():
    passed = True
    for test in TESTS:
        run_test = get_git_config('hooks.%s' % test.config)
github asottile / git-code-debt / pre-commit.py View on Github external
matching_files_command = '%s | xargs egrep -l "[[:space:]]$"' % ALL_FILES

    def fix_file(self, file):
        subprocess.check_call(['sed', '-i', '-e', 's/[[:space:]]*$//', file])

class FixLineEndings(FixAllBase):
    name = 'Fixing line endings'
    matching_files_command = "%s | xargs egrep -l $'\\r'\\$" % ALL_FILES

    def fix_file(self, file):
        subprocess.check_call(['dos2unix', file])
        subprocess.check_call(['mac2unix', file])

FIXERS = [
    FixTrailingWhitespace,
    FixLineEndings,
]

def run_tests():
    passed = True
    for test in TESTS:
        run_test = get_git_config('hooks.%s' % test.config)
        if run_test == 'false':
            print 'Skipping "%s" due to git config.' % test.name
            continue

        try:
            retcode = 0
            output = subprocess.check_output(
                test.command, shell=True, stderr=subprocess.STDOUT
            )
        except subprocess.CalledProcessError as e:
github pre-commit / pre-commit / pre-commit.py View on Github external
matching_files_command = '%s | xargs egrep -l "[[:space:]]$"' % ALL_FILES

    def fix_file(self, file):
        subprocess.check_call(['sed', '-i', '-e', 's/[[:space:]]*$//', file])

class FixLineEndings(FixAllBase):
    name = 'Fixing line endings'
    matching_files_command = "%s | xargs egrep -l $'\\r'\\$" % ALL_FILES

    def fix_file(self, file):
        subprocess.check_call(['dos2unix', file])
        subprocess.check_call(['mac2unix', file])

FIXERS = [
    FixTrailingWhitespace,
    FixLineEndings,
]

def run_tests():
    passed = True
    for test in TESTS:
        run_test = get_git_config('hooks.%s' % test.config)
        if run_test == 'false':
            print 'Skipping "%s" due to git config.' % test.name
            continue

        try:
            retcode = 0
            output = subprocess.check_output(
                test.command, shell=True, stderr=subprocess.STDOUT
            )
        except subprocess.CalledProcessError as e:
github asottile / git-code-debt / pre-commit.py View on Github external
name = 'Trimming trailing whitespace'
    matching_files_command = '%s | xargs egrep -l "[[:space:]]$"' % ALL_FILES

    def fix_file(self, file):
        subprocess.check_call(['sed', '-i', '-e', 's/[[:space:]]*$//', file])

class FixLineEndings(FixAllBase):
    name = 'Fixing line endings'
    matching_files_command = "%s | xargs egrep -l $'\\r'\\$" % ALL_FILES

    def fix_file(self, file):
        subprocess.check_call(['dos2unix', file])
        subprocess.check_call(['mac2unix', file])

FIXERS = [
    FixTrailingWhitespace,
    FixLineEndings,
]

def run_tests():
    passed = True
    for test in TESTS:
        run_test = get_git_config('hooks.%s' % test.config)
        if run_test == 'false':
            print 'Skipping "%s" due to git config.' % test.name
            continue

        try:
            retcode = 0
            output = subprocess.check_output(
                test.command, shell=True, stderr=subprocess.STDOUT
            )
github pre-commit / pre-commit / pre-commit.py View on Github external
name = 'Trimming trailing whitespace'
    matching_files_command = '%s | xargs egrep -l "[[:space:]]$"' % ALL_FILES

    def fix_file(self, file):
        subprocess.check_call(['sed', '-i', '-e', 's/[[:space:]]*$//', file])

class FixLineEndings(FixAllBase):
    name = 'Fixing line endings'
    matching_files_command = "%s | xargs egrep -l $'\\r'\\$" % ALL_FILES

    def fix_file(self, file):
        subprocess.check_call(['dos2unix', file])
        subprocess.check_call(['mac2unix', file])

FIXERS = [
    FixTrailingWhitespace,
    FixLineEndings,
]

def run_tests():
    passed = True
    for test in TESTS:
        run_test = get_git_config('hooks.%s' % test.config)
        if run_test == 'false':
            print 'Skipping "%s" due to git config.' % test.name
            continue

        try:
            retcode = 0
            output = subprocess.check_output(
                test.command, shell=True, stderr=subprocess.STDOUT
            )

pre-commit

A framework for managing and maintaining multi-language pre-commit hooks.

MIT
Latest version published 3 months ago

Package Health Score

94 / 100
Full package analysis