crap-score
यह क्या करती है
यह स्किल किसी नामित .NET method, class या फ़ाइल के लिए CRAP स्कोर निकालती है। यह स्कोर code की जटिलता और उसकी परख की अच्छाई को मिलाकर जोखिम भरा code उजागर करता है। यह उन डेवलपर के लिए है जो तय कर रहे हैं कि पहले किस code के tests लिखें।
कब इस्तेमाल करें
- ✓जब आपको किसी खास method, class या फ़ाइल का जोखिम स्कोर चाहिए।
- ✓जब आपको एक नामित code के भीतर पहले कौन से tests लिखने हैं, यह तय करना हो।
- ✓जब आप जाँचना चाहें कि कोई जटिल method बदलना सुरक्षित है या नहीं।
Skill का लिंक
https://github.com/dotnet/skills/blob/main/plugins/dotnet-test/skills/crap-score/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“OrderProcessor class का CRAP स्कोर क्या है, और मुझे उसकी कौन सी methods के tests पहले लिखने चाहिए?”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
एजेंट नामित code की जटिलता और coverage मापता है, CRAP सूत्र लगाता है, और methods को रैंक करता है ताकि सबसे जोखिम वाली पहले आएँ।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
CRAP Score Analysis
Calculate CRAP (Change Risk Anti-Patterns) scores for .NET methods to identify code that is both complex and undertested.
Background
The CRAP score combines cyclomatic complexity and code coverage into a single metric:
$$\text{CRAP}(m) = \text{comp}(m)^2 \times (1 - \text{cov}(m))^3 + \text{comp}(m)$$
Where:
- $\text{comp}(m)$ = cyclomatic complexity of method $m$
- $\text{cov}(m)$ = code coverage ratio (0.0 to 1.0) of method $m$
| CRAP Score | Risk Level | Interpretation |
|---|---|---|
| < 5 | Low | Simple and well-tested |
| 5 to < 15 | Moderate | Acceptable for most code |
| 15 to 30 | High | Needs more tests or simplification |
| > 30 | Critical | Refactor and add coverage urgently |
A method with 100% coverage has CRAP = complexity (the minimum). A method with 0% coverage has CRAP = complexity^2 + complexity.
When to Use
- User wants to assess which methods are risky due to low coverage and high complexity
- User asks for CRAP score of specific methods, classes, or files
- User wants to prioritize what to test next within a named method, class, or file based on coverage-and-complexity risk
- User wants to evaluate test quality beyond simple coverage percentages
When Not to Use
- User just wants to run tests (use
run-testsskill) - User wants to write new tests (use
code-testing) - User only wants a coverage percentage without complexity analysis
- User wants project-wide coverage/CRAP analysis or priorities (use
coverage-analysis)
Inputs
| Input | Required | Description |
|---|---|---|
| Target scope | Yes | Method name, class name, or file path to analyze |
| Test project path | No | Path to the test project. Defaults to discovering test projects in the solution. |
| Source project path | No | Path to the source project under analysis |
Workflow
Step 1: Collect code coverage data
If the user supplies a valid Cobertura report that contains the requested
target, use it directly and do not rerun tests. If the supplied report is
malformed, empty, internally contradictory, or missing the target, treat it as
failed input: regenerate it with a repository-compatible command when possible,
or request a valid report when collection is unavailable. Otherwise invoke
run-tests to classify the repository's test platform and confirm the
compatible command shape, then require a command that emits Cobertura:
| Coverage provider | Cobertura command |
|---|---|
coverlet.collector with VSTest |
dotnet test <test.csproj> --collect:"XPlat Code Coverage" --results-directory <results-dir> |
Microsoft.Testing.Extensions.CodeCoverage with .NET 9 bridged MTP |
dotnet test <test.csproj> -- --coverage --coverage-output-format cobertura --coverage-output <output-path> |
Microsoft.Testing.Extensions.CodeCoverage with .NET 10+ native MTP |
dotnet test --project <test.csproj> --coverage --coverage-output-format cobertura --coverage-output <output-path> |
Use an equivalent repository-owned command when the project defines one. Search
the results directory recursively when the collector creates a GUID subfolder.
Do not substitute a generic binary .coverage command when no converter is
available.
Do not stop at the first restore, compilation, test, or collector failure. Classify the failing layer, inspect every report the command emitted, and exhaust non-persistent retries before asking for input. Safe retries include command-line MSBuild properties that leave source and manifests unchanged and an already-installed or repository-provided alternative collector. A trivial source error is a collection blocker, not the final analysis, when a reversible command-line setting can compile the same source. Never call an empty Cobertura file a successful fallback.
For classic non-SDK projects (ToolsVersion, explicit compile items, or
packages.config), use only a repository-provided coverage command that emits
Cobertura. If none exists, request Cobertura XML and stop; do not migrate the
project or inject an SDK-style provider. CRAP scores always require real
coverage data.
Never estimate coverage
Guessed coverage produces wrong CRAP scores, which is worse than no answer. For a classic project with no repository coverage command or existing report, stop here and request Cobertura.
Do not add coverage packages, change project manifests, or install global tools un
अक्सर पूछे जाने वाले सवाल
उच्च CRAP स्कोर का क्या मतलब है?
इसका मतलब है code जटिल है और ठीक से परखा नहीं गया, इसलिए वहाँ बदलाव से समस्या होने की संभावना ज़्यादा है।
क्या यह पूरे प्रोजेक्ट का स्कोर निकाल सकती है?
नहीं। प्रोजेक्ट-व्यापी coverage और CRAP विश्लेषण एक अलग स्किल के हिस्से हैं।
क्या यह tests लिखती है?
नहीं। यह प्राथमिकताएँ दिखाती है, और tests लिखना दूसरी स्किल संभालती है।
जानकारी
लेखक का मूल विवरण
Calculates CRAP (Change Risk Anti-Patterns) for a named .NET method, class, or file. USE FOR: explicit CRAP calculation or coverage-and-complexity risk within that named target, including which tests to prioritize. DO NOT USE FOR: project-wide coverage/CRAP, plateaus, or project-wide blockers/priorities (coverage-analysis); behavioral/pseudo-mutation gaps (test-gap-analysis); writing tests; test runs without CRAP context.
repo: dotnet/skills
लोकप्रियता
- GitHub स्टार
- 5.8k
- रैंकिंग में स्थान
- #14626
- लाइसेंस
- MIT
- अपडेट की गई
- 2/11/2026
कमेंट
- …
इस repository की और skills
create-custom-agent
5.8kयह आपके एजेंट को VS Code के custom agent फ़ाइलें बनाने देती है, जिनके अपने tools, निर्देश और दूसरे agents को handoffs होते हैं।
create-skill
5.8kयह आपके एजेंट को सही नाम, साफ़ trigger विवरण और मानक के अनुसार SKILL.md फ़ाइल वाली नई agent skill बनाने में मदद करती है।
csharp-scripts
5.8kयह आपके एजेंट को .NET command line टूल से एक छोटा C# प्रोग्राम एकल फ़ाइल के रूप में चलाने देती है, पूरा प्रोजेक्ट बनाए बिना।
dotnet-pinvoke
5.8kयह आपके एजेंट को .NET से native C या C++ libraries सही तरीके से कॉल करने में मदद करती है, जिसमें signatures, string संभालना, memory और सुरक्षित handles शामिल हैं।
मिलती-जुलती skills
test-driven-development
311kयह आपके एजेंट को किसी भी फ़ीचर या सुधार से पहले पहले असफल होने वाला टेस्ट लिखना, उसे असफल होते देखना, फिर पास करने वाला सबसे छोटा कोड लिखना सिखाती है।
verification-before-completion
311kयह आपके एजेंट को किसी काम, सुधार या build के पूरा या पास होने का दावा करने से पहले असली जांच चलाकर उसका आउटपुट पढ़ना सिखाती है।
migrate-to-shoehorn
310kआपकी टेस्ट फ़ाइलों में जोखिम भरे type casts की जगह shoehorn लाइब्रेरी लगाती है, ताकि टेस्ट अधूरे डेटा से भी type checks पास कर सकें।