Skip to content

Commit

Permalink
Support --exclude for lint command (#801)
Browse files Browse the repository at this point in the history
  • Loading branch information
ken-matsui authored Dec 22, 2023
1 parent 9d8b39f commit 6e679ac
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 44 deletions.
25 changes: 10 additions & 15 deletions .github/workflows/cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,16 @@ jobs:
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
poac fmt --check --verbose
# lint:
# runs-on: ubuntu-22.04
# steps:
# - uses: actions/checkout@v4
lint:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4

# - name: Install Poac
# run: |
# eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
# brew update
# brew install poac
- name: Build Poac
run: make RELEASE=1

# - name: Install cpplint
# run: pip install cpplint
- name: Install cpplint
run: pip install cpplint

# - name: Run lint
# run: |
# eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
# poac lint --verbose
- name: Run lint
run: ./build-out/poac lint --verbose --exclude srcOld --exclude testsOld
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ Hello, world!

## Supported Operating Systems

| Linux | macOS |
| :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
| Linux | macOS |
| :----------------------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------: |
| [![Linux](https://github.com/poac-dev/poac/actions/workflows/linux.yml/badge.svg)](https://github.com/poac-dev/poac/actions/workflows/linux.yml) | [![macOS](https://github.com/poac-dev/poac/actions/workflows/macos.yml/badge.svg)](https://github.com/poac-dev/poac/actions/workflows/macos.yml) |

## Installation
Expand Down Expand Up @@ -106,7 +106,7 @@ Once you have all the necessary requirements in place, you can proceed to build
```bash
git clone https://github.com/poac-dev/poac.git
cd poac
make
make RELEASE=1
```

Poac attempts to utilize locally installed dependencies by default. To bypass the use of local packages, you can download the required dependencies in `build-out/DEPS`.
Expand Down
4 changes: 4 additions & 0 deletions poac.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ filters = [
"-readability/namespace", # Unknown NOLINT error category: bugprone-branch-clone # This is for clang-tidy
"-readability/nolint", # I believe non-const reference would be much better than a pointer.
"-runtime/references",
"-readability/braces", # prioritize clang-format
"-build/include_order", # prioritize clang-format
"-build/include_subdir",
"-readability/todo",
]
2 changes: 2 additions & 0 deletions src/Algos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

#include "Rustify.hpp"

#include <algorithm>
#include <memory>
#include <utility>

// O(M) where M is the length of the word.
void trieInsert(TrieNode& root, StringRef word) {
Expand Down
3 changes: 1 addition & 2 deletions src/BuildConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <ostream>
#include <sstream>
#include <stdexcept>
#include <string>

static String OUT_DIR;
static String CXX = "clang++";
Expand Down Expand Up @@ -553,8 +554,6 @@ String getMakeCommand() {
#ifdef POAC_TEST

# include <cassert>
# include <sstream>
# include <stdexcept>

void test_cycle_vars() {
BuildConfig config;
Expand Down
1 change: 1 addition & 0 deletions src/Cmd/Clean.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <iostream>
#include <span>
#include <string>

int cleanMain(std::span<const StringRef> args) noexcept {
Path outDir = "poac-out";
Expand Down
3 changes: 2 additions & 1 deletion src/Cmd/Fmt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
#include "../Logger.hpp"
#include "../Manifest.hpp"
#include "../Rustify.hpp"
#include "Global.hpp"
#include "./Global.hpp"

#include <cstdlib>
#include <fstream>
#include <iostream>
#include <span>
#include <string>

int fmtMain(std::span<const StringRef> args) {
bool isCheck = false;
Expand Down
1 change: 1 addition & 0 deletions src/Cmd/Init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <fstream>
#include <iostream>
#include <span>
#include <string>

int initMain(std::span<const StringRef> args) {
// Parse args
Expand Down
25 changes: 20 additions & 5 deletions src/Cmd/Lint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
static int lint(StringRef name, StringRef cpplintArgs) {
Logger::info("Linting", name);

String cpplintCmd = "cpplint --recursive .";
String cpplintCmd = "cpplint";
cpplintCmd += cpplintArgs;
if (!isVerbose()) {
cpplintCmd += " --quiet";
Expand All @@ -32,6 +32,7 @@ static int lint(StringRef name, StringRef cpplintArgs) {
cpplintCmd += line;
}
}
cpplintCmd += " --recursive ."; // This should be after `--exclude` options

Logger::debug("Executing ", cpplintCmd);
const int status = std::system(cpplintCmd.c_str());
Expand All @@ -45,9 +46,21 @@ static int lint(StringRef name, StringRef cpplintArgs) {

int lintMain(std::span<const StringRef> args) {
// Parse args
for (StringRef arg : args) {
String cpplintArgs;
for (usize i = 0; i < args.size(); ++i) {
StringRef arg = args[i];
HANDLE_GLOBAL_OPTS({{"lint"}})

else if (arg == "--exclude") {
if (i + 1 >= args.size()) {
Logger::error("Missing argument for ", arg);
return EXIT_FAILURE;
}

++i;
cpplintArgs += " --exclude=";
cpplintArgs += args[i];
}
else {
Logger::error("invalid argument: ", arg);
return EXIT_FAILURE;
Expand All @@ -66,18 +79,19 @@ int lintMain(std::span<const StringRef> args) {
const Vec<String> cpplintFilters = getLintCpplintFilters();
if (!cpplintFilters.empty()) {
Logger::debug("Using Poac manifest file for lint ...");
String cpplintArgs = " --root=include --filter=";
cpplintArgs += " --root=include --filter=";
for (StringRef filter : cpplintFilters) {
cpplintArgs += filter;
cpplintArgs += ',';
}
// Remove last comma
cpplintArgs.pop_back();
return lint(packageName, cpplintArgs);
} else if (fs::exists("CPPLINT.cfg")) {
Logger::debug("Using CPPLINT.cfg for lint ...");
return lint(packageName, "");
return lint(packageName, cpplintArgs);
} else {
Logger::debug("Using default arguments for lint ...");
String cpplintArgs;
if (fs::exists("include")) {
cpplintArgs += " --root=include";
}
Expand All @@ -95,4 +109,5 @@ void lintHelp() noexcept {
std::cout << '\n';
printHeader("Options:");
printGlobalOpts();
printOption("--exclude", "", "Exclude files from linting");
}
4 changes: 2 additions & 2 deletions src/Cmd/New.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <iostream>
#include <span>
#include <stdexcept>
#include <string>

static inline constexpr StringRef mainCc =
"#include <iostream>\n\n"
Expand Down Expand Up @@ -230,8 +231,7 @@ int newMain(std::span<const StringRef> args) {
// Parse args
bool isBin = true;
String packageName;
for (usize i = 0; i < args.size(); ++i) {
StringRef arg = args[i];
for (StringRef arg : args) {
HANDLE_GLOBAL_OPTS({{"new"}})

else if (arg == "-b" || arg == "--bin") {
Expand Down
1 change: 1 addition & 0 deletions src/Manifest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <cstdlib>
#include <iostream>
#include <stdexcept>
#include <string>

#define TOML11_NO_ERROR_PREFIX
#include <toml.hpp>
Expand Down
2 changes: 1 addition & 1 deletion src/TermColor.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "Rustify.hpp"
#include "./Rustify.hpp"

enum class ColorMode {
always,
Expand Down
30 changes: 15 additions & 15 deletions src/main.cc
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#include "Algos.hpp"
#include "Cmd/Build.hpp"
#include "Cmd/Clean.hpp"
#include "Cmd/Fmt.hpp"
#include "Cmd/Global.hpp"
#include "Cmd/Help.hpp"
#include "Cmd/Init.hpp"
#include "Cmd/Lint.hpp"
#include "Cmd/New.hpp"
#include "Cmd/Run.hpp"
#include "Cmd/Test.hpp"
#include "Cmd/Version.hpp"
#include "Logger.hpp"
#include "Rustify.hpp"
#include "TermColor.hpp"
#include "./Algos.hpp"
#include "./Cmd/Build.hpp"
#include "./Cmd/Clean.hpp"
#include "./Cmd/Fmt.hpp"
#include "./Cmd/Global.hpp"
#include "./Cmd/Help.hpp"
#include "./Cmd/Init.hpp"
#include "./Cmd/Lint.hpp"
#include "./Cmd/New.hpp"
#include "./Cmd/Run.hpp"
#include "./Cmd/Test.hpp"
#include "./Cmd/Version.hpp"
#include "./Logger.hpp"
#include "./Rustify.hpp"
#include "./TermColor.hpp"

#include <cstdlib>
#include <iomanip>
Expand Down

0 comments on commit 6e679ac

Please sign in to comment.