mit einem Klick
cpp-code-quality
// Improve C++ code quality by identifying duplication, complexity, and design issues. Apply DRY, YAGNI, SRP principles. Use when refactoring, deduplicating, simplifying, or improving backend code in native/c/.
// Improve C++ code quality by identifying duplication, complexity, and design issues. Apply DRY, YAGNI, SRP principles. Use when refactoring, deduplicating, simplifying, or improving backend code in native/c/.
Improve TypeScript code quality in CLI, SDK, and VS Code extension packages. Apply DRY, YAGNI, SRP principles to reduce duplication and complexity. Use when refactoring, deduplicating, simplifying, or improving code in packages/cli/ or packages/sdk/.
Review pull requests for the zowex codebase. Analyze C++ backend and middleware (ibm-clang), TypeScript clients (CLI, SDK, VS Code extension), and z/OS-specific concerns. Use when asked to review a PR, branch, or code changes.
Validate VS Code extensions and CLI plug-ins against Zowe V3 Conformance Criteria. Audit package.json, settings, commands, menus, profile usage, and API registration for conformance. Use when checking Zowe conformance, preparing for conformance submission, auditing an extension/plug-in against Zowe criteria, or when the user mentions conformance.
Use when writing, debugging, or maintaining tests for the native C/C++ and Metal C components in native/c/test/. Covers the custom ztest framework, test patterns, build system integration, and debugging test failures.
Guides users through creating new zowex commands across the Zowe Remote SSH stack (native C++, server, SDK). Use when the user wants to add a new command, implement a zowex command, or add functionality to the native backend.
Prevent data loss and unsafe operations in data set and USS workflows, including cross-profile, cross-LPAR, and overwrites. Use when performing move, copy, upload, rename, or delete operations on z/OS resources.
| name | cpp-code-quality |
| description | Improve C++ code quality by identifying duplication, complexity, and design issues. Apply DRY, YAGNI, SRP principles. Use when refactoring, deduplicating, simplifying, or improving backend code in native/c/. |
Identify and fix code quality issues in the native C++ codebase (native/c/).
Backend and Middleware (ibm-clang): C++17, Clang 18.
Before refactoring, evaluate code against:
malloc/free and raw pointers to avoid ABI issues.std::unique_ptr, std::shared_ptr) to prevent memory leaks.Look for:
Extract helper function:
// Before: duplicated in multiple places
if (zds->diag.e_msg_len > 0) {
memcpy(dest, zds->diag.e_msg, zds->diag.e_msg_len);
}
// After: single helper
static void copy_diag_msg(ZDS *zds, char *dest) {
if (zds->diag.e_msg_len > 0) {
memcpy(dest, zds->diag.e_msg, zds->diag.e_msg_len);
}
}
Use RAII guards (when appropriate for ibm-clang code):
// See DiagMsgGuard pattern in zds.cpp for reference
class ResourceGuard {
Resource *r_;
public:
explicit ResourceGuard(Resource *r) : r_(r) {}
~ResourceGuard() { release(r_); }
ResourceGuard(const ResourceGuard &) = delete;
ResourceGuard &operator=(const ResourceGuard &) = delete;
};
Consolidate similar switch cases:
// Before
case TYPE_A: return handle_type_a(data);
case TYPE_B: return handle_type_b(data);
// After (if logic is similar)
case TYPE_A:
case TYPE_B:
return handle_common(type, data);
Look for:
Signs a function does too much:
Split by responsibility:
// Before: one function doing everything
int process_dataset(const char *name, int flags) {
// validation
// parsing
// transformation
// output
}
// After: separate concerns
int validate_dataset_name(const char *name);
DatasetInfo parse_dataset(const char *name);
TransformResult transform_dataset(DatasetInfo *info, int flags);
int write_output(TransformResult *result);
Early return:
// Before
int process(Data *d) {
if (d != nullptr) {
if (d->valid) {
// 50 lines of logic
}
}
return -1;
}
// After
int process(Data *d) {
if (d == nullptr) return -1;
if (!d->valid) return -1;
// 50 lines of logic
}
Extract conditional logic:
// Before
if (a > 0 && b < 100 && (c == TYPE_A || c == TYPE_B) && d != nullptr) {
// After
static bool is_valid_range(int a, int b) {
return a > 0 && b < 100;
}
static bool is_supported_type(int c) {
return c == TYPE_A || c == TYPE_B;
}
if (is_valid_range(a, b) && is_supported_type(c) && d != nullptr) {
Replace nested if-else with lookup:
// Before
const char *get_error_msg(int code) {
if (code == 1) return "Error A";
else if (code == 2) return "Error B";
// ... many more
}
// After
static const char *ERROR_MSGS[] = { nullptr, "Error A", "Error B", ... };
const char *get_error_msg(int code) {
if (code < 0 || code >= sizeof(ERROR_MSGS)/sizeof(ERROR_MSGS[0])) {
return "Unknown error";
}
return ERROR_MSGS[code];
}
parse_dataset, validate_input, get_member_listzds_, zjb_, zut_ for C++ functions in zds.cpp, zjb.cpp, and zut.cpp respectivelymember_count not cntis_valid, has_members, should_retryMAX_DS_LENGTH, DEFAULT_TIMEOUTWhen improving code quality:
Find potential duplicates:
rg -n "pattern" native/c/ native/zowed/
Analyze function length and complexity: Note: Use structural code search tools or read the target files directly to evaluate function lengths and branches. Avoid brittle brace-matching regex.
From .clang-format:
char *ptr)| Pattern | Issue | Fix |
|---|---|---|
| Magic numbers | Unclear meaning | Extract to named constants |
| God functions | > 100 lines | Split by responsibility |
| Deep nesting | Hard to follow | Early returns, extract functions |
| Commented code | Clutters codebase | Delete (use git history) |
| Boolean parameters | Unclear at call site | Use enums or separate functions |
| Copy-paste code | Maintenance burden | Extract shared function |