代码 重构
- 作者仓库星标 0
- 作者仓库 skills-registry
Code Refactor — Loja Luz do Atlântico
When to Use
Activate this skill whenever the user asks to:
- Refactor, modernize, clean up, or improve existing code
- Convert legacy Angular patterns (constructor injection, NgModules,
BehaviorSubject) to current project standards - Update Express routes, add Zod validation, or reorganize backend logic
- Fix TypeScript strict-mode violations
- Improve SCSS structure or responsiveness
Priority Order
Apply changes in this order to avoid regressions:
- TypeScript types — fix implicit
any, add missing types, align withtypes.ts - Angular patterns — standalone,
inject(), signals - Backend patterns — Zod schema validation, auth middleware reuse
- SCSS — flat selectors,
clamp(), remove hardcoded breakpoints
Angular Refactoring
Full patterns in ./references/angular-patterns.md.
Top transformations
| From (legacy) | To (current) |
|---|---|
constructor(private svc: Service) |
private readonly svc = inject(Service) |
BehaviorSubject<T> + async pipe |
signal<T>() + template call value() |
NgModule declarations |
standalone: true + inline imports: [] |
this.observable$.pipe(tap(...)) side effects |
effect(() => { ... }) |
ngModel two-way binding on non-forms |
signal() + (input) event |
Checklist — Angular
- No
constructor()— all deps viainject() -
standalone: trueon every component - All mutable state is
signal<T>(); derived state iscomputed() -
protected readonlyfor signals accessed in template - Only needed Angular modules in
imports: [] - Signals called as functions in template:
{{ value() }} - No implicit
any— all signals typed explicitly
Backend Refactoring
Full patterns in ./references/backend-patterns.md.
Top transformations
| From (legacy) | To (current) |
|---|---|
Manual req.body field access without validation |
schema.parse(req.body) with Zod |
| Auth check copy-pasted into each route | Extract requireAdmin(req, res) guard |
try/catch with console.error only |
try/catch returning proper JSON { message: string } |
req.params.id used directly |
Validated/sanitized before use |
| File upload with no MIME check | Use existing upload multer config with allowedImageMimeTypes |
Checklist — Backend
- All incoming payloads validated with a Zod schema (
.parse()or.safeParse()) - Auth header validated for every admin route:
req.headers.authorization === \Bearer ${adminToken}`` - Error responses return
{ message: string }JSON, not plain text - No
req.params/req.queryvalues used unsanitized in file paths or SQL - Webhook raw body handled before
express.json()middleware
TypeScript Refactoring
- Replace all
anywith concrete types fromfrontend/src/app/types.tsor inline interfaces - Replace
||with??when the intent is nullish coalescing (not falsy) - Replace
as Xtype assertions with proper narrowing (if (x instanceof X), type guards) - Ensure
noImplicitReturnsis satisfied — every branch of a function must return
SCSS Refactoring
- Replace fixed
pxfont sizes withclamp():font-size: clamp(1rem, 3vw, 2rem) - Replace deep nesting (
.parent .child .grandchild) with flat BEM-like selectors (.card,.card-title,.card-body) - Replace
@media (max-width: 768px)breakpoints with fluid layouts using CSS Gridauto-fit/minmaxwhere possible - Remove
!important— use specificity instead
Refactoring Workflow
- Read the file(s) to be refactored in full before changing anything
- Identify which category applies (Angular / backend / TypeScript / SCSS)
- Apply the matching checklist above
- Preserve all existing business logic — only change structure, patterns, and syntax
- Verify the project compiles without TypeScript errors after Angular changes
<!-- tomevault:4.0:skill_md:2026-05-22 -->Source: AisleiAvila/loja — distributed by TomeVault.
- 流狐分类
- 工程开发
- 作者声明 Agent
- 未找到明确声明;不据此推断已兼容或已测试
- 静态检查
- 88 / 100 · 启发式扫描,不代表运行安全
- 作者 / 版本 / 许可
- @tomevault-io · 未声明 license
- 流狐 Token 估算
- 低消耗
- 流狐接入估算
- 即装即用
- 是否需要外部 API Key
- 未发现要求
- 检测到的系统要求
- 未声明
- 底层运行要求
- 未声明
- 检测到的文件与系统行为
-
- 只读
- 允许写入 / 修改
- 检测到的网络行为
- 允许外网请求
- 安装命令数
- 无(仅作为资料)
档案由构建时根据 SKILL.md 与安装命令自动衍生,可能与作者实际意图存在差异。
需要注意: 未限定 allowed-tools,默认拥有全部工具权限。
作者没有在当前 SKILL.md 中定义固定输出样例。 Activate this skill whenever the user asks to: Refactor, modernize, clean up, or improve existing code Convert legacy Angular patterns (constructor injection, NgModules, BehaviorSubject) to current project standards
Apply changes in this order to avoid regressions: TypeScript types — fix implicit any, add missing types, align with types.ts Angular patterns — standalone, inject(), signals
Full patterns in ./references/angular-patterns.md.
From (legacy) · To (current) constructor(private svc: Service) · private readonly svc = inject(Service) BehaviorSubject<T> + async pipe · signal<T>() + template call value()
[ ] No constructor() — all deps via inject() [ ] standalone: true on every component [ ] All mutable state is signal<T>(); derived state is computed()
Full patterns in ./references/backend-patterns.md.
# Code Refactor — Loja Luz do Atlântico
## When to Use
Activate this skill whenever the user asks to:
- Refactor, modernize, clean up, or improve existing code
- Convert legacy Angular patterns (constructor injection, NgModules, `BehaviorSubject`) to current project standards
- Update Express routes, add Zod validation, or reorganize backend logic
- Fix TypeScript strict-mode violations
- Improve SCSS structure or responsiveness
---
## Priority Order
Apply changes in this order to avoid regressions:
1. **TypeScript types** — fix implicit `any`, add missing types, align with `types.ts`
2. **Angular patterns** — standalone, `inject()`, signals
3. **Backend patterns** — Zod schema validation, auth middleware reuse
4. **SCSS** — flat selectors, `clamp()`, remove hardcoded breakpoints
---
## Angular Refactoring
Full patterns in [./references/angular-patterns.md](./references/angular-patterns.md).
### Top transformations
| From (legacy) | To (current) |
|---------------|--------------|
| `constructor(private svc: Service)` | `private readonly svc = inject(Service)` |
| `BehaviorSubject<T>` + `async` pipe | `signal<T>()` + template call `value()` |
| `NgModule` declarations | `standalone: true` + inline `imports: []` |
| `this.observable$.pipe(tap(...))` side effects | `effect(() => { ... })` |
| `ngModel` two-way binding on non-forms | `signal()` + `(input)` event |
### Checklist — Angular
- [ ] No `constructor()` — all deps via `inject()`
- [ ] `standalone: true` on every component
- [ ] All mutable state is `signal<T>()`; derived state is `computed()`
- [ ] `protected readonly` for signals accessed in template
- [ ] Only needed Angular modules in `imports: []`
- [ ] Signals called as functions in template: `{{ value() }}`
… 作者原文负责流程事实;流狐只索引当前章节、要点、文件与命令。
章节 -> When to Use → Priority Order → Angular Refactoring → Top transformations → Checklist — Angular → Backend Refactoring
要点 -> TypeScript types · Angular patterns · Backend patterns · SCSS · Read · Identify · Apply · Preserve
文件/命令 -> BehaviorSubject · any · types.ts · inject() · clamp() · constructor(private svc: Service) · private readonly svc = inject(Service) · BehaviorSubject<T>
内容 SHA-256 -> e0691e39455e
方法与流程
适用与边界
原文中的明确线索
BehaviorSubject、any、types.ts、inject()、clamp()、constructor(private svc: Service)、private readonly svc = inject(Service)、BehaviorSubject<T>