CmdLineParser: deprecated `--template <template>` and `--template-location <template>` (#5331)

Both are bugprone since they just take the next parameter which doesn't
start with `-`.

Also `--template` has not been documented since
17842394c0 back in 2011(!). And
`--template-location` has never been documented since its induction in
f058d9ad08. That's also why we can have a
short deprecation period.
This commit is contained in:
Oliver Stöneberg 2023-08-18 11:59:14 +02:00 committed by GitHub
parent 33dee83c21
commit c7f88db90a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 14 deletions

View File

@ -899,7 +899,6 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
} }
} }
// TODO: deprecate "--template <template>"
// Output formatter // Output formatter
else if (std::strcmp(argv[i], "--template") == 0 || else if (std::strcmp(argv[i], "--template") == 0 ||
std::strncmp(argv[i], "--template=", 11) == 0) { std::strncmp(argv[i], "--template=", 11) == 0) {
@ -907,6 +906,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
if (argv[i][10] == '=') if (argv[i][10] == '=')
mSettings.templateFormat = argv[i] + 11; mSettings.templateFormat = argv[i] + 11;
else if ((i+1) < argc && argv[i+1][0] != '-') { else if ((i+1) < argc && argv[i+1][0] != '-') {
printMessage("'--template <template>' is deprecated and will be removed in 2.13 - please use '--template=<template>' instead");
++i; ++i;
mSettings.templateFormat = argv[i]; mSettings.templateFormat = argv[i];
} else { } else {
@ -935,13 +935,13 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
} }
} }
// TODO: deprecate "--template-location <template>"
else if (std::strcmp(argv[i], "--template-location") == 0 || else if (std::strcmp(argv[i], "--template-location") == 0 ||
std::strncmp(argv[i], "--template-location=", 20) == 0) { std::strncmp(argv[i], "--template-location=", 20) == 0) {
// "--template-location format" // "--template-location format"
if (argv[i][19] == '=') if (argv[i][19] == '=')
mSettings.templateLocation = argv[i] + 20; mSettings.templateLocation = argv[i] + 20;
else if ((i+1) < argc && argv[i+1][0] != '-') { else if ((i+1) < argc && argv[i+1][0] != '-') {
printMessage("'--template-location <template>' is deprecated and will be removed in 2.13 - please use '--template-location=<template>' instead");
++i; ++i;
mSettings.templateLocation = argv[i]; mSettings.templateLocation = argv[i];
} else { } else {

View File

@ -1,4 +1,4 @@
release notes for cppcheck-2.12 Release Notes for Cppcheck 2.12
New checks: New checks:
- uselessOverride finds overriding functions that either duplicate code from or delegate back to the base class implementation - uselessOverride finds overriding functions that either duplicate code from or delegate back to the base class implementation
@ -14,6 +14,8 @@ Changed interface:
Deprecations: Deprecations:
- The qmake build system has been deprecated and will be removed in a future version. - The qmake build system has been deprecated and will be removed in a future version.
- Command-line option '--template <template>' is deprecated and will be removed in 2.13 - please use '--template=<template>' instead.
- Command-line option '--template-location <template>' is deprecated and will be removed in 2.13 - please use '--template-location=<template>' instead.
Other: Other:
- "USE_QT6=On" will no longer fallback to Qt5 when Qt6 is not found. - "USE_QT6=On" will no longer fallback to Qt5 when Qt6 is not found.

View File

@ -1335,10 +1335,10 @@ private:
void templates() { void templates() {
REDIRECT; REDIRECT;
const char * const argv[] = {"cppcheck", "--template", "{file}:{line},{severity},{id},{message}", "--template-location={file}:{line}:{column} {info}", "file.cpp"}; const char * const argv[] = {"cppcheck", "--template={file}:{line},{severity},{id},{message}", "--template-location={file}:{line}:{column} {info}", "file.cpp"};
settings->templateFormat.clear(); settings->templateFormat.clear();
settings->templateLocation.clear(); settings->templateLocation.clear();
ASSERT(parser->parseFromArgs(5, argv)); ASSERT(parser->parseFromArgs(4, argv));
ASSERT_EQUALS("{file}:{line},{severity},{id},{message}", settings->templateFormat); ASSERT_EQUALS("{file}:{line},{severity},{id},{message}", settings->templateFormat);
ASSERT_EQUALS("{file}:{line}:{column} {info}", settings->templateLocation); ASSERT_EQUALS("{file}:{line}:{column} {info}", settings->templateLocation);
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
@ -1346,10 +1346,10 @@ private:
void templatesGcc() { void templatesGcc() {
REDIRECT; REDIRECT;
const char * const argv[] = {"cppcheck", "--template", "gcc", "file.cpp"}; const char * const argv[] = {"cppcheck", "--template=gcc", "file.cpp"};
settings->templateFormat.clear(); settings->templateFormat.clear();
settings->templateLocation.clear(); settings->templateLocation.clear();
ASSERT(parser->parseFromArgs(4, argv)); ASSERT(parser->parseFromArgs(3, argv));
ASSERT_EQUALS("{file}:{line}:{column}: warning: {message} [{id}]\n{code}", settings->templateFormat); ASSERT_EQUALS("{file}:{line}:{column}: warning: {message} [{id}]\n{code}", settings->templateFormat);
ASSERT_EQUALS("{file}:{line}:{column}: note: {info}\n{code}", settings->templateLocation); ASSERT_EQUALS("{file}:{line}:{column}: note: {info}\n{code}", settings->templateLocation);
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
@ -1357,10 +1357,10 @@ private:
void templatesVs() { void templatesVs() {
REDIRECT; REDIRECT;
const char * const argv[] = {"cppcheck", "--template", "vs", "file.cpp"}; const char * const argv[] = {"cppcheck", "--template=vs", "file.cpp"};
settings->templateFormat.clear(); settings->templateFormat.clear();
settings->templateLocation.clear(); settings->templateLocation.clear();
ASSERT(parser->parseFromArgs(4, argv)); ASSERT(parser->parseFromArgs(3, argv));
ASSERT_EQUALS("{file}({line}): {severity}: {message}", settings->templateFormat); ASSERT_EQUALS("{file}({line}): {severity}: {message}", settings->templateFormat);
ASSERT_EQUALS("", settings->templateLocation); ASSERT_EQUALS("", settings->templateLocation);
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
@ -1368,10 +1368,10 @@ private:
void templatesEdit() { void templatesEdit() {
REDIRECT; REDIRECT;
const char * const argv[] = {"cppcheck", "--template", "edit", "file.cpp"}; const char * const argv[] = {"cppcheck", "--template=edit", "file.cpp"};
settings->templateFormat.clear(); settings->templateFormat.clear();
settings->templateLocation.clear(); settings->templateLocation.clear();
ASSERT(parser->parseFromArgs(4, argv)); ASSERT(parser->parseFromArgs(3, argv));
ASSERT_EQUALS("{file} +{line}: {severity}: {message}", settings->templateFormat); ASSERT_EQUALS("{file} +{line}: {severity}: {message}", settings->templateFormat);
ASSERT_EQUALS("", settings->templateLocation); ASSERT_EQUALS("", settings->templateLocation);
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
@ -1439,7 +1439,9 @@ private:
ASSERT(!parser->parseFromArgs(3, argv)); ASSERT(!parser->parseFromArgs(3, argv));
ASSERT_EQUALS("file.cpp", settings->templateFormat); ASSERT_EQUALS("file.cpp", settings->templateFormat);
ASSERT_EQUALS("", settings->templateLocation); ASSERT_EQUALS("", settings->templateLocation);
TODO_ASSERT_EQUALS("cppcheck: error: argument to '--template' is missing.\n", "cppcheck: error: no C or C++ source files found.\n", GET_REDIRECT_OUTPUT); TODO_ASSERT_EQUALS("cppcheck: error: argument to '--template' is missing.\n",
"cppcheck: '--template <template>' is deprecated and will be removed in 2.13 - please use '--template=<template>' instead\n"
"cppcheck: error: no C or C++ source files found.\n", GET_REDIRECT_OUTPUT);
} }
// will use the default // will use the default
@ -1462,7 +1464,7 @@ private:
ASSERT_EQUALS("cppcheck: error: argument to '--template-location' is missing.\n", GET_REDIRECT_OUTPUT); ASSERT_EQUALS("cppcheck: error: argument to '--template-location' is missing.\n", GET_REDIRECT_OUTPUT);
} }
// TODO: will not error out as he next option does not start with a "-" // TODO: will not error out as the next option does not start with a "-"
void templateLocationInvalid2() { void templateLocationInvalid2() {
REDIRECT; REDIRECT;
settings->templateFormat.clear(); settings->templateFormat.clear();
@ -1471,7 +1473,9 @@ private:
ASSERT(!parser->parseFromArgs(3, argv)); ASSERT(!parser->parseFromArgs(3, argv));
ASSERT_EQUALS("{file}:{line}:{column}: {inconclusive:}{severity}:{inconclusive: inconclusive:} {message} [{id}]\n{code}", settings->templateFormat); ASSERT_EQUALS("{file}:{line}:{column}: {inconclusive:}{severity}:{inconclusive: inconclusive:} {message} [{id}]\n{code}", settings->templateFormat);
ASSERT_EQUALS("file.cpp", settings->templateLocation); ASSERT_EQUALS("file.cpp", settings->templateLocation);
TODO_ASSERT_EQUALS("", "cppcheck: error: no C or C++ source files found.\n", GET_REDIRECT_OUTPUT); TODO_ASSERT_EQUALS("",
"cppcheck: '--template-location <template>' is deprecated and will be removed in 2.13 - please use '--template-location=<template>' instead\n"
"cppcheck: error: no C or C++ source files found.\n", GET_REDIRECT_OUTPUT);
} }
// will use the default // will use the default