def lint(files, config, **lintargs): log = lintargs['log'] if not reinstall_yamllint(): print(YAMLLINT_INSTALL_ERROR) return 1 binary = get_yamllint_binary() cmdargs = [which('python'), binary, '-f', 'parsable'] log.debug("Command: {}".format(' '.join(cmdargs))) config = config.copy() config['root'] = lintargs['root'] # Run any paths with a .yamllint file in the directory separately so # it gets picked up. This means only .yamllint files that live in # directories that are explicitly included will be considered. paths_by_config = defaultdict(list) for f in files: conf_files = get_ancestors_by_name('.yamllint', f, config['root']) paths_by_config[conf_files[0] if conf_files else 'default'].append(f) for conf_file, paths in paths_by_config.items(): run_process( config, gen_yamllint_args(cmdargs, conf_file=conf_file, paths=paths)) return results
def lint(files, config, **lintargs): log = lintargs["log"] log.debug("Version: {}".format(get_yamllint_version())) cmdargs = [ sys.executable, os.path.join(topsrcdir, "mach"), "python", "--", "-m", "yamllint", "-f", "parsable", ] log.debug("Command: {}".format(" ".join(cmdargs))) config = config.copy() config["root"] = lintargs["root"] # Run any paths with a .yamllint file in the directory separately so # it gets picked up. This means only .yamllint files that live in # directories that are explicitly included will be considered. paths_by_config = defaultdict(list) for f in files: conf_files = get_ancestors_by_name(".yamllint", f, config["root"]) paths_by_config[conf_files[0] if conf_files else "default"].append(f) for conf_file, paths in paths_by_config.items(): run_process( config, gen_yamllint_args(cmdargs, conf_file=conf_file, paths=paths)) return results
def lint(paths, config, **lintargs): binary = get_flake8_binary() cmdargs = [ binary, '--format', '{"path":"%(path)s","lineno":%(row)s,' '"column":%(col)s,"rule":"%(code)s","message":"%(text)s"}', ] # Run any paths with a .flake8 file in the directory separately so # it gets picked up. This means only .flake8 files that live in # directories that are explicitly included will be considered. # See bug 1277851 paths_by_config = defaultdict(list) for path in paths: configs = get_ancestors_by_name('.flake8', path, lintargs['root']) paths_by_config[os.pathsep. join(configs) if configs else 'default'].append(path) for configs, paths in paths_by_config.items(): cmd = cmdargs[:] if configs != 'default': configs = reversed(configs.split(os.pathsep)) cmd.extend(['--append-config={}'.format(c) for c in configs]) cmd.extend(paths) run_process(config, cmd) return results
def lint(paths, config, **lintargs): if not reinstall_flake8(): print(FLAKE8_INSTALL_ERROR) return 1 binary = get_flake8_binary() cmdargs = [ binary, '--format', '{"path":"%(path)s","lineno":%(row)s,' '"column":%(col)s,"rule":"%(code)s","message":"%(text)s"}', ] # Run any paths with a .flake8 file in the directory separately so # it gets picked up. This means only .flake8 files that live in # directories that are explicitly included will be considered. # See bug 1277851 paths_by_config = defaultdict(list) for path in paths: configs = get_ancestors_by_name('.flake8', path, lintargs['root']) paths_by_config[os.pathsep.join(configs) if configs else 'default'].append(path) for configs, paths in paths_by_config.items(): cmd = cmdargs[:] if configs != 'default': configs = reversed(configs.split(os.pathsep)) cmd.extend(['--append-config={}'.format(c) for c in configs]) cmd.extend(paths) run_process(config, cmd) return results
def lint(paths, config, **lintargs): # TODO don't store results in a global global results results = [] cmdargs = [ os.path.join(bindir, 'flake8'), '--format', '{"path":"%(path)s","lineno":%(row)s,' '"column":%(col)s,"rule":"%(code)s","message":"%(text)s"}', '--filename', ','.join(['*.{}'.format(e) for e in config['extensions']]), ] fix_cmdargs = [ os.path.join(bindir, 'autopep8'), '--global-config', os.path.join(lintargs['root'], '.flake8'), '--in-place', '--recursive', ] if 'exclude' in lintargs: fix_cmdargs.extend(['--exclude', ','.join(lintargs['exclude'])]) # Run any paths with a .flake8 file in the directory separately so # it gets picked up. This means only .flake8 files that live in # directories that are explicitly included will be considered. # See bug 1277851 paths_by_config = defaultdict(list) for path in paths: configs = get_ancestors_by_name('.flake8', path, lintargs['root']) paths_by_config[os.pathsep. join(configs) if configs else 'default'].append(path) for configs, paths in paths_by_config.items(): if lintargs.get('fix'): subprocess.call(fix_cmdargs + paths) cmd = cmdargs[:] if configs != 'default': configs = reversed(configs.split(os.pathsep)) cmd.extend(['--append-config={}'.format(c) for c in configs]) cmd.extend(paths) if run_process(config, cmd): break return results
def lint(paths, config, fix=None, **lintargs): log = lintargs["log"] cargo = get_cargo_binary(log) if not cargo: print(CARGO_NOT_FOUND) if "MOZ_AUTOMATION" in os.environ: return 1 return [] min_version_str = config.get("min_clippy_version") min_version = StrictVersion(min_version_str) actual_version = get_clippy_version(log, cargo) log.debug("Found version: {}. Minimal expected version: {}".format( actual_version, min_version)) if actual_version < min_version: print(CLIPPY_WRONG_VERSION.format(version=min_version_str)) return 1 cmd_args_clean = [cargo] cmd_args_clean.append("clean") cmd_args_common = ["--manifest-path"] cmd_args_clippy = [cargo] if fix: cmd_args_clippy += ["+nightly"] cmd_args_clippy += [ "clippy", "--message-format=json", ] if fix: cmd_args_clippy += ["--fix", "-Z", "unstable-options"] lock_files_to_delete = [] for p in paths: lock_file = os.path.join(p, "Cargo.lock") if not os.path.exists(lock_file): lock_files_to_delete.append(lock_file) results = [] for p in paths: # Quick sanity check of the paths if p.endswith("Cargo.toml"): print("Error: expects a directory or a rs file") print("Found {}".format(p)) return 1 for p in paths: onlyIn = [] path_conf = p log.debug("Path = {}".format(p)) if os.path.isfile(p): # We are dealing with a file. We remove the filename from the path # to find the closest Cargo file # We also store the name of the file to be able to filter out other # files built by the cargo p = os.path.dirname(p) onlyIn = path_conf if os.path.isdir(p): # Sometimes, clippy reports issues from other crates # Make sure that we don't display that either onlyIn = p cargo_files = get_ancestors_by_name("Cargo.toml", p, lintargs["root"]) p = cargo_files[0] log.debug("Path translated to = {}".format(p)) # Needs clean because of https://github.com/rust-lang/rust-clippy/issues/2604 clean_command = cmd_args_clean + cmd_args_common + [p] run_process(log, config, clean_command) # Create the actual clippy command base_command = cmd_args_clippy + cmd_args_common + [p] output = run_process(log, config, base_command) # Remove build artifacts created by clippy run_process(log, config, clean_command) results += parse_issues(log, config, output, p, onlyIn) # Remove Cargo.lock files created by clippy for lock_file in lock_files_to_delete: if os.path.exists(lock_file): os.remove(lock_file) return sorted(results, key=lambda issue: issue.path)
def lint(paths, config, fix=None, **lintargs): log = lintargs["log"] cargo = get_cargo_binary(log) if not cargo: print(CARGO_NOT_FOUND) if 'MOZ_AUTOMATION' in os.environ: return 1 return [] if not is_clippy_installed(cargo): print(CLIPPY_NOT_FOUND) if 'MOZ_AUTOMATION' in os.environ: return 1 return [] cmd_args_clean = [cargo] cmd_args_clean.append("clean") cmd_args_common = ["--manifest-path"] cmd_args_clippy = [ cargo, 'clippy', '--message-format=json', ] lock_files_to_delete = [] for p in paths: lock_file = os.path.join(p, 'Cargo.lock') if not os.path.exists(lock_file): lock_files_to_delete.append(lock_file) results = [] for p in paths: # Quick sanity check of the paths if p.endswith("Cargo.toml"): print("Error: expects a directory or a rs file") print("Found {}".format(p)) return 1 for p in paths: onlyIn = [] path_conf = p log.debug("Path = {}".format(p)) if os.path.isfile(p): # We are dealing with a file. We remove the filename from the path # to find the closest Cargo file # We also store the name of the file to be able to filter out other # files built by the cargo p = os.path.dirname(p) onlyIn = path_conf if os.path.isdir(p): # Sometimes, clippy reports issues from other crates # Make sure that we don't display that either onlyIn = p cargo_files = get_ancestors_by_name('Cargo.toml', p, lintargs['root']) p = cargo_files[0] log.debug("Path translated to = {}".format(p)) # Needs clean because of https://github.com/rust-lang/rust-clippy/issues/2604 clean_command = cmd_args_clean + cmd_args_common + [p] run_process(log, config, clean_command) # Create the actual clippy command base_command = cmd_args_clippy + cmd_args_common + [p] output = run_process(log, config, base_command) # Remove build artifacts created by clippy run_process(log, config, clean_command) results += parse_issues(log, config, output, p, onlyIn) # Remove Cargo.lock files created by clippy for lock_file in lock_files_to_delete: if os.path.exists(lock_file): os.remove(lock_file) return sorted(results, key=lambda issue: issue.path)