[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [clazy] /: Support env variables with quotes
From:       Sergio Martins <null () kde ! org>
Date:       2017-04-30 19:19:44
Message-ID: E1d4uNk-0005Ob-5R () code ! kde ! org
[Download RAW message or body]

Git commit ec1cd9d2c4eb0008372531d650367a7573b40553 by Sergio Martins.
Committed on 30/04/2017 at 19:17.
Pushed by smartins into branch 'master'.

Support env variables with quotes

When using the shell directly env variables won't have the quotes,
but some people use QtCreator and specify the list of checks
in between quotes.

Now we strip quotes, otherwise we would get an error like:
Invalid check: "level1"

M  +6    -4    src/checkmanager.cpp
M  +9    -0    src/clazy_stl.h
M  +5    -0    tests/clazy/test_requested_checks.sh
M  +2    -0    tests/clazy/test_requested_checks.sh.expected

https://commits.kde.org/clazy/ec1cd9d2c4eb0008372531d650367a7573b40553

diff --git a/src/checkmanager.cpp b/src/checkmanager.cpp
index b6ac6c1..bfcea8a 100644
--- a/src/checkmanager.cpp
+++ b/src/checkmanager.cpp
@@ -41,10 +41,11 @@ CheckManager::CheckManager()
     m_registeredChecks.reserve(30);
     const char *fixitsEnv = getenv("CLAZY_FIXIT");
     if (fixitsEnv) {
-        if (string(fixitsEnv) == string("all_fixits")) {
+        const string fixitsEnvStr = clazy_std::unquoteString(fixitsEnv);
+        if (fixitsEnvStr == "all_fixits") {
             m_enableAllFixits = true;
         } else {
-            m_requestedFixitName = string(fixitsEnv);
+            m_requestedFixitName = fixitsEnvStr;
         }
     }
 }
@@ -168,8 +169,9 @@ RegisteredCheck::List \
CheckManager::requestedChecksThroughEnv(vector<string> &us  if \
(requestedChecksThroughEnv.empty()) {  const char *checksEnv = \
getenv("CLAZY_CHECKS");  if (checksEnv) {
-            requestedChecksThroughEnv = string(checksEnv) == "all_checks" ? \
                availableChecks(CheckLevel2)
-                                                                          : \
checksForCommaSeparatedString(checksEnv, /*by-ref=*/ userDisabledChecks); +           \
const string checksEnvStr = clazy_std::unquoteString(checksEnv); +            \
requestedChecksThroughEnv = checksEnvStr == "all_checks" ? \
availableChecks(CheckLevel2) +                                                        \
: checksForCommaSeparatedString(checksEnvStr, /*by-ref=*/ userDisabledChecks);  }
 
         const string checkName = checkNameForFixIt(m_requestedFixitName);
diff --git a/src/clazy_stl.h b/src/clazy_stl.h
index ef2fb96..b31f443 100644
--- a/src/clazy_stl.h
+++ b/src/clazy_stl.h
@@ -248,6 +248,15 @@ void sort_and_remove_dups(Container &c, LessThan lessThan)
     c.erase(std::unique(c.begin(), c.end()), c.end());
 }
 
+inline std::string unquoteString(const std::string &str)
+{
+    // If first and last are ", return what's in between quotes:
+    if (str.size() >= 3 && str[0] == '"' && str.at(str.size() - 1) == '"')
+        return str.substr(1, str.size() - 2);
+
+    return str;
+}
+
 }
 
 #endif
diff --git a/tests/clazy/test_requested_checks.sh \
b/tests/clazy/test_requested_checks.sh index a6765bc..ddb8cad 100755
--- a/tests/clazy/test_requested_checks.sh
+++ b/tests/clazy/test_requested_checks.sh
@@ -73,6 +73,11 @@ echo | $($CLAZY_COMMAND -Xclang -plugin-arg-clang-lazy -Xclang \
implicit-casts,fo  export CLAZY_CHECKS="level1"
 echo | $CLAZY_COMMAND_STDIN
 
+# Should also work with quotes. Users sometimes add quotes in QtCreator.
+echo Test9
+export CLAZY_CHECKS=\"level1\"
+echo | $CLAZY_COMMAND_STDIN
+
 # Use a level in env-variable + another check
 export CLAZY_CHECKS="level0,reserve-candidates"
 echo | $CLAZY_COMMAND_STDIN
diff --git a/tests/clazy/test_requested_checks.sh.expected \
b/tests/clazy/test_requested_checks.sh.expected index eef3360..7a04614 100644
--- a/tests/clazy/test_requested_checks.sh.expected
+++ b/tests/clazy/test_requested_checks.sh.expected
@@ -18,6 +18,8 @@ Requested checks: connect-non-signal, container-anti-pattern, \
lambda-in-connect,  Requested checks: connect-non-signal, container-anti-pattern, \
lambda-in-connect, mutable-container-key, qcolor-from-literal, qdatetime-utc, qenums, \
qfileinfo-exists, qgetenv, qmap-with-pointer-key, qstring-arg, \
qstring-insensitive-allocation, qstring-ref, qt-macros, \
qvariant-template-instantiation, temporary-iterator, unused-non-trivial-variable, \
writing-to-temporary, wrong-qglobalstatic  Requested checks: connect-non-signal, \
container-anti-pattern, foreach, implicit-casts, lambda-in-connect, \
mutable-container-key, qcolor-from-literal, qdatetime-utc, qenums, qfileinfo-exists, \
qgetenv, qmap-with-pointer-key, qstring-arg, qstring-insensitive-allocation, \
qstring-ref, qt-macros, qvariant-template-instantiation, temporary-iterator, \
unused-non-trivial-variable, writing-to-temporary, wrong-qglobalstatic  Requested \
checks: auto-unexpected-qstringbuilder, child-event-qobject-cast, connect-non-signal, \
container-anti-pattern, detaching-temporary, foreach, incorrect-emit, \
inefficient-qlist-soft, install-event-filter, lambda-in-connect, \
missing-qobject-macro, mutable-container-key, non-pod-global-static, post-event, \
qcolor-from-literal, qdatetime-utc, qdeleteall, qenums, qfileinfo-exists, qgetenv, \
qlatin1string-non-ascii, qmap-with-pointer-key, qstring-arg, \
qstring-insensitive-allocation, qstring-left, qstring-ref, qt-macros, \
qvariant-template-instantiation, range-loop, returning-data-from-temporary, \
rule-of-two-soft, temporary-iterator, unused-non-trivial-variable, \
writing-to-temporary, wrong-qglobalstatic +Test9
+Requested checks: auto-unexpected-qstringbuilder, child-event-qobject-cast, \
connect-non-signal, container-anti-pattern, detaching-temporary, foreach, \
incorrect-emit, inefficient-qlist-soft, install-event-filter, lambda-in-connect, \
missing-qobject-macro, mutable-container-key, non-pod-global-static, post-event, \
qcolor-from-literal, qdatetime-utc, qdeleteall, qenums, qfileinfo-exists, qgetenv, \
qlatin1string-non-ascii, qmap-with-pointer-key, qstring-arg, \
qstring-insensitive-allocation, qstring-left, qstring-ref, qt-macros, \
qvariant-template-instantiation, range-loop, returning-data-from-temporary, \
rule-of-two-soft, temporary-iterator, unused-non-trivial-variable, \
writing-to-temporary, wrong-qglobalstatic  Requested checks: connect-non-signal, \
container-anti-pattern, lambda-in-connect, mutable-container-key, \
qcolor-from-literal, qdatetime-utc, qenums, qfileinfo-exists, qgetenv, \
qmap-with-pointer-key, qstring-arg, qstring-insensitive-allocation, qstring-ref, \
qt-macros, qvariant-template-instantiation, reserve-candidates, temporary-iterator, \
unused-non-trivial-variable, writing-to-temporary, wrong-qglobalstatic  Requested \
checks: connect-non-signal, container-anti-pattern, implicit-casts, \
lambda-in-connect, mutable-container-key, qcolor-from-literal, qdatetime-utc, qenums, \
qfileinfo-exists, qgetenv, qmap-with-pointer-key, qstring-arg, \
qstring-insensitive-allocation, qstring-ref, qt-macros, \
qvariant-template-instantiation, reserve-candidates, temporary-iterator, \
unused-non-trivial-variable, writing-to-temporary, wrong-qglobalstatic  Requested \
checks: implicit-casts


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic