Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a tool for inspect that checks for character limits
Created to default to hard limit of 90, excludes documented files, CMakeLists.txt, and #error.
- Loading branch information
Showing
3 changed files
with
208 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
// character_length_check implementation ----------------------------------// | ||
|
||
// Copyright (c) 2015 Brandon Cordes | ||
// Based on the apple_macro_check checker by Marshall Clow | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// (See accompanying file LICENSE_1_0.txt or copy at | ||
// http://www.boost.org/LICENSE_1_0.txt) | ||
|
||
#include "length_check.hpp" | ||
#include <iostream> | ||
#include <functional> | ||
#include <string> | ||
#include <boost/foreach.hpp> | ||
#include <boost/tokenizer.hpp> | ||
#include "boost/regex.hpp" | ||
#include "boost/lexical_cast.hpp" | ||
#include "boost/filesystem/operations.hpp" | ||
|
||
using namespace std; | ||
namespace fs = boost::filesystem; | ||
|
||
namespace boost | ||
{ | ||
namespace inspect | ||
{ | ||
size_t limit; | ||
|
||
length_check::length_check(size_t setting) | ||
: m_files_with_errors(0) | ||
|
||
{ | ||
register_signature(".c"); | ||
register_signature(".cpp"); | ||
register_signature(".css"); | ||
register_signature(".cxx"); | ||
register_signature(".h"); | ||
register_signature(".hpp"); | ||
register_signature(".hxx"); | ||
register_signature(".inc"); | ||
register_signature(".ipp"); | ||
register_signature(".txt"); | ||
|
||
limit = setting; | ||
} | ||
|
||
void length_check::inspect( | ||
const string & library_name, | ||
const path & full_path, // ex: c:/foo/boost/filesystem/path.hpp | ||
const string & contents) // contents of file to be inspected | ||
{ | ||
if (contents.find("hpxinspect:" "length") != string::npos) | ||
return; | ||
string pathname = full_path.string(); | ||
if (pathname.find("CMakeLists.txt") != string::npos) | ||
return; | ||
//Temporary, until we are ready to format documentation files in this limitation. | ||
if (library_name.find(".qbk") != string::npos) | ||
return; | ||
|
||
string total, linenum; | ||
long errors = 0, currline = 0; | ||
size_t p = 0, extend = 0; | ||
vector<string> someline, lineorder; | ||
|
||
char_separator<char> sep("\n", "", boost::keep_empty_tokens); | ||
tokenizer<char_separator<char>> tokens(contents, sep); | ||
for (const auto& t : tokens) { | ||
size_t rend = t.find_first_of("\r"), size = t.size(); | ||
if (rend == size - 1) | ||
{ | ||
someline.push_back(t); | ||
} | ||
else | ||
{ | ||
char_separator<char> sep2("\r", "", boost::keep_empty_tokens); | ||
tokenizer<char_separator<char>> tokens2(t, sep2); | ||
for (const auto& u : tokens2) { | ||
someline.push_back(u); | ||
} | ||
} | ||
} | ||
while (p < someline.size()) | ||
{ | ||
currline++; | ||
size_t rend = someline[p].find_last_of("\r"); | ||
boost::regex error_note; | ||
error_note = "\\s*#\\s*error"; | ||
boost::smatch m; | ||
if (boost::regex_match(someline[p], m, error_note)) | ||
{ | ||
if (m.position() == 0) | ||
{ | ||
return; | ||
} | ||
} | ||
if (rend != string::npos) | ||
{ | ||
extend = limit + 2; | ||
} | ||
else | ||
{ | ||
extend = limit; | ||
} | ||
size_t size = someline[p].size(); | ||
if (size > extend) | ||
{ | ||
errors++; | ||
linenum = to_string(currline); | ||
lineorder.push_back(linenum); | ||
} | ||
p++; | ||
} | ||
p = 0; | ||
while (p < lineorder.size()) | ||
{ | ||
total += lineorder[p]; | ||
if (p < lineorder.size() - 1) | ||
{ | ||
total += ", "; | ||
} | ||
p++; | ||
} | ||
if (errors > 0) | ||
{ | ||
string errored = "Character Limit*: " + total; | ||
error(library_name, full_path, errored); | ||
++m_files_with_errors; | ||
} | ||
} | ||
} // namespace inspect | ||
} // namespace boost |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// character_length_check header ------------------------------------------// | ||
|
||
// Copyright (c) 2015 Brandon Cordes | ||
// Based on the apple_macro_check checker by Marshall Clow | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// (See accompanying file LICENSE_1_0.txt or copy at | ||
// http://www.boost.org/LICENSE_1_0.txt) | ||
|
||
#ifndef BOOST_EIGHTY_CHECK_HPP | ||
#define BOOST_EIGHTY_CHECK_HPP | ||
|
||
#include "inspector.hpp" | ||
|
||
namespace boost | ||
{ | ||
namespace inspect | ||
{ | ||
class length_check : public inspector | ||
{ | ||
long m_files_with_errors; | ||
public: | ||
|
||
length_check(size_t setting); | ||
|
||
std::string a = "*Character Limit*"; | ||
std::string b = "The line is larger than the character limit"; | ||
virtual const char * name() const { return a.c_str(); } | ||
virtual const char * desc() const { return b.c_str(); } | ||
|
||
virtual void inspect( | ||
const std::string & library_name, | ||
const path & full_path, | ||
const std::string & contents); | ||
|
||
virtual void print_summary(std::ostream& out) | ||
{ | ||
string c = " files exceeding the character limit"; | ||
out << " " << m_files_with_errors << c << line_break(); | ||
} | ||
|
||
virtual ~length_check() {} | ||
}; | ||
} | ||
} | ||
|
||
#endif // BOOST_EXTRA_WHITESPACE_CHECK_HPP |