From bd0fd2619cc9be4e517733c03161b5373a4b0fa3 Mon Sep 17 00:00:00 2001 From: Matej Ferencevic Date: Thu, 13 Feb 2020 11:38:32 +0100 Subject: [PATCH] Add cppcheck and clang-format arc linters Reviewers: teon.banek Reviewed By: teon.banek Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2670 --- .arclint | 12 ++++++++++++ init | 1 + tools/arc-clang-format | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100755 tools/arc-clang-format diff --git a/.arclint b/.arclint index 14cde4712..c81f67d47 100644 --- a/.arclint +++ b/.arclint @@ -2,8 +2,20 @@ "linters": { "clang-tidy": { "type": "script-and-regex", + "include": "(\\.(cpp|cc|cxx|c|h|hpp|lcp)$)", "script-and-regex.script": "./tools/arc-clang-tidy", "script-and-regex.regex": "/^(?P.*):(?P\\d+):(?P\\d+): (?Pwarning|error): (?P.*)$/m" + }, + "cppcheck": { + "type": "cppcheck", + "include": "(\\.(cpp|cc|cxx)$)", + "flags": ["--suppress=useStlAlgorithm"] + }, + "clang-format": { + "type": "script-and-regex", + "include": "(\\.(cpp|cc|cxx|c|h|hpp)$)", + "script-and-regex.script": "./tools/arc-clang-format", + "script-and-regex.regex": "/^(?Pwarning):(?P\\d+):(?P.*)$/m" } } } diff --git a/init b/init index e0f41d36b..c0ed67468 100755 --- a/init +++ b/init @@ -12,6 +12,7 @@ required_pkgs=(git arcanist # source code control uuid-dev # mg-utils libcurl4-openssl-dev # mg-requests sbcl # for custom Lisp C++ preprocessing + php-xml # for arcanist linters ) optional_pkgs=(doxygen graphviz # source documentation generators diff --git a/tools/arc-clang-format b/tools/arc-clang-format new file mode 100755 index 000000000..3d054a58c --- /dev/null +++ b/tools/arc-clang-format @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 +import re +import sys +import subprocess + +# Run this script through arc lint + +MESSAGE = "Wrong formatting!" + +data = subprocess.run( + ["clang-format", "--output-replacements-xml", sys.argv[1]], + stdout=subprocess.PIPE, check=True).stdout.decode( + "utf-8").strip().split("\n") +for row in data: + match = re.match( + r"^", row) + if match: + offset = int(match.group(1)) + int(match.group(2)) + print("warning:{}:{}".format(offset, MESSAGE))