Skip to content
Browse files

tools: rewrite in python

As it is, does not show more helpful error messages,
and supporting various shells could be a problem. This patch rewrites
the same in Python.

This patch also enables in the linting process

PR-URL: #6105
Reviewed-By: Ben Noordhuis <>
Reviewed-By: Fedor Indutny <>
Reviewed-By: James M Snell <>
  • Loading branch information...
thefourtheye committed Apr 7, 2016
1 parent 75e073f commit 6781d917f49adfd5a00a7c251277ed9f971f3aee
Showing with 43 additions and 36 deletions.
  1. +1 −0 Makefile
  2. +42 −0 tools/
  3. +0 −36 tools/
@@ -639,6 +639,7 @@ CPPLINT_FILES = $(filter-out $(CPPLINT_EXCLUDE), $(wildcard \

@$(PYTHON) tools/

ifneq ("","$(wildcard tools/eslint/bin/eslint.js)")
lint: jslint cpplint
@@ -0,0 +1,42 @@
#!/usr/bin/env python

from __future__ import print_function
import glob
import re
import sys

def do_exist(file_name, lines, imported):
if not any(not re.match('using \w+::{0};'.format(imported), line) and, line) for line in lines):
print('File "{0}" does not use "{1}"'.format(file_name, imported))
return False
return True

def is_valid(file_name):
with open(file_name) as source_file:
lines = [line.strip() for line in source_file]

usings, importeds, line_numbers, valid = [], [], [], True
for idx, line in enumerate(lines, 1):
matches ='^using (\w+::(\w+));$', line)
if matches:

valid = all([do_exist(file_name, lines, imported) for imported in importeds])

sorted_usings = sorted(usings, key=lambda x: x.lower())
if sorted_usings != usings:
print("using statements aren't sorted in '{0}'.".format(file_name))
for num, actual, expected in zip(line_numbers, usings, sorted_usings):
if actual != expected:
print('\tLine {0}: Actual: {1}, Expected: {2}'
.format(num, actual, expected))
return False
return valid

sys.exit(0 if all(map(is_valid, glob.iglob('src/*.cc'))) else 1)

This file was deleted.

0 comments on commit 6781d91

Please sign in to comment.
You can’t perform that action at this time.