-
-
Notifications
You must be signed in to change notification settings - Fork 4
Minor code optimization #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,7 +57,7 @@ class CppLintState { | |
| public: | ||
| CppLintState(); | ||
|
|
||
| int OutputFormat() const { return m_output_format; } | ||
| [[nodiscard]] int OutputFormat() const { return m_output_format; } | ||
| void SetOutputFormat(const std::string& output_format) { | ||
| // Sets the output format for errors. | ||
| if (output_format == "vs7") | ||
|
|
@@ -74,15 +74,15 @@ class CppLintState { | |
| m_output_format = OUTPUT_EMACS; | ||
| } | ||
|
|
||
| bool Quiet() const { return m_quiet; } | ||
| [[nodiscard]] bool Quiet() const { return m_quiet; } | ||
| bool SetQuiet(bool quiet) { | ||
| // Sets the module's quiet settings, and returns the previous setting. | ||
| bool last_quiet = m_quiet; | ||
| m_quiet = quiet; | ||
| return last_quiet; | ||
| } | ||
|
|
||
| int VerboseLevel() const { return m_verbose_level; } | ||
| [[nodiscard]] int VerboseLevel() const { return m_verbose_level; } | ||
| int SetVerboseLevel(int level) { | ||
| // Sets the module's verbosity, and returns the previous setting. | ||
| int last_verbose_level = m_verbose_level; | ||
|
|
@@ -106,11 +106,11 @@ class CppLintState { | |
| m_errors_by_category.clear(); | ||
| } | ||
|
|
||
| int ErrorCount() const { return m_error_count; } | ||
| int ErrorCount(const std::string& category) const; | ||
| [[nodiscard]] int ErrorCount() const { return m_error_count; } | ||
| [[nodiscard]] int ErrorCount(const std::string& category) const; | ||
|
|
||
| void SetNumThreads(int num_threads) { m_num_threads = num_threads; } | ||
| int GetNumThreads() const { return m_num_threads; } | ||
| [[nodiscard]] int GetNumThreads() const { return m_num_threads; } | ||
|
|
||
| // Bumps the module's error statistic. | ||
| void IncrementErrorCount(const std::string& category); | ||
|
|
@@ -129,10 +129,10 @@ class CppLintState { | |
|
|
||
| // Print a summary of errors by category, and the total. | ||
| void PrintErrorCounts(); | ||
| void PrintInfo(const std::string& message); | ||
| void PrintError(const std::string& message); | ||
| void PrintInfo(const std::string& message) const; | ||
| void PrintError(const std::string& message) const; | ||
|
|
||
| bool AddJUnitFailure(const std::string& filename, | ||
| static bool AddJUnitFailure(const std::string& filename, | ||
| size_t linenum, | ||
| const std::string& message, | ||
| const std::string& category, | ||
|
Comment on lines
+135
to
138
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You still need to align arguments for some functions that use |
||
|
|
@@ -145,5 +145,5 @@ class CppLintState { | |
| return false; | ||
| } | ||
|
|
||
| std::string FormatJUnitXML() { return ""; } | ||
| static std::string FormatJUnitXML() { return ""; } | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,7 +31,7 @@ class FileLinter { | |
| bool m_has_error; | ||
|
|
||
| public: | ||
| FileLinter() {} | ||
| FileLinter() = default; | ||
| FileLinter(const fs::path& file, CppLintState* state, const Options& options) : | ||
| m_cpplint_state(state), | ||
| m_options(options), | ||
|
|
@@ -48,8 +48,8 @@ class FileLinter { | |
| m_re_result(RegexCreateMatchData(16)), | ||
| m_has_error(false) {} | ||
|
|
||
| fs::path GetRelativeFromRepository(const fs::path& file, const fs::path& repository); | ||
| fs::path GetRelativeFromSubdir(const fs::path& file, const fs::path& subdir); | ||
| static fs::path GetRelativeFromRepository(const fs::path& file, const fs::path& repository); | ||
| static fs::path GetRelativeFromSubdir(const fs::path& file, const fs::path& subdir); | ||
|
|
||
| // Logs an error if no Copyright message appears at the top of the file. | ||
| void CheckForCopyright(const std::vector<std::string>& lines); | ||
|
|
@@ -69,9 +69,9 @@ class FileLinter { | |
| */ | ||
| void CheckForHeaderGuard(const CleansedLines& clean_lines); | ||
|
|
||
| bool IsForwardClassDeclaration(const std::string& elided_line); | ||
| static bool IsForwardClassDeclaration(const std::string& elided_line); | ||
|
|
||
| bool IsMacroDefinition(const CleansedLines& clean_lines, | ||
| static bool IsMacroDefinition(const CleansedLines& clean_lines, | ||
| const std::string& elided_line, size_t linenum); | ||
|
Comment on lines
+74
to
75
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Arguments should be aligned. |
||
|
|
||
| void CheckForNamespaceIndentation(const CleansedLines& clean_lines, | ||
|
|
@@ -231,7 +231,7 @@ class FileLinter { | |
| IncludeState* include_state); | ||
|
|
||
| // Checks whether where function type arguments are expected. | ||
| bool ExpectingFunctionArgs(const CleansedLines& clean_lines, | ||
| static bool ExpectingFunctionArgs(const CleansedLines& clean_lines, | ||
| const std::string& elided_line, size_t linenum); | ||
|
Comment on lines
+234
to
235
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Arguments should be aligned. |
||
|
|
||
| // Checks for a C-style cast by looking for the pattern. | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -17,8 +17,8 @@ class Filter { | |||||
| public: | ||||||
| Filter() : | ||||||
| m_sign(false), | ||||||
| m_category(""), | ||||||
| m_file(""), | ||||||
| m_category(), | ||||||
| m_file(), | ||||||
| m_linenum(INDEX_NONE) {} | ||||||
|
|
||||||
| explicit Filter(const std::string& filter) { | ||||||
|
|
@@ -27,9 +27,9 @@ class Filter { | |||||
|
|
||||||
| void ParseFilterSelector(const std::string& filter); | ||||||
|
|
||||||
| bool IsPositive() const { return m_sign; } | ||||||
| [[nodiscard]] bool IsPositive() const { return m_sign; } | ||||||
|
|
||||||
| bool IsMatched(const std::string& category, | ||||||
| [[nodiscard]] bool IsMatched(const std::string& category, | ||||||
| const std::string& file, | ||||||
| size_t linenum) const { | ||||||
|
Comment on lines
+32
to
34
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Arguments should be aligned. |
||||||
| return category.starts_with(m_category) && | ||||||
|
|
@@ -76,12 +76,13 @@ class Options { | |||||
| // Searches a list of filenames and replaces directories in the list with | ||||||
| // all files descending from those directories. Files with extensions not in | ||||||
| // the valid extensions list are excluded. | ||||||
| std::vector<fs::path> ExpandDirectories(const std::vector<fs::path>& filenames); | ||||||
| std::vector<fs::path> ExpandDirectories(const std::vector<fs::path>& filenames) const; | ||||||
|
|
||||||
| // Filters out files listed in the --exclude command line switch. File paths | ||||||
| // in the switch are evaluated relative to the current working directory | ||||||
| std::vector<fs::path> FilterExcludedFiles(std::vector<fs::path> filenames, | ||||||
| const std::vector<fs::path>& excludes); | ||||||
| static std::vector<fs::path> FilterExcludedFiles( | ||||||
| std::vector<fs::path> filenames, | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Tab indentations should be removed. |
||||||
| const std::vector<fs::path>& excludes); | ||||||
|
|
||||||
| public: | ||||||
| Options() : | ||||||
|
|
@@ -102,28 +103,29 @@ class Options { | |||||
| std::vector<fs::path> ParseArguments(int argc, char** argv, | ||||||
| CppLintState* cpplint_state); | ||||||
|
|
||||||
| const fs::path& Root() const { return m_root; } | ||||||
| const fs::path& Repository() const { return m_repository; } | ||||||
| size_t LineLength() const { return m_line_length; } | ||||||
| [[nodiscard]] const fs::path& Root() const { return m_root; } | ||||||
| [[nodiscard]] const fs::path& Repository() const { return m_repository; } | ||||||
| [[nodiscard]] size_t LineLength() const { return m_line_length; } | ||||||
|
|
||||||
| std::set<std::string> GetAllExtensions() const; | ||||||
| std::set<std::string> GetHeaderExtensions() const; | ||||||
| [[nodiscard]] std::set<std::string> GetAllExtensions() const; | ||||||
| [[nodiscard]] std::set<std::string> GetHeaderExtensions() const; | ||||||
|
|
||||||
| bool ProcessConfigOverrides(const fs::path& filename, | ||||||
| CppLintState* cpplint_state); | ||||||
|
|
||||||
| void PrintUsage(const std::string& message = ""); | ||||||
| void PrintUsage(const std::string& message = "") const; | ||||||
|
|
||||||
| int IncludeOrder() const { return m_include_order; } | ||||||
| [[nodiscard]] int IncludeOrder() const { return m_include_order; } | ||||||
|
|
||||||
| const std::vector<Filter>& Filters() const { return m_filters; } | ||||||
| [[nodiscard]] const std::vector<Filter>& Filters() const { return m_filters; } | ||||||
|
|
||||||
| // Adds filters to the existing list of error-message filters. | ||||||
| bool AddFilters(const std::string& filters); | ||||||
|
|
||||||
| // Checks if the error is filtered or not. | ||||||
| bool ShouldPrintError(const std::string& category, | ||||||
| const std::string& filename, size_t linenum) const; | ||||||
| [[nodiscard]] bool ShouldPrintError( | ||||||
| const std::string& category, | ||||||
| const std::string& filename, size_t linenum) const; | ||||||
|
|
||||||
| bool Timing() const { return m_timing; } | ||||||
| [[nodiscard]] bool Timing() const { return m_timing; } | ||||||
| }; | ||||||
Uh oh!
There was an error while loading. Please reload this page.