示例#1
0
文件: run.py 项目: blueyed/dodgy
def run_checks(directory, ignore_paths=None):
    warnings = []

    ignore_paths = ignore_paths or []
    ignore_paths = [re.compile(patt) for patt in ignore_paths]
    ignore_paths += IGNORE_PATHS

    filepaths = list_files(directory)
    for filepath in filepaths:
        relpath = os.path.relpath(filepath, directory)
        if any([ignore.search(relpath) for ignore in ignore_paths]):
            continue

        # this is a naive check to skip binary files, it's probably okay for now
        mimetype = mimetypes.guess_type(filepath)
        if mimetype[0] is None or not mimetype[0].startswith('text/'):
            continue

        for msg_parts in check_file(filepath):
            warnings.append({
                'path': relpath,
                'line': msg_parts[0],
                'code': msg_parts[1],
                'message': msg_parts[2]
            })

    return warnings
示例#2
0
文件: run.py 项目: Liam-Deacon/dodgy
def run_checks(directory, ignore_paths=None):
    warnings = []

    ignore_paths = ignore_paths or []
    ignore_paths = [re.compile(patt) for patt in ignore_paths]
    ignore_paths += IGNORE_PATHS

    filepaths = list_files(directory)
    for filepath in filepaths:
        relpath = os.path.relpath(filepath, directory)
        if any([ignore.search(relpath) for ignore in ignore_paths]):
            continue

        # this is a naive check to skip binary files, it's probably okay for now
        mimetype = mimetypes.guess_type(filepath)
        if mimetype[0] is None or not mimetype[0].startswith('text/'):
            continue

        try:
            for msg_parts in check_file(filepath):
                warnings.append({
                    'path': relpath,
                    'line': msg_parts[0],
                    'code': msg_parts[1],
                    'message': msg_parts[2]
                })
        except UnicodeDecodeError as err:
            # This is a file which cannot be opened using codecs with UTF-8
            print('Unable to read {!r}: {}'.format(filepath, err))

    return warnings
示例#3
0
文件: run.py 项目: blueyed/dodgy
def run_checks(directory, ignore_paths=None):
    warnings = []

    ignore_paths = ignore_paths or []
    ignore_paths = [re.compile(patt) for patt in ignore_paths]
    ignore_paths += IGNORE_PATHS

    filepaths = list_files(directory)
    for filepath in filepaths:
        relpath = os.path.relpath(filepath, directory)
        if any([ignore.search(relpath) for ignore in ignore_paths]):
            continue

        # this is a naive check to skip binary files, it's probably okay for now
        mimetype = mimetypes.guess_type(filepath)
        if mimetype[0] is None or not mimetype[0].startswith('text/'):
            continue

        for msg_parts in check_file(filepath):
            warnings.append({
                'path': relpath,
                'line': msg_parts[0],
                'code': msg_parts[1],
                'message': msg_parts[2]
            })

    return warnings
示例#4
0
 def _run_checks(self, file_name):
     filepath = os.path.join(os.path.dirname(__file__), 'testdata', file_name)
     return check_file(filepath)
示例#5
0
 def _run_checks(self, file_name):
     filepath = os.path.join(os.path.dirname(__file__), 'testdata',
                             file_name)
     return check_file(filepath)