[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6EDK7JHEVHH2MTY7N0Y9X6R":3,"skill-same:01M6EDK7JHEVHH2MTY7N0Y9X6R":48},{"skillNo":4,"name":5,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":21,"linkOnly":22,"markdownContent":23,"markdownBody":23,"frontMatter":24,"refName":25,"commitSha":26,"skillDirectory":27,"forksCount":28,"repositoryHtmlUrl":29,"repositoryHomepageUrl":30,"ownerHtmlUrl":31,"ownerBlogUrl":6,"ownerDescription":32,"updatedAt":33,"install":34,"resources":47},"01M6EDK7JHEVHH2MTY7N0Y9X6R","code-refactoring",null,"ComeOnOliver\u002Fskillshub","ComeOnOliver","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F43215937?v=4","01M6E5JNFECJAAVFE0W7SMWWD2","Haoran Shu","01M6E5JNNDQS7AJZDYFQ8TPZCK",67,"MIT","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002FMoizIbnYousaf\u002FAi-Agent-Skills\u002Fcode-refactoring\u002FSKILL.md",[],[18,19,20],"code","refactoring","code refactoring","2026-11-10 10:12:30",false,"# Code Refactoring\n\n## Refactoring Principles\n\n### When to Refactor\n- Before adding new features (make change easy, then make easy change)\n- After getting tests passing (red-green-refactor)\n- When you see code smells\n- During code review feedback\n\n### When NOT to Refactor\n- Without tests covering the code\n- Under tight deadlines with no safety net\n- Code that will be replaced soon\n- When you don't understand what the code does\n\n## Common Code Smells\n\n### Long Methods\n```typescript\n\u002F\u002F BEFORE: Method doing too much\nfunction processOrder(order: Order) {\n  \u002F\u002F 100 lines of validation, calculation, notification, logging...\n}\n\n\u002F\u002F AFTER: Extract into focused methods\nfunction processOrder(order: Order) {\n  validateOrder(order);\n  const total = calculateTotal(order);\n  saveOrder(order, total);\n  notifyCustomer(order);\n}\n```\n\n### Deeply Nested Conditionals\n```typescript\n\u002F\u002F BEFORE: Arrow code\nfunction getDiscount(user: User, order: Order) {\n  if (user) {\n    if (user.isPremium) {\n      if (order.total > 100) {\n        if (order.items.length > 5) {\n          return 0.2;\n        }\n      }\n    }\n  }\n  return 0;\n}\n\n\u002F\u002F AFTER: Early returns (guard clauses)\nfunction getDiscount(user: User, order: Order) {\n  if (!user) return 0;\n  if (!user.isPremium) return 0;\n  if (order.total \u003C= 100) return 0;\n  if (order.items.length \u003C= 5) return 0;\n  return 0.2;\n}\n```\n\n### Primitive Obsession\n```typescript\n\u002F\u002F BEFORE: Primitives everywhere\nfunction createUser(name: string, email: string, phone: string) {\n  if (!email.includes('@')) throw new Error('Invalid email');\n  \u002F\u002F more validation...\n}\n\n\u002F\u002F AFTER: Value objects\nclass Email {\n  constructor(private value: string) {\n    if (!value.includes('@')) throw new Error('Invalid email');\n  }\n  toString() { return this.value; }\n}\n\nfunction createUser(name: string, email: Email, phone: Phone) {\n  \u002F\u002F Email is already validated\n}\n```\n\n### Feature Envy\n```typescript\n\u002F\u002F BEFORE: Method uses another object's data extensively\nfunction calculateShipping(order: Order) {\n  const address = order.customer.address;\n  const weight = order.items.reduce((sum, i) => sum + i.weight, 0);\n  const distance = calculateDistance(address.zip);\n  return weight * distance * 0.01;\n}\n\n\u002F\u002F AFTER: Move method to where the data is\nclass Order {\n  calculateShipping() {\n    return this.totalWeight * this.customer.shippingDistance * 0.01;\n  }\n}\n```\n\n## Refactoring Techniques\n\n### Extract Method\n```typescript\n\u002F\u002F Identify a code block that does one thing\n\u002F\u002F Move it to a new method with a descriptive name\n\u002F\u002F Replace original code with method call\n\nfunction printReport(data: ReportData) {\n  \u002F\u002F Extract this block...\n  const header = `Report: ${data.title}\\nDate: ${data.date}\\n${'='.repeat(40)}`;\n  console.log(header);\n\n  \u002F\u002F ...into a method\n  printHeader(data);\n}\n```\n\n### Replace Conditional with Polymorphism\n```typescript\n\u002F\u002F BEFORE: Switch on type\nfunction getArea(shape: Shape) {\n  switch (shape.type) {\n    case 'circle': return Math.PI * shape.radius ** 2;\n    case 'rectangle': return shape.width * shape.height;\n    case 'triangle': return shape.base * shape.height \u002F 2;\n  }\n}\n\n\u002F\u002F AFTER: Polymorphic classes\ninterface Shape {\n  getArea(): number;\n}\n\nclass Circle implements Shape {\n  constructor(private radius: number) {}\n  getArea() { return Math.PI * this.radius ** 2; }\n}\n\nclass Rectangle implements Shape {\n  constructor(private width: number, private height: number) {}\n  getArea() { return this.width * this.height; }\n}\n```\n\n### Introduce Parameter Object\n```typescript\n\u002F\u002F BEFORE: Too many parameters\nfunction searchProducts(\n  query: string,\n  minPrice: number,\n  maxPrice: number,\n  category: string,\n  inStock: boolean,\n  sortBy: string,\n  sortOrder: string\n) { ... }\n\n\u002F\u002F AFTER: Parameter object\ninterface SearchParams {\n  query: string;\n  priceRange: { min: number; max: number };\n  category?: string;\n  inStock?: boolean;\n  sort?: { by: string; order: 'asc' | 'desc' };\n}\n\nfunction searchProducts(params: SearchParams) { ... }\n```\n\n### Replace Magic Numbers with Constants\n```typescript\n\u002F\u002F BEFORE\nif (user.age >= 18 && order.total >= 50) {\n  applyDiscount(order, 0.1);\n}\n\n\u002F\u002F AFTER\nconst MINIMUM_AGE = 18;\nconst DISCOUNT_THRESHOLD = 50;\nconst STANDARD_DISCOUNT = 0.1;\n\nif (user.age >= MINIMUM_AGE && order.total >= DISCOUNT_THRESHOLD) {\n  applyDiscount(order, STANDARD_DISCOUNT);\n}\n```\n\n## Safe Refactoring Process\n\n1. **Ensure tests exist** - Write tests if they don't\n2. **Make small changes** - One refactoring at a time\n3. **Run tests after each change** - Catch regressions immediately\n4. **Commit frequently** - Easy to revert if something breaks\n5. **Review the diff** - Make sure behavior hasn't changed\n\n## Refactoring Checklist\n\n- [ ] Tests pass before starting\n- [ ] Each change is small and focused\n- [ ] Tests pass after each change\n- [ ] No behavior changes (only structure)\n- [ ] Code is more readable than before\n- [ ] Commit message explains the refactoring\n",{},"main","def8531e65114c0fca8fb8551c1871ee0eed705c","skills\u002FMoizIbnYousaf\u002FAi-Agent-Skills\u002Fcode-refactoring",24,"https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub","https:\u002F\u002Fskillshub.wtf","https:\u002F\u002Fgithub.com\u002FComeOnOliver","AI & Blockchain Engineer\r\n","2026-06-24 22:07:19",{"source":7,"skillName":5,"commands":35,"prompt":45,"zipAvailable":46},[36,39,42],{"tool":37,"command":38},"npx","npx skills add ComeOnOliver\u002Fskillshub --skill code-refactoring",{"tool":40,"command":41},"bunx","bunx skills add ComeOnOliver\u002Fskillshub --skill code-refactoring",{"tool":43,"command":44},"pnpm","pnpm dlx skills add ComeOnOliver\u002Fskillshub --skill code-refactoring","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002FMoizIbnYousaf\u002FAi-Agent-Skills\u002Fcode-refactoring\u002FSKILL.md",true,[],[49,58,67,76,82,88],{"skillNo":50,"name":51,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":52,"categories":53,"keywords":54,"publishedAt":21},"01M6FKJN13GMG4KY57J3QD8GY5","model-hierarchy-skill","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzscole\u002Fmodel-hierarchy-skill\u002Fmodel-hierarchy-skill\u002FSKILL.md",[],[55,56,57],"model","model hierarchy","model hierarchy skill",{"skillNo":59,"name":60,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":61,"categories":62,"keywords":63,"publishedAt":21},"01M6FKJJJ6GCAMR4PPPRD12M5X","zoom-mcp","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-mcp\u002FSKILL.md",[],[64,65,66],"MCP","zoom","zoom mcp",{"skillNo":68,"name":69,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":70,"categories":71,"keywords":72,"publishedAt":21},"01M6FKJE3KYT3KPEZMEEHYKA6K","zoom-apps-sdk","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-apps-sdk\u002FSKILL.md",[],[73,74,75,65],"sdk","zoom apps sdk","apps",{"skillNo":77,"name":78,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":79,"categories":80,"keywords":81,"publishedAt":21},"01M6FKJ9EDH9Q5VWDF8HAJRSP0","windows","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwindows\u002FSKILL.md",[],[78],{"skillNo":83,"name":84,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":85,"categories":86,"keywords":87,"publishedAt":21},"01M6FKJ666BEEFC3AE9GJ72Q93","whiteboard","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwhiteboard\u002FSKILL.md",[],[84],{"skillNo":89,"name":90,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":91,"categories":92,"keywords":93,"publishedAt":21},"01M6FKJ21WFCDGTJQ2Q91T9DVW","websockets","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwebsockets\u002FSKILL.md",[],[90]]