aboutsummaryrefslogtreecommitdiff
path: root/paludis/repositories/e/qa/function_keyword.cc
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2008-01-26 17:13:26 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2008-01-26 17:13:26 +0000
commita9b4ed0d06e8238a80dc6b9ec4142fc924339433 (patch)
tree068b4e603f92e3039814e485b2f6b3288eff88ff /paludis/repositories/e/qa/function_keyword.cc
parent20b841f4170fe5eafab9a65e877e9d17b9db13db (diff)
downloadpaludis-a9b4ed0d06e8238a80dc6b9ec4142fc924339433.tar.gz
paludis-a9b4ed0d06e8238a80dc6b9ec4142fc924339433.tar.xz
Add function_keyword check.
Diffstat (limited to 'paludis/repositories/e/qa/function_keyword.cc')
-rw-r--r--paludis/repositories/e/qa/function_keyword.cc75
1 files changed, 75 insertions, 0 deletions
diff --git a/paludis/repositories/e/qa/function_keyword.cc b/paludis/repositories/e/qa/function_keyword.cc
new file mode 100644
index 0000000..e0e55dd
--- /dev/null
+++ b/paludis/repositories/e/qa/function_keyword.cc
@@ -0,0 +1,75 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Fernando J. Pereda
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "function_keyword.hh"
+#include <paludis/qa.hh>
+#include <paludis/util/log.hh>
+#include <paludis/util/tokeniser.hh>
+#include <pcre++.h>
+#include <list>
+
+using namespace paludis;
+
+namespace
+{
+ QAMessage
+ with_id(QAMessage m, const tr1::shared_ptr<const PackageID> & id)
+ {
+ return id ? m.with_associated_id(id) : m;
+ }
+}
+
+bool
+paludis::erepository::function_keyword_check(
+ const FSEntry & entry,
+ QAReporter & reporter,
+ const tr1::shared_ptr<const PackageID> & id,
+ const std::string & content,
+ const std::string & name)
+{
+ Context context("When performing check '" + name + "' using function_keyword_check on '" + (id ? stringify(*id) : stringify(entry)) + "':");
+
+ pcrepp::Pcre::Pcre r_function("^function +[^ ]+ *(\\(\\))? *{?");
+
+ if (id)
+ Log::get_instance()->message(ll_debug, lc_context) << "function_keyword '"
+ << entry << "', '" << *id << "', '" << name << "'";
+ else
+ Log::get_instance()->message(ll_debug, lc_context) << "function_keyword '"
+ << entry << "', '" << name << "'";
+
+ std::list<std::string> lines;
+ tokenise<delim_kind::AnyOfTag, delim_mode::DelimiterTag>(content, "\n", "", std::back_inserter(lines));
+
+ unsigned line_number(0);
+ for (std::list<std::string>::iterator it(lines.begin()),
+ it_end(lines.end()); it_end != it; ++it)
+ {
+ ++line_number;
+
+ if (it->empty())
+ continue;
+
+ if (r_function.search(*it))
+ reporter.message(with_id(QAMessage(entry, qaml_minor, name, "Use of the keyword 'function' on line " + stringify(line_number)), id));
+ }
+
+ return true;
+}
+