diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index efe0d5f7d..ef2ba3855 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,7 +9,7 @@ repos: - id: check-yaml - id: check-added-large-files - repo: https://github.com/pre-commit/mirrors-clang-format - rev: v20.1.8 + rev: v21.1.0 hooks: - id: clang-format types_or: [c++, c] diff --git a/src/Context.h b/src/Context.h index a456364e9..61933400c 100644 --- a/src/Context.h +++ b/src/Context.h @@ -46,36 +46,36 @@ class Context { Context() = default; // Default constructor ~Context(); // Destructor - Context(const Context &); - Context &operator=(const Context &); + Context(const Context&); + Context& operator=(const Context&); - static Context &getContext(); - static void setContext(Context *); + static Context& getContext(); + static void setContext(Context*); - int initialize(int, const char **); // all startup + int initialize(int, const char**); // all startup int run(); - int dispatch(std::string &); // command handler dispatch + int dispatch(std::string&); // command handler dispatch int getWidth(); // determine terminal width int getHeight(); // determine terminal height - std::string getTaskContext(const std::string &, std::string, bool fallback = true); + std::string getTaskContext(const std::string&, std::string, bool fallback = true); const std::vector getColumns() const; - void getLimits(int &, int &); + void getLimits(int&, int&); - bool color(); // TTY or ? - bool verbose(const std::string &); // Verbosity control + bool color(); // TTY or ? + bool verbose(const std::string&); // Verbosity control - void header(const std::string &); // Header message sink - void footnote(const std::string &); // Footnote message sink - void debug(const std::string &); // Debug message sink - void error(const std::string &); // Error message sink - non-maskable + void header(const std::string&); // Header message sink + void footnote(const std::string&); // Footnote message sink + void debug(const std::string&); // Debug message sink + void error(const std::string&); // Error message sink - non-maskable - void decomposeSortField(const std::string &, std::string &, bool &, bool &); - void debugTiming(const std::string &, const Timer &); + void decomposeSortField(const std::string&, std::string&, bool&, bool&); + void debugTiming(const std::string&, const Timer&); - CurrentTask withCurrentTask(const Task *); + CurrentTask withCurrentTask(const Task*); friend class CurrentTask; private: @@ -86,7 +86,7 @@ class Context { void loadAliases(); void propagateDebug(); - static Context *context; + static Context* context; public: CLI2 cli2{}; @@ -104,8 +104,8 @@ class Context { std::vector footnotes{}; std::vector errors{}; std::vector debugMessages{}; - std::map commands{}; - std::map columns{}; + std::map commands{}; + std::map columns{}; int terminal_width{0}; int terminal_height{0}; @@ -121,7 +121,7 @@ class Context { long time_hooks_us{0}; // the current task for DOM references, or NULL if there is no task - const Task *currentTask{NULL}; + const Task* currentTask{NULL}; }; //////////////////////////////////////////////////////////////////////////////// @@ -132,10 +132,10 @@ class CurrentTask { ~CurrentTask(); private: - CurrentTask(Context &context, const Task *previous); + CurrentTask(Context& context, const Task* previous); - Context &context; - const Task *previous; + Context& context; + const Task* previous; friend class Context; }; diff --git a/src/Eval.h b/src/Eval.h index 3203e8a15..85fe96721 100644 --- a/src/Eval.h +++ b/src/Eval.h @@ -33,43 +33,43 @@ #include #include -bool domSource(const std::string &, Variant &); +bool domSource(const std::string&, Variant&); class Eval { public: Eval(); - void addSource(bool (*fn)(const std::string &, Variant &)); - void evaluateInfixExpression(const std::string &, Variant &) const; - void evaluatePostfixExpression(const std::string &, Variant &) const; - void compileExpression(const std::vector> &); - void evaluateCompiledExpression(Variant &); + void addSource(bool (*fn)(const std::string&, Variant&)); + void evaluateInfixExpression(const std::string&, Variant&) const; + void evaluatePostfixExpression(const std::string&, Variant&) const; + void compileExpression(const std::vector>&); + void evaluateCompiledExpression(Variant&); void debug(bool); static std::vector getOperators(); static std::vector getBinaryOperators(); private: - void evaluatePostfixStack(const std::vector> &, - Variant &) const; - void infixToPostfix(std::vector> &) const; - void infixParse(std::vector> &) const; - bool parseLogical(std::vector> &, unsigned int &) const; - bool parseRegex(std::vector> &, unsigned int &) const; - bool parseEquality(std::vector> &, unsigned int &) const; - bool parseComparative(std::vector> &, unsigned int &) const; - bool parseArithmetic(std::vector> &, unsigned int &) const; - bool parseGeometric(std::vector> &, unsigned int &) const; - bool parseTag(std::vector> &, unsigned int &) const; - bool parseUnary(std::vector> &, unsigned int &) const; - bool parseExponent(std::vector> &, unsigned int &) const; - bool parsePrimitive(std::vector> &, unsigned int &) const; - bool identifyOperator(const std::string &, char &, unsigned int &, char &) const; + void evaluatePostfixStack(const std::vector>&, + Variant&) const; + void infixToPostfix(std::vector>&) const; + void infixParse(std::vector>&) const; + bool parseLogical(std::vector>&, unsigned int&) const; + bool parseRegex(std::vector>&, unsigned int&) const; + bool parseEquality(std::vector>&, unsigned int&) const; + bool parseComparative(std::vector>&, unsigned int&) const; + bool parseArithmetic(std::vector>&, unsigned int&) const; + bool parseGeometric(std::vector>&, unsigned int&) const; + bool parseTag(std::vector>&, unsigned int&) const; + bool parseUnary(std::vector>&, unsigned int&) const; + bool parseExponent(std::vector>&, unsigned int&) const; + bool parsePrimitive(std::vector>&, unsigned int&) const; + bool identifyOperator(const std::string&, char&, unsigned int&, char&) const; - std::string dump(std::vector> &) const; + std::string dump(std::vector>&) const; private: - std::vector _sources{}; + std::vector _sources{}; bool _debug{false}; std::vector> _compiled{}; }; diff --git a/src/Operation.h b/src/Operation.h index 82c2ea022..b6588e93f 100644 --- a/src/Operation.h +++ b/src/Operation.h @@ -39,14 +39,14 @@ // type. class Operation { public: - explicit Operation(const tc::Operation &); + explicit Operation(const tc::Operation&); - Operation(const Operation &other) = default; - Operation &operator=(const Operation &other); + Operation(const Operation& other) = default; + Operation& operator=(const Operation& other); // Create a vector of Operations given the result of `Replica::get_undo_operations` or // `Replica::get_task_operations`. The resulting vector must not outlive the input `rust::Vec`. - static std::vector operations(const rust::Vec &); + static std::vector operations(const rust::Vec&); // Methods from the underlying `tc::Operation`. bool is_create() const { return op->is_create(); } @@ -79,10 +79,10 @@ class Operation { // Define a partial order on Operations: // - Create < Update < Delete < UndoPoint // - Given two updates, sort by timestamp - bool operator<(const Operation &other) const; + bool operator<(const Operation& other) const; private: - const tc::Operation *op; + const tc::Operation* op; }; #endif diff --git a/src/TDB2.h b/src/TDB2.h index 51669ab6d..fc9e8e132 100644 --- a/src/TDB2.h +++ b/src/TDB2.h @@ -44,12 +44,12 @@ class TDB2 { TDB2() = default; - void open_replica(const std::string &, bool create_if_missing, bool read_write); + void open_replica(const std::string&, bool create_if_missing, bool read_write); void open_replica_in_memory(); - void add(Task &); - void modify(Task &); - void purge(Task &); - void get_changes(std::vector &); + void add(Task&); + void modify(Task&); + void purge(Task&); + void get_changes(std::vector&); void gc(); void expire_tasks(); int latest_id(); @@ -58,20 +58,20 @@ class TDB2 { const std::vector all_tasks(); const std::vector pending_tasks(); const std::vector completed_tasks(); - bool get(int, Task &); - bool get(const std::string &, Task &); - bool has(const std::string &); - const std::vector siblings(Task &); - const std::vector children(Task &); + bool get(int, Task&); + bool get(const std::string&, Task&); + bool has(const std::string&); + const std::vector siblings(Task&); + const std::vector children(Task&); // ID <--> UUID mapping. std::string uuid(int); - int id(const std::string &); + int id(const std::string&); int num_local_changes(); int num_reverts_possible(); - rust::Box &replica(); + rust::Box& replica(); private: std::optional> _replica; @@ -85,8 +85,8 @@ class TDB2 { // UUID -> Task containing all tasks modified in this invocation. std::map changes; - const rust::Box &working_set(); - void maybe_add_undo_point(rust::Vec &); + const rust::Box& working_set(); + void maybe_add_undo_point(rust::Vec&); }; #endif diff --git a/src/Version.cpp b/src/Version.cpp index e1633f86c..f3cff0ba4 100644 --- a/src/Version.cpp +++ b/src/Version.cpp @@ -66,32 +66,32 @@ Version Version::Current() { return Version(PACKAGE_VERSION); } bool Version::is_valid() const { return major >= 0; } //////////////////////////////////////////////////////////////////////////////// -bool Version::operator<(const Version &other) const { +bool Version::operator<(const Version& other) const { return std::tie(major, minor, patch) < std::tie(other.major, other.minor, other.patch); } //////////////////////////////////////////////////////////////////////////////// -bool Version::operator<=(const Version &other) const { +bool Version::operator<=(const Version& other) const { return std::tie(major, minor, patch) <= std::tie(other.major, other.minor, other.patch); } //////////////////////////////////////////////////////////////////////////////// -bool Version::operator>(const Version &other) const { +bool Version::operator>(const Version& other) const { return std::tie(major, minor, patch) > std::tie(other.major, other.minor, other.patch); } //////////////////////////////////////////////////////////////////////////////// -bool Version::operator>=(const Version &other) const { +bool Version::operator>=(const Version& other) const { return std::tie(major, minor, patch) >= std::tie(other.major, other.minor, other.patch); } //////////////////////////////////////////////////////////////////////////////// -bool Version::operator==(const Version &other) const { +bool Version::operator==(const Version& other) const { return std::tie(major, minor, patch) == std::tie(other.major, other.minor, other.patch); } //////////////////////////////////////////////////////////////////////////////// -bool Version::operator!=(const Version &other) const { +bool Version::operator!=(const Version& other) const { return std::tie(major, minor, patch) != std::tie(other.major, other.minor, other.patch); } @@ -107,7 +107,7 @@ Version::operator std::string() const { } //////////////////////////////////////////////////////////////////////////////// -std::ostream &operator<<(std::ostream &os, const Version &version) { +std::ostream& operator<<(std::ostream& os, const Version& version) { os << std::string(version); return os; } diff --git a/src/Version.h b/src/Version.h index 03b81d2ad..e5f040295 100644 --- a/src/Version.h +++ b/src/Version.h @@ -39,10 +39,10 @@ class Version { // Create an invalid version. Version() = default; - Version(const Version &other) = default; - Version(Version &&other) = default; - Version &operator=(const Version &) = default; - Version &operator=(Version &&) = default; + Version(const Version& other) = default; + Version(Version&& other) = default; + Version& operator=(const Version&) = default; + Version& operator=(Version&&) = default; // Return a version representing the release being built. static Version Current(); @@ -50,17 +50,17 @@ class Version { bool is_valid() const; // Compare versions. - bool operator<(const Version &) const; - bool operator<=(const Version &) const; - bool operator>(const Version &) const; - bool operator>=(const Version &) const; - bool operator==(const Version &) const; - bool operator!=(const Version &) const; + bool operator<(const Version&) const; + bool operator<=(const Version&) const; + bool operator>(const Version&) const; + bool operator>=(const Version&) const; + bool operator==(const Version&) const; + bool operator!=(const Version&) const; // Convert back to a string. operator std::string() const; - friend std::ostream &operator<<(std::ostream &os, const Version &version); + friend std::ostream& operator<<(std::ostream& os, const Version& version); private: int major = -1; diff --git a/src/commands/CmdImportV2.h b/src/commands/CmdImportV2.h index 5cfddd63d..5691b52b5 100644 --- a/src/commands/CmdImportV2.h +++ b/src/commands/CmdImportV2.h @@ -35,10 +35,10 @@ class CmdImportV2 : public Command { public: CmdImportV2(); - int execute(std::string &); + int execute(std::string&); private: - int import(const std::vector> &task_data); + int import(const std::vector>& task_data); }; #endif diff --git a/src/commands/CmdModify.cpp b/src/commands/CmdModify.cpp index a962ea10b..f2bd3f025 100644 --- a/src/commands/CmdModify.cpp +++ b/src/commands/CmdModify.cpp @@ -58,7 +58,7 @@ CmdModify::CmdModify() { } //////////////////////////////////////////////////////////////////////////////// -int CmdModify::execute(std::string &) { +int CmdModify::execute(std::string&) { auto rc = 0; // Apply filter. @@ -77,7 +77,7 @@ int CmdModify::execute(std::string &) { if (filtered.size() > 1) { feedback_affected("This command will alter {1} tasks.", filtered.size()); } - for (auto &task : filtered) { + for (auto& task : filtered) { Task before(task); task.modify(Task::modReplace); @@ -99,7 +99,7 @@ int CmdModify::execute(std::string &) { } // Now list the project changes. - for (const auto &change : projectChanges) + for (const auto& change : projectChanges) if (change.first != "") Context::getContext().footnote(change.second); feedback_affected(count == 1 ? "Modified {1} task." : "Modified {1} tasks.", count); @@ -108,7 +108,7 @@ int CmdModify::execute(std::string &) { //////////////////////////////////////////////////////////////////////////////// // TODO Why is this not in Task::validate? -void CmdModify::checkConsistency(Task &before, Task &after) { +void CmdModify::checkConsistency(Task& before, Task& after) { // Perform some logical consistency checks. if (after.has("recur") && !after.has("due") && !before.has("due")) throw std::string("You cannot specify a recurring task without a due date."); @@ -126,8 +126,8 @@ void CmdModify::checkConsistency(Task &before, Task &after) { } //////////////////////////////////////////////////////////////////////////////// -int CmdModify::modifyAndUpdate(Task &before, Task &after, - std::map *projectChanges /* = NULL */) { +int CmdModify::modifyAndUpdate(Task& before, Task& after, + std::map* projectChanges /* = NULL */) { // This task. auto count = 1; @@ -150,14 +150,14 @@ int CmdModify::modifyAndUpdate(Task &before, Task &after, //////////////////////////////////////////////////////////////////////////////// int CmdModify::modifyRecurrenceSiblings( - Task &task, std::map *projectChanges /* = NULL */) { + Task& task, std::map* projectChanges /* = NULL */) { auto count = 0; if ((Context::getContext().config.get("recurrence.confirmation") == "prompt" && confirm(STRING_CMD_MODIFY_RECUR)) || Context::getContext().config.getBoolean("recurrence.confirmation")) { std::vector siblings = Context::getContext().tdb2.siblings(task); - for (auto &sibling : siblings) { + for (auto& sibling : siblings) { Task alternate(sibling); sibling.modify(Task::modReplace); updateRecurrenceMask(sibling); @@ -181,7 +181,7 @@ int CmdModify::modifyRecurrenceSiblings( //////////////////////////////////////////////////////////////////////////////// int CmdModify::modifyRecurrenceParent( - Task &task, std::map *projectChanges /* = NULL */) { + Task& task, std::map* projectChanges /* = NULL */) { auto count = 0; auto children = Context::getContext().tdb2.children(task); @@ -189,7 +189,7 @@ int CmdModify::modifyRecurrenceParent( ((Context::getContext().config.get("recurrence.confirmation") == "prompt" && confirm(STRING_CMD_MODIFY_RECUR)) || Context::getContext().config.getBoolean("recurrence.confirmation"))) { - for (auto &child : children) { + for (auto& child : children) { Task alternate(child); child.modify(Task::modReplace); updateRecurrenceMask(child); diff --git a/src/commands/CmdModify.h b/src/commands/CmdModify.h index 17313e798..0e33d877f 100644 --- a/src/commands/CmdModify.h +++ b/src/commands/CmdModify.h @@ -34,14 +34,14 @@ class CmdModify : public Command { public: CmdModify(); - int execute(std::string &); - void checkConsistency(Task &before, Task &after); - int modifyAndUpdate(Task &before, Task &after, - std::map *projectChanges = nullptr); - int modifyRecurrenceSiblings(Task &task, - std::map *projectChanges = nullptr); - int modifyRecurrenceParent(Task &task, - std::map *projectChanges = nullptr); + int execute(std::string&); + void checkConsistency(Task& before, Task& after); + int modifyAndUpdate(Task& before, Task& after, + std::map* projectChanges = nullptr); + int modifyRecurrenceSiblings(Task& task, + std::map* projectChanges = nullptr); + int modifyRecurrenceParent(Task& task, + std::map* projectChanges = nullptr); }; #endif diff --git a/src/commands/CmdUndo.h b/src/commands/CmdUndo.h index 590184178..e82655393 100644 --- a/src/commands/CmdUndo.h +++ b/src/commands/CmdUndo.h @@ -36,10 +36,10 @@ class CmdUndo : public Command { public: CmdUndo(); - int execute(std::string &); + int execute(std::string&); private: - bool confirm_revert(const std::vector &); + bool confirm_revert(const std::vector&); }; #endif diff --git a/test/make_tc_task.cpp b/test/make_tc_task.cpp index 37f1d963f..661a7595f 100644 --- a/test/make_tc_task.cpp +++ b/test/make_tc_task.cpp @@ -46,11 +46,11 @@ int usage() { } // namespace //////////////////////////////////////////////////////////////////////////////// -int main(int argc, char **argv) { +int main(int argc, char** argv) { if (!--argc) { return usage(); } - char *datadir = *++argv; + char* datadir = *++argv; auto replica = tc::new_replica_on_disk(datadir, /*create_if_missing=*/true, /*read_write=*/true); auto uuid = tc::uuid_v4(); diff --git a/test/tc_cpp_test.cpp b/test/tc_cpp_test.cpp index c92e5e66d..7059ed48d 100644 --- a/test/tc_cpp_test.cpp +++ b/test/tc_cpp_test.cpp @@ -41,7 +41,7 @@ std::string uuid2str(tc::Uuid uuid) { return static_cast(uuid.to_st // Tests for the basic cxxbridge functionality. This focuses on the methods with // complex cxxbridge implementations, rather than those with complex Rust // implementations but simple APIs, like sync. -int TEST_NAME(int, char **) { +int TEST_NAME(int, char**) { UnitTest t; std::string str; @@ -94,7 +94,7 @@ int TEST_NAME(int, char **) { auto old_task = ops[5].get_old_task(); // old_task is in arbitrary order, so just check that status is in there. bool found = false; - for (auto &pv : old_task) { + for (auto& pv : old_task) { std::string p = static_cast(pv.prop); if (p == "status") { std::string v = static_cast(pv.value); @@ -131,7 +131,7 @@ int TEST_NAME(int, char **) { auto all_tasks = replica->all_task_data(); t.is(all_tasks.size(), (size_t)2, "now there are 2 tasks"); - for (auto &maybe_task : all_tasks) { + for (auto& maybe_task : all_tasks) { t.ok(maybe_task.is_some(), "all_tasks is fully populated"); auto task = maybe_task.take(); if (task->get_uuid() == uuid) { @@ -144,7 +144,7 @@ int TEST_NAME(int, char **) { try { replica->sync_to_local("/does/not/exist", false); // tc::new_replica_on_disk("/does/not/exist", false); - } catch (rust::Error &err) { + } catch (rust::Error& err) { t.is(err.what(), "unable to open database file: /does/not/exist/taskchampion-local-sync-server.sqlite3: " "Error code 14: Unable to open the database file",