From 6e8ec586721f5a937ce4c9183df09536b47a97dd Mon Sep 17 00:00:00 2001 From: Lucas Cimon <925560+Lucas-C@users.noreply.github.com> Date: Wed, 31 Mar 2021 15:31:45 +0200 Subject: [PATCH] Zero return status code when all errors & warnings have been muted - close #933 --- console/tidy.c | 4 ++-- include/tidy.h | 12 ++++++++++++ src/message.c | 4 ++++ src/tidy-int.h | 2 ++ src/tidylib.c | 16 ++++++++++++++++ 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/console/tidy.c b/console/tidy.c index 3a3d9ad8e..2565401d8 100644 --- a/console/tidy.c +++ b/console/tidy.c @@ -2544,8 +2544,8 @@ int main( int argc, char** argv ) } } - contentErrors += tidyErrorCount( tdoc ); - contentWarnings += tidyWarningCount( tdoc ); + contentErrors += tidyErrorCount( tdoc ) - tidyMutedErrorCount( tdoc ); + contentWarnings += tidyWarningCount( tdoc ) - tidyMutedWarningCount( tdoc ); accessWarnings += tidyAccessWarningCount( tdoc ); --argc; diff --git a/include/tidy.h b/include/tidy.h index da80857e8..f78ba3bc7 100644 --- a/include/tidy.h +++ b/include/tidy.h @@ -444,12 +444,24 @@ TIDY_EXPORT Bool TIDY_CALL tidyDetectedGenericXml( TidyDoc tdoc ); */ TIDY_EXPORT uint TIDY_CALL tidyErrorCount( TidyDoc tdoc ); +/** Indicates the number of error messages muted, that won't be output. + ** @param tdoc An instance of a TidyDoc to query. + ** @result Returns the number of muted error messages. + */ +TIDY_EXPORT uint TIDY_CALL tidyMutedErrorCount( TidyDoc tdoc ); + /** Indicates the number of TidyWarning messages that were generated. ** @param tdoc An instance of a TidyDoc to query. ** @result Returns the number of TidyWarning messages that were generated. */ TIDY_EXPORT uint TIDY_CALL tidyWarningCount( TidyDoc tdoc ); +/** Indicates the number of warning messages muted, that won't be output. + ** @param tdoc An instance of a TidyDoc to query. + ** @result Returns the number of muted warning messages. + */ +TIDY_EXPORT uint TIDY_CALL tidyMutedWarningCount( TidyDoc tdoc ); + /** Indicates the number of TidyAccess messages that were generated. ** @param tdoc An instance of a TidyDoc to query. ** @result Returns the number of TidyAccess messages that were generated. diff --git a/src/message.c b/src/message.c index ee2e6c6f3..fac740771 100644 --- a/src/message.c +++ b/src/message.c @@ -133,6 +133,8 @@ static void messageOut( TidyMessageImpl *message ) break; case TidyWarning: doc->warnings++; + if ( message->muted ) + doc->mutedWarningCount++; break; case TidyConfig: doc->optionErrors++; @@ -142,6 +144,8 @@ static void messageOut( TidyMessageImpl *message ) break; case TidyError: doc->errors++; + if ( message->muted ) + doc->mutedErrorCount++; break; case TidyBadDocument: doc->docErrors++; diff --git a/src/tidy-int.h b/src/tidy-int.h index 55ab3416a..0650c0f0e 100644 --- a/src/tidy-int.h +++ b/src/tidy-int.h @@ -65,7 +65,9 @@ struct _TidyDocImpl /* Parse + Repair Results */ uint optionErrors; uint errors; + uint mutedErrorCount; uint warnings; + uint mutedWarningCount; uint accessErrors; uint infoMessages; uint docErrors; diff --git a/src/tidylib.c b/src/tidylib.c index 75cb1d964..46d566fe2 100644 --- a/src/tidylib.c +++ b/src/tidylib.c @@ -1044,6 +1044,14 @@ uint TIDY_CALL tidyErrorCount( TidyDoc tdoc ) count = impl->errors; return count; } +uint TIDY_CALL tidyMutedErrorCount( TidyDoc tdoc ) +{ + TidyDocImpl* impl = tidyDocToImpl( tdoc ); + uint count = 0xFFFFFFFF; + if ( impl ) + count = impl->mutedErrorCount; + return count; +} uint TIDY_CALL tidyWarningCount( TidyDoc tdoc ) { TidyDocImpl* impl = tidyDocToImpl( tdoc ); @@ -1052,6 +1060,14 @@ uint TIDY_CALL tidyWarningCount( TidyDoc tdoc ) count = impl->warnings; return count; } +uint TIDY_CALL tidyMutedWarningCount( TidyDoc tdoc ) +{ + TidyDocImpl* impl = tidyDocToImpl( tdoc ); + uint count = 0xFFFFFFFF; + if ( impl ) + count = impl->mutedWarningCount; + return count; +} uint TIDY_CALL tidyAccessWarningCount( TidyDoc tdoc ) { TidyDocImpl* impl = tidyDocToImpl( tdoc );