Skip to content

Commit

Permalink
Static Analysis Tools:
Browse files Browse the repository at this point in the history
- Added CONTRIBUTING.md
- Added .clang-format and formatted files using clang
- Added Clang documentation
- Added Linting Documentation and cleaned lint
  • Loading branch information
joshuali7536 committed Nov 5, 2021
1 parent e9a05c0 commit 3107d05
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 64 deletions.
6 changes: 6 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Format Style Options - Created with Clang Power Tools
---
BasedOnStyle: Microsoft
ReflowComments: false
SortIncludes: false
...
45 changes: 45 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# LENNAH SSG Contributing Guide

## Environment Setup

## Clang-Format
You can set up Clang to be used in the command line or through a Visual Studio Extension.

### Command Line:
1. Install Clang-Format from [here](https://llvm.org/builds/)
![image](https://user-images.githubusercontent.com/49960519/140454745-859a9bed-e809-4b35-b0a6-e19fe5e5295c.png)
1. Then when you install make sure to allow a new PATH to be created for Clang
1. To run clang-format open the terminal and use the following command in the project folder:
```sh
$ clang-format -style=file LennahSSG/*.cpp LennahSSG/*.h
```

### Extension:
1. Install Clang by following the instructions [here](https://clangpowertools.com/blog/get-started-with-clang-power-tools.html).
1. Turn on "Format on save" in the settings.
![image](https://user-images.githubusercontent.com/49960519/140451001-b1ebf533-f74f-4c68-bcf0-daaea0adbe01.png)
Now files should automatically format upon saving.
1. You can also format by clicking the format button(Alt+M) in Visual Studio:

![image](https://user-images.githubusercontent.com/49960519/140455055-dded7859-8c2b-4a09-bc7e-f2d02a5bbcbf.png)

## Clang-Tidy
You can set up Clang to be used in the command line or through a Visual Studio Extension.

### Command Line:
1. Clang-Tidy is included in the same package as Clang-Format. Follow the same instructions as Clang-Format if not already done.
1. To run clang-tidy open the terminal and use the following command in the project folder:
```sh
$ clang-tidy --config="" LennahSSG/*.cpp LennahSSG/*.h --extra-arg=-std=c++17 --extra-arg=-xc++ --
```
This will display the lint that needs fixing in errors.

### Extension:
1. Follow the same installation as for the extension for Clang-Format if not already done.
1. Turn on "Format after Tidy" and "Tidy on save"
![image](https://user-images.githubusercontent.com/49960519/140455540-7c606b0f-9c3a-4a0f-8118-18b7ce0585d6.png)
1. You can Lint the current file by clicking the Tidy button(Alt+Y) in Visual Studio:

![image](https://user-images.githubusercontent.com/49960519/140455702-b7e2f2f9-6e50-4617-bc5b-6e6930b8e6b8.png)
1. Then you can view the lint that needs fixing in the warnings area below.
1. You can also make a quick fix by pressing the drop down beside the Tidy button or pressing Alt+X
9 changes: 4 additions & 5 deletions LennahSSG/Config.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "Config.h"


Config::Config() {
Config::Config()
{
_input = "";
_output = "./dist";
_fileType = 0;
Expand All @@ -14,7 +14,7 @@ Config::Config() {
*
* returns a bool if config was a given argument
*/
string Config::getConfig(int argc, char** argv)
string Config::getConfig(int argc, char **argv)
{
string configName;
for (int i = 1; i < argc; i++)
Expand Down Expand Up @@ -75,7 +75,6 @@ void Config::readConfig(string inputFile)
_fileType = 2;
}
}

}
}

Expand All @@ -92,4 +91,4 @@ string Config::getOutput()
int Config::getFileType()
{
return _fileType;
}
}
21 changes: 10 additions & 11 deletions LennahSSG/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ using namespace std;

class Config
{
string _input;
string _output;
int _fileType;
string _input;
string _output;
int _fileType;

public:
Config();
string getConfig(int argc, char** argv);
void readConfig(string inputFile);
string getInput();
string getOutput();
int getFileType();
public:
Config();
string getConfig(int argc, char **argv);
void readConfig(string inputFile);
string getInput();
string getOutput();
int getFileType();
};

27 changes: 10 additions & 17 deletions LennahSSG/FileReader.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "FileReader.h"


/*
* readTxt - reads and converts a .txt or .md file to an html file
* path: the file path of the .txt/.md file
Expand All @@ -13,9 +12,6 @@ string FileReader::convertFile(string input, string output, int fileType, bool i
Formatter format;
string title, line;




ifstream inputFile;
inputFile.open(input);
if (!inputFile)
Expand All @@ -35,33 +31,31 @@ string FileReader::convertFile(string input, string output, int fileType, bool i
{

outputFile << "<!doctype html>\n"
<< "<html lang = \"en\">\n"
<< "<head>\n"
<< "<meta charset=\"utf-8\">\n"
<< "<title>";
<< "<html lang = \"en\">\n"
<< "<head>\n"
<< "<meta charset=\"utf-8\">\n"
<< "<title>";

if (fileType == 1)
{

//Getting Title
string line1, line2, line3;
bool hasTitle = false;
getline(inputFile, line1);
getline(inputFile, line2);
getline(inputFile, line3);

if (line1 != "" && line2 == "" && line3 == "")
{
title = line1;
hasTitle = true;
}
outputFile << title;
}

outputFile << "</title>\n"
<< "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n"
<< "</head>\n"
<< "<body>\n";
<< "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n"
<< "</head>\n"
<< "<body>\n";

if (isFolder)
outputFile << "<a href=\"index.html\">Home Page</a>\n";
Expand Down Expand Up @@ -97,8 +91,7 @@ string FileReader::convertFile(string input, string output, int fileType, bool i
//format <p> tags
if (prevLine == "" && line != "")
{
outputFile << "<p>\n"
<< line << "\n";
outputFile << "<p>\n" << line << "\n";
}
else if (prevLine != "" && line == "")
{
Expand All @@ -116,8 +109,8 @@ string FileReader::convertFile(string input, string output, int fileType, bool i
}

outputFile << "</body>\n"
<< "</html>";
<< "</html>";

outputFile.close();
return file_without_extension;
}
}
5 changes: 2 additions & 3 deletions LennahSSG/FileReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ using namespace std;

class FileReader
{
public:
string convertFile(string input, string output, int fileType, bool isFolder);
public:
string convertFile(string input, string output, int fileType, bool isFolder);
};

5 changes: 2 additions & 3 deletions LennahSSG/Formatter.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "Formatter.h"


/*
* italicize - Returns the given string with italicized HTML where italicized markdown was used
* itLine: string line to be formatted with italicize
Expand Down Expand Up @@ -59,7 +58,7 @@ string Formatter::boldify(string boldLine)
*/
string Formatter::trim(string line)
{
const char* WhiteSpace = " \t\v\r\n";
const char *WhiteSpace = " \t\v\r\n";
size_t start = line.find_first_not_of(WhiteSpace);
size_t end = line.find_last_not_of(WhiteSpace);
return start == end ? string() : line.substr(start, end - start + 1);
Expand All @@ -84,4 +83,4 @@ string Formatter::inlineCode(string line)
}
}
return line;
}
}
11 changes: 5 additions & 6 deletions LennahSSG/Formatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ using namespace std;

class Formatter
{
public:
string italicize(string itLine);
string boldify(string boldLine);
string trim(string line);
string inlineCode(string line);
public:
string italicize(string itLine);
string boldify(string boldLine);
string trim(string line);
string inlineCode(string line);
};

37 changes: 18 additions & 19 deletions LennahSSG/LennahSSG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ int main(int argc, char **argv)
{
std::string arg = argv[1];
std::string argDetail = argv[2];

//Check if config argument is given and what config file is called
string configFilePath = config.getConfig(argc, argv);
if (configFilePath != "")
Expand Down Expand Up @@ -101,7 +101,7 @@ void inputManager(string input, string output)
{
list<string> generatedHTMLs;
using fileIterator = filesystem::recursive_directory_iterator;
for (const auto& dirEntry : fileIterator(input))
for (const auto &dirEntry : fileIterator(input))
{
string path = dirEntry.path().string();
if (path.find(".txt") != string::npos || path.find(".md") != string::npos)
Expand All @@ -123,7 +123,6 @@ void inputManager(string input, string output)
cout << "Outputting to: " << output << endl;
createIndexHTML(generatedHTMLs, output);
}

}

/*
Expand Down Expand Up @@ -163,24 +162,24 @@ void createIndexHTML(list<string> links, string output)
ofstream outputFile(output + "/index.html");

outputFile << "<!doctype html>\n"
<< "<html lang = \"en\">\n"
<< "<head>\n"
<< "<meta charset=\"utf-8\">\n"
<< "<title>Home Page</title>"
<< "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n"
<< "</head>\n"
<< "<body>\n"
<< "<h1>Home Page</h1>\n"
<< "<h2>Table of Contents</h2>\n"
<< "<ul>\n";
<< "<html lang = \"en\">\n"
<< "<head>\n"
<< "<meta charset=\"utf-8\">\n"
<< "<title>Home Page</title>"
<< "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n"
<< "</head>\n"
<< "<body>\n"
<< "<h1>Home Page</h1>\n"
<< "<h2>Table of Contents</h2>\n"
<< "<ul>\n";

list<string>::iterator it;
for (it = links.begin(); it != links.end(); ++it) {
for (it = links.begin(); it != links.end(); ++it)
{
outputFile << "<li><a href=\"" << *it << ".html\">" << *it << "</li>";
}

outputFile << "</ul>\n"
<< "</body>\n"
<< "</html>\n";

}
outputFile << "</ul>\n"
<< "</body>\n"
<< "</html>\n";
}

0 comments on commit 3107d05

Please sign in to comment.