def run(paths, linters, fmt, outgoing, workdir, edit, list_linters=None, **lintargs): from mozlint import LintRoller, formatters from mozlint.editor import edit_results if list_linters: lint_paths = find_linters(linters) print("Available linters: {}".format( [os.path.splitext(os.path.basename(l))[0] for l in lint_paths] )) return 0 lint = LintRoller(**lintargs) lint.read(find_linters(linters)) # run all linters results = lint.roll(paths, outgoing=outgoing, workdir=workdir) if edit and results: edit_results(results) results = lint.roll(results.keys()) formatter = formatters.get(fmt) # Encode output with 'replace' to avoid UnicodeEncodeErrors on # environments that aren't using utf-8. out = formatter(results, failed=lint.failed).encode( sys.stdout.encoding or 'ascii', 'replace') if out: print(out) return 1 if results or lint.failed else 0
def run(paths, linters, formats, outgoing, workdir, edit, setup=False, list_linters=False, num_procs=None, **lintargs): from mozlint import LintRoller, formatters from mozlint.editor import edit_issues if list_linters: lint_paths = find_linters(linters) print("Available linters: {}".format( [os.path.splitext(os.path.basename(l))[0] for l in lint_paths])) return 0 lint = LintRoller(**lintargs) lint.read(find_linters(linters)) # Always run bootstrapping, but return early if --setup was passed in. ret = lint.setup() if setup: return ret # run all linters result = lint.roll(paths, outgoing=outgoing, workdir=workdir, num_procs=num_procs) if edit and result.issues: edit_issues(result) result = lint.roll(result.issues.keys(), num_procs=num_procs) for formatter_name, path in formats: formatter = formatters.get(formatter_name) out = formatter(result) if out: fh = open(path, 'w') if path else sys.stdout if not path and fh.encoding == 'ascii': # If sys.stdout.encoding is ascii, printing output will fail # due to the stylish formatter's use of unicode characters. # Ideally the user should fix their environment by setting # `LC_ALL=C.UTF-8` or similar. But this is a common enough # problem that we help them out a little here by manually # encoding and writing to the stdout buffer directly. out += '\n' fh.buffer.write(out.encode('utf-8', errors='replace')) fh.buffer.flush() else: print(out, file=fh) return result.returncode
def lint_setup(self, linters=None, **lintargs): from mozlint import LintRoller lint_files = self.find_linters(linters) lint = LintRoller(lintargs=lintargs) lint.read(lint_files) for l in lint.linters: if 'setup' in l: l['setup']()
def run(paths, linters, fmt, rev, workdir, **lintargs): from mozlint import LintRoller, formatters lint = LintRoller(**lintargs) lint.read(find_linters(linters)) # run all linters results = lint.roll(paths, rev=rev, workdir=workdir) formatter = formatters.get(fmt) print(formatter(results)) return 1 if results else 0
def lint(request): lintargs = getattr(request.module, "lintargs", {}) lint = LintRoller(root=here, **lintargs) # Add a few super powers to our lint instance def mock_vcs(files): def _fake_vcs_files(*args, **kwargs): return files setattr(lint.vcs, "get_changed_files", _fake_vcs_files) setattr(lint.vcs, "get_outgoing_files", _fake_vcs_files) setattr(lint, "vcs", Namespace()) setattr(lint, "mock_vcs", mock_vcs) return lint
def run(paths, linters, formats, outgoing, workdir, edit, setup=False, list_linters=False, **lintargs): from mozlint import LintRoller, formatters from mozlint.editor import edit_issues if list_linters: lint_paths = find_linters(linters) print("Available linters: {}".format( [os.path.splitext(os.path.basename(l))[0] for l in lint_paths])) return 0 lint = LintRoller(**lintargs) lint.read(find_linters(linters)) # Always run bootstrapping, but return early if --setup was passed in. ret = lint.setup() if setup: return ret # run all linters result = lint.roll(paths, outgoing=outgoing, workdir=workdir) if edit and result.issues: edit_issues(result) result = lint.roll(result.issues.keys()) for formatter_name, path in formats: formatter = formatters.get(formatter_name) out = formatter(result) if sys.version_info[0] == 2: # Encode output with 'replace' to avoid UnicodeEncodeErrors on # environments that aren't using utf-8. out = formatter(result).encode(sys.stdout.encoding or 'ascii', 'replace') if out: output_file = open(path, 'w') if path else sys.stdout print(out, file=output_file) return result.returncode
def run(paths, linters, fmt, rev, workdir, **lintargs): from mozlint import LintRoller, formatters lint = LintRoller(**lintargs) lint.read(find_linters(linters)) # run all linters results = lint.roll(paths, rev=rev, workdir=workdir) formatter = formatters.get(fmt) # Encode output with 'replace' to avoid UnicodeEncodeErrors on # environments that aren't using utf-8. print(formatter(results, failed=lint.failed).encode( sys.stdout.encoding or 'ascii', 'replace')) return 1 if results or lint.failed else 0
def run(paths, linters, fmt, rev, workdir, **lintargs): from mozlint import LintRoller, formatters lint = LintRoller(**lintargs) lint.read(find_linters(linters)) # run all linters results = lint.roll(paths, rev=rev, workdir=workdir) formatter = formatters.get(fmt) # Explicitly utf-8 encode the output as some of the formatters make # use of unicode characters. This will prevent a UnicodeEncodeError # on environments where utf-8 isn't the default print(formatter(results).encode('utf-8', 'replace')) return lint.return_code
def lint(self, paths, linters=None, fmt='stylish', **lintargs): """Run linters.""" from mozlint import LintRoller, formatters paths = paths or ['.'] lint_files = self.find_linters(linters) lintargs['exclude'] = ['obj*'] lint = LintRoller(**lintargs) lint.read(lint_files) # run all linters results = lint.roll(paths) formatter = formatters.get(fmt) print(formatter(results))
def run(paths, linters, fmt, outgoing, workdir, edit, list_linters=None, **lintargs): from mozlint import LintRoller, formatters if list_linters: lint_paths = find_linters(linters) print("Available linters: {}".format( [os.path.splitext(os.path.basename(l))[0] for l in lint_paths])) return 0 lint = LintRoller(**lintargs) lint.read(find_linters(linters)) # Check if the path that is entered is a valid one. invalid_paths = [path for path in paths if not os.path.exists(path)] if invalid_paths: print("Error: The following paths do not exist:\n{}".format( "\n".join(invalid_paths))) return 1 # run all linters results = lint.roll(paths, outgoing=outgoing, workdir=workdir) if edit: editor = os.environ['EDITOR'] for path in results: subprocess.call([editor, path]) return 1 if lint.failed else 0 formatter = formatters.get(fmt) # Encode output with 'replace' to avoid UnicodeEncodeErrors on # environments that aren't using utf-8. out = formatter(results, failed=lint.failed).encode(sys.stdout.encoding or 'ascii', 'replace') if out: print(out) return 1 if results or lint.failed else 0
def run(paths, linters, fmt, rev, workdir, **lintargs): from mozlint import LintRoller, formatters # Calculate files from VCS vcfiles = VCFiles() if rev: paths.extend(vcfiles.by_rev(rev)) if workdir: paths.extend(vcfiles.by_workdir()) paths = paths or ['.'] lint = LintRoller(**lintargs) lint.read(find_linters(linters)) # run all linters results = lint.roll(paths) formatter = formatters.get(fmt) print(formatter(results)) return 1 if results else 0
def setUp(self): TestCase.setUp(self) self.lint = LintRoller()
def run( paths, linters, formats, outgoing, workdir, rev, edit, check_exclude_list, setup=False, list_linters=False, num_procs=None, virtualenv_manager=None, **lintargs ): from mozlint import LintRoller, formatters from mozlint.editor import edit_issues lintargs["config_paths"] = [ os.path.join(lintargs["root"], p) for p in lintargs["config_paths"] ] # Always perform exhaustive linting for exclude list paths lintargs["use_filters"] = lintargs["use_filters"] and not check_exclude_list if list_linters: lint_paths = find_linters(lintargs["config_paths"], linters) linters = [ os.path.splitext(os.path.basename(l))[0] for l in lint_paths["lint_paths"] ] print("\n".join(sorted(linters))) return 0 lint = LintRoller(**lintargs) linters_info = find_linters(lintargs["config_paths"], linters) result = None try: lint.read(linters_info["lint_paths"]) if check_exclude_list: if len(lint.linters) > 1: print("error: specify a single linter to check with `-l/--linter`") return 1 paths = lint.linters[0]["local_exclude"] if ( not linters and not paths and os.getcwd() == lint.root and not (outgoing or workdir) ): print( "warning: linting the entire repo takes a long time, using --outgoing and " "--workdir instead. If you want to lint the entire repo, run `./mach lint .`" ) # Setting the default values outgoing = "default" workdir = "all" # Always run bootstrapping, but return early if --setup was passed in. ret = lint.setup(virtualenv_manager=virtualenv_manager) if setup: return ret if linters_info["linters_not_found"] != []: raise NoValidLinter # run all linters result = lint.roll( paths, outgoing=outgoing, workdir=workdir, rev=rev, num_procs=num_procs ) except NoValidLinter as e: result = lint.result print(str(e)) if edit and result.issues: edit_issues(result) result = lint.roll(result.issues.keys(), num_procs=num_procs) for every in linters_info["linters_not_found"]: result.failed_setup.add(every) if check_exclude_list: # Get and display all those paths in the exclude list which are # now green and can be safely removed from the list out = get_exclude_list_output(result, paths) print(out, file=sys.stdout) return result.returncode for formatter_name, path in formats: formatter = formatters.get(formatter_name) out = formatter(result) if out: fh = open(path, "w") if path else sys.stdout if not path and fh.encoding == "ascii": # If sys.stdout.encoding is ascii, printing output will fail # due to the stylish formatter's use of unicode characters. # Ideally the user should fix their environment by setting # `LC_ALL=C.UTF-8` or similar. But this is a common enough # problem that we help them out a little here by manually # encoding and writing to the stdout buffer directly. out += "\n" fh.buffer.write(out.encode("utf-8", errors="replace")) fh.buffer.flush() else: print(out, file=fh) return result.returncode
def setUp(self): TestCase.setUp(self) self.lint = LintRoller(root=here)
def lint(request): lintargs = getattr(request.module, 'lintargs', {}) return LintRoller(root=here, **lintargs)
def run( paths, linters, formats, outgoing, workdir, rev, edit, setup=False, list_linters=False, num_procs=None, virtualenv_manager=None, **lintargs ): from mozlint import LintRoller, formatters from mozlint.editor import edit_issues lintargs["config_paths"] = [ os.path.join(lintargs["root"], p) for p in lintargs["config_paths"] ] if list_linters: lint_paths = find_linters(lintargs["config_paths"], linters) linters = [ os.path.splitext(os.path.basename(l))[0] for l in lint_paths["lint_paths"] ] print("\n".join(sorted(linters))) return 0 lint = LintRoller(**lintargs) linters_info = find_linters(lintargs["config_paths"], linters) result = None try: lint.read(linters_info["lint_paths"]) # Always run bootstrapping, but return early if --setup was passed in. ret = lint.setup(virtualenv_manager=virtualenv_manager) if setup: return ret if linters_info["linters_not_found"] != []: raise NoValidLinter # run all linters result = lint.roll( paths, outgoing=outgoing, workdir=workdir, rev=rev, num_procs=num_procs ) except NoValidLinter as e: result = lint.result print(str(e)) if edit and result.issues: edit_issues(result) result = lint.roll(result.issues.keys(), num_procs=num_procs) for every in linters_info["linters_not_found"]: result.failed_setup.add(every) for formatter_name, path in formats: formatter = formatters.get(formatter_name) out = formatter(result) if out: fh = open(path, "w") if path else sys.stdout if not path and fh.encoding == "ascii": # If sys.stdout.encoding is ascii, printing output will fail # due to the stylish formatter's use of unicode characters. # Ideally the user should fix their environment by setting # `LC_ALL=C.UTF-8` or similar. But this is a common enough # problem that we help them out a little here by manually # encoding and writing to the stdout buffer directly. out += "\n" fh.buffer.write(out.encode("utf-8", errors="replace")) fh.buffer.flush() else: print(out, file=fh) return result.returncode