.
This commit is contained in:
parent
36cc445fa2
commit
62170f1e38
2 changed files with 101 additions and 14 deletions
86
global/rules/funcoes-anonimas-arrow
Normal file
86
global/rules/funcoes-anonimas-arrow
Normal file
|
|
@ -0,0 +1,86 @@
|
||||||
|
---
|
||||||
|
type: rule
|
||||||
|
name: funcoes-anonimas-arrow
|
||||||
|
trigger: always_on
|
||||||
|
description: Exige uso de arrow functions (const x = () => {}) em vez de function declarations (function x() {})
|
||||||
|
scope: global
|
||||||
|
updatedAt: "2026-07-01"
|
||||||
|
globs:
|
||||||
|
- "**/*.ts"
|
||||||
|
- "**/*.tsx"
|
||||||
|
- "**/*.js"
|
||||||
|
- "**/*.vue"
|
||||||
|
alwaysApply: true
|
||||||
|
---
|
||||||
|
|
||||||
|
## Contexto
|
||||||
|
|
||||||
|
Este projeto adota **arrow functions** como padrão obrigatório para definição de funções. A declaração clássica `function x() {}` é proibida sempre que uma arrow function puder substituí-la, o que cobre a esmagadora maioria dos casos.
|
||||||
|
|
||||||
|
Isso garante consistência de estilo, evita ambiguidades de `this`, favorece inferência de tipos em TypeScript e mantém o código visualmente uniforme em todo o ecossistema.
|
||||||
|
|
||||||
|
## Regra
|
||||||
|
|
||||||
|
**Sempre que possível, é obrigatório usar arrow function expression:**
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// ✅ CORRETO — arrow function expression
|
||||||
|
const calcular = (a: number, b: number): number => a + b
|
||||||
|
|
||||||
|
const buscarUsuario = async (id: string): Promise<Usuario> => {
|
||||||
|
return api.get(`/usuarios/${id}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const transformar = <T>(lista: T[], fn: (item: T) => T): T[] =>
|
||||||
|
lista.map(fn)
|
||||||
|
```
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// ❌ PROIBIDO — function declaration
|
||||||
|
function calcular(a: number, b: number): number {
|
||||||
|
return a + b
|
||||||
|
}
|
||||||
|
|
||||||
|
async function buscarUsuario(id: string): Promise<Usuario> {
|
||||||
|
return api.get(`/usuarios/${id}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
function transformar<T>(lista: T[], fn: (item: T) => T): T[] {
|
||||||
|
return lista.map(fn)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Exceções permitidas
|
||||||
|
|
||||||
|
As únicas situações em que `function` é tolerada:
|
||||||
|
|
||||||
|
1. **Generators** — `function*` não tem equivalente em arrow function:
|
||||||
|
```ts
|
||||||
|
function* gerador() { yield 1 }
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Métodos de objeto/classe** — dentro de um `class` ou object literal com método de protocolo, a sintaxe de método é aceita:
|
||||||
|
```ts
|
||||||
|
class Servico {
|
||||||
|
processar() { ... } // OK dentro de classe
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
3. **Callbacks que exigem `this` dinâmico** — raro; apenas quando a API externa exige explicitamente (ex: certas integrações jQuery legadas).
|
||||||
|
|
||||||
|
Fora dessas três exceções, `function` é **proibida**.
|
||||||
|
|
||||||
|
## Diretiva para o agente
|
||||||
|
|
||||||
|
Ao revisar ou escrever código, o agente deve:
|
||||||
|
|
||||||
|
1. Identificar toda ocorrência de `function nome(` fora de classes e generators;
|
||||||
|
2. Substituir pela forma `const nome = (...) => { ... }`;
|
||||||
|
3. Ajustar a tipagem de retorno explícita quando necessário: `const fn = (): Tipo => { ... }`;
|
||||||
|
4. Para funções genéricas, manter o generic na arrow: `const fn = <T>(arg: T): T => arg`;
|
||||||
|
5. Nunca silenciar um erro de tipagem ao fazer a conversão — se surgir erro, resolver com tipagem correta.
|
||||||
|
|
||||||
|
## Referências
|
||||||
|
|
||||||
|
- Rule: `global/rules/typescript-sem-any`
|
||||||
|
- Rule: `global/rules/jsdoc-padrao`
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"versao": "3.0.0",
|
"versao": "3.0.0",
|
||||||
"base_url": "https://paiol.idz.one/desenvolvimento/agent-ia",
|
"base_url": "https://paiol.idz.one/desenvolvimento/agent-ia",
|
||||||
"gerado_em": "2026-06-23T16:22:41-03:00",
|
"gerado_em": "2026-07-01T13:10:56-03:00",
|
||||||
"artefatos": {
|
"artefatos": {
|
||||||
"global": {
|
"global": {
|
||||||
"rules": [
|
"rules": [
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
"global/rules/escrita-natural",
|
"global/rules/escrita-natural",
|
||||||
"global/rules/feedback-visivel",
|
"global/rules/feedback-visivel",
|
||||||
"global/rules/fronteiras-monorepo",
|
"global/rules/fronteiras-monorepo",
|
||||||
|
"global/rules/funcoes-anonimas-arrow",
|
||||||
"global/rules/jsdoc-padrao",
|
"global/rules/jsdoc-padrao",
|
||||||
"global/rules/limite-linhas",
|
"global/rules/limite-linhas",
|
||||||
"global/rules/mensagens-usuario",
|
"global/rules/mensagens-usuario",
|
||||||
|
|
@ -132,6 +133,19 @@
|
||||||
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"ag-land": {
|
||||||
|
"persona": "agents/ag-land/persona",
|
||||||
|
"config": "agents/ag-land/agent.json",
|
||||||
|
"rules": [
|
||||||
|
|
||||||
|
],
|
||||||
|
"workflows": [
|
||||||
|
|
||||||
|
],
|
||||||
|
"skills": [
|
||||||
|
|
||||||
|
]
|
||||||
|
},
|
||||||
"ag-memoria": {
|
"ag-memoria": {
|
||||||
"persona": "agents/ag-memoria/persona",
|
"persona": "agents/ag-memoria/persona",
|
||||||
"config": "agents/ag-memoria/agent.json",
|
"config": "agents/ag-memoria/agent.json",
|
||||||
|
|
@ -184,19 +198,6 @@
|
||||||
],
|
],
|
||||||
"skills": [
|
"skills": [
|
||||||
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"ag-land": {
|
|
||||||
"persona": "agents/ag-land/persona",
|
|
||||||
"config": "agents/ag-land/agent.json",
|
|
||||||
"rules": [
|
|
||||||
|
|
||||||
],
|
|
||||||
"workflows": [
|
|
||||||
|
|
||||||
],
|
|
||||||
"skills": [
|
|
||||||
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue