@ihelpee/prumo-plugin-go-gin 0.0.0-stage → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +103 -2
- package/dist/ast.d.ts +154 -0
- package/dist/ast.d.ts.map +1 -0
- package/dist/ast.js +123 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/rules.d.ts +113 -0
- package/dist/rules.d.ts.map +1 -0
- package/dist/rules.js +717 -0
- package/go-extractor/cmd/prumo-go-extractor/main.go +596 -0
- package/go-extractor/go.mod +3 -0
- package/package.json +35 -3
package/dist/rules.d.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { definePlugin, type RuleDef } from '@ihelpee/prumo/invariants';
|
|
2
|
+
import { type GoGinOptions } from './ast.js';
|
|
3
|
+
/**
|
|
4
|
+
* R1.4: `go` ausente no host NÃO é skip silencioso. As regras `error`
|
|
5
|
+
* retornam vazio (não podem avaliar), e esta regra dedicada emite um achado
|
|
6
|
+
* `warn` nomeado que o relatório destaca. Um gate que pula mudo reporta mais
|
|
7
|
+
* saúde do que existe; um gate que bloqueia por ferramenta ausente é gate
|
|
8
|
+
* que o time desliga. `--fail-on-warn` promove a bloqueio.
|
|
9
|
+
*/
|
|
10
|
+
export declare function goToolchainMissing(opts?: GoGinOptions): RuleDef;
|
|
11
|
+
/** R1.3: arquivo com erro de parse vira achado `go-parse-error` (nunca mudo). */
|
|
12
|
+
export declare function goParseError(): RuleDef;
|
|
13
|
+
/**
|
|
14
|
+
* Rota de mutação (POST/PUT/PATCH/DELETE) registrada em gin.Engine ou
|
|
15
|
+
* gin.RouterGroup sem middleware de auth em NENHUMA camada (inline,
|
|
16
|
+
* Group.Use, Engine.Use). A camada de grupo é a maior fonte de
|
|
17
|
+
* falso-negativo; a resolução transitiva (R3.2/R3.4) é obrigatória.
|
|
18
|
+
*
|
|
19
|
+
* Fronteira honesta: Recovery/Logger/CORS NÃO são auth (R3.5); rota de
|
|
20
|
+
* leitura (GET/HEAD/OPTIONS) nunca é alvo; `NoAuth()` explícito marca
|
|
21
|
+
* público intencional (R3.6).
|
|
22
|
+
*/
|
|
23
|
+
export declare function mutationRoutesGuarded(opts?: GoGinOptions): RuleDef;
|
|
24
|
+
/**
|
|
25
|
+
* O anti-padrão mais perigoso em Go: erro silenciosamente descartado.
|
|
26
|
+
*
|
|
27
|
+
* - R3.7 (error): descarte EXPLÍCITO — `_ = err`, `x, _ := f()`. Decisão
|
|
28
|
+
* deliberada de ignorar falha → bloqueia.
|
|
29
|
+
* - R3.8 (warn): chamada cujo último retorno é error aparece como ExprStmt
|
|
30
|
+
* puro (`db.Save(o)` sozinho). Sem type info o parser NÃO sabe quais
|
|
31
|
+
* funções retornam error, então é HEURÍSTICO: só `knownErrReturning` ou
|
|
32
|
+
* função que já aparece com `err` no mesmo arquivo. Por isso `warn`.
|
|
33
|
+
*
|
|
34
|
+
* Fronteira honesta: `if err := f(); err != nil` não é achado; `fmt.Println`
|
|
35
|
+
* (não retorna error) não é achado.
|
|
36
|
+
*/
|
|
37
|
+
export declare function errorHandlingEnforced(_opts?: GoGinOptions): RuleDef;
|
|
38
|
+
/**
|
|
39
|
+
* R3.8 isolado — chamada que retorna error sem check, como `warn` (heurística
|
|
40
|
+
* sem type info). Separada de `error-handling-enforced` (que é `error`) para
|
|
41
|
+
* respeitar a política do core: heurística que bloqueia é heurística que o
|
|
42
|
+
* time desliga na segunda semana.
|
|
43
|
+
*
|
|
44
|
+
* Redução de falso-positivo: só `knownErrReturning` OU função que já aparece
|
|
45
|
+
* com `err` noutra linha do mesmo arquivo.
|
|
46
|
+
*/
|
|
47
|
+
export declare function errorHandlingUnchecked(opts?: GoGinOptions): RuleDef;
|
|
48
|
+
/**
|
|
49
|
+
* Handler Gin que faz binding de payload para struct cujos campos não
|
|
50
|
+
* declaram tags `binding:"..."` de validação.
|
|
51
|
+
*
|
|
52
|
+
* R3.9: resolve o tipo da struct por heurística SINTÁTICA (var req T, req :=
|
|
53
|
+
* T{}, parâmetro func(req *T)). Se o tipo não for resolvível no arquivo,
|
|
54
|
+
* NÃO reporta (nunca adivinha).
|
|
55
|
+
* R3.10: qualquer campo de dados (exportado) com hasBinding==false é achado.
|
|
56
|
+
* R3.11: `binding:"-"` é ignorado (não faz parte do payload validável).
|
|
57
|
+
* R3.12: body (ShouldBindJSON/Bind/...) é `error`; query/uri é `warn`.
|
|
58
|
+
*/
|
|
59
|
+
export declare function payloadValidationBound(): RuleDef;
|
|
60
|
+
/** R3.12 — binding de query/uri sem tag é `warn` (validação de query é frequentemente opcional). */
|
|
61
|
+
export declare function payloadValidationQuery(opts?: GoGinOptions): RuleDef;
|
|
62
|
+
/**
|
|
63
|
+
* R2.1/R2.2/R2.3/R2.4 — teste de oráculo que importa pacote interno da
|
|
64
|
+
* aplicação (resolvido contra o module path) é espelho. Cobre import
|
|
65
|
+
* absoluto, alias, dot e blank: a burla por alias está bloqueada porque a
|
|
66
|
+
* resolução é por path, não por nome.
|
|
67
|
+
*/
|
|
68
|
+
export declare function oracleNoSrc(opts?: GoGinOptions): RuleDef;
|
|
69
|
+
/**
|
|
70
|
+
* R2.5 — regra nativa de Go: um `_test.go` DENTRO da árvore internal/ (ou
|
|
71
|
+
* layout.src) que declara `package foo` (e não `package foo_test`) acessa
|
|
72
|
+
* símbolos não-exportados da implementação: é espelho branco por construção,
|
|
73
|
+
* mesmo sem import. `package foo_test` é black-box e NÃO viola.
|
|
74
|
+
*/
|
|
75
|
+
export declare function oracleWhiteboxTest(opts?: GoGinOptions): RuleDef;
|
|
76
|
+
/**
|
|
77
|
+
* R2.7 — fronteira reversa: produção (internal/ ou layout.src) importando o
|
|
78
|
+
* diretório de oráculo é espelho invertido (fixture vazando para produção).
|
|
79
|
+
*/
|
|
80
|
+
export declare function srcNoOracle(opts?: GoGinOptions): RuleDef;
|
|
81
|
+
/**
|
|
82
|
+
* R2.8 — em topologia de módulo separado, `oracle/go.mod` não pode
|
|
83
|
+
* require/replace o módulo da aplicação: se contém, a fronteira do
|
|
84
|
+
* compilador foi desativada de propósito.
|
|
85
|
+
*
|
|
86
|
+
* Lido direto do filesystem (o extrator Go não parseia go.mod de submódulo):
|
|
87
|
+
* é um tripwire textual, não AST — suficiente para o `require`/`replace`.
|
|
88
|
+
*/
|
|
89
|
+
export declare function oracleModuleCouplesApp(): RuleDef;
|
|
90
|
+
/**
|
|
91
|
+
* R3.13 — `internal/<featureA>/` importando `internal/<featureB>/`
|
|
92
|
+
* (fronteira de contexto). Heurística `featureOf` adaptada ao layout Go.
|
|
93
|
+
* `warn` no MVP (layouts Go variam).
|
|
94
|
+
*/
|
|
95
|
+
export declare function noCrossFeatureImport(opts?: GoGinOptions): RuleDef;
|
|
96
|
+
/**
|
|
97
|
+
* R3.14 — campo monetário tipado como float32/float64. Em Go o anti-padrão
|
|
98
|
+
* é float64 para dinheiro; int64 (centavos) ou shopspring/decimal é aceitável.
|
|
99
|
+
* `warn`.
|
|
100
|
+
*/
|
|
101
|
+
export declare function monetaryIsInteger(): RuleDef;
|
|
102
|
+
/**
|
|
103
|
+
* O Plugin oficial de Go/Gin para o Prumo (spec §4.5).
|
|
104
|
+
*
|
|
105
|
+
* Analisa, nunca executa: o extrator Go é stdlib-only e só faz
|
|
106
|
+
* `parser.ParseFile` — o app analisado nunca dá boot, o parser nunca herda o
|
|
107
|
+
* drift do que analisa (R1.2). A lei vive 100% neste arquivo Node (§4.2).
|
|
108
|
+
*/
|
|
109
|
+
export declare function goGinPlugin(opts?: GoGinOptions): ReturnType<typeof definePlugin>;
|
|
110
|
+
/** Preset pronto para `invariants: [goGinPreset]` / `.prumo/invariants/rules.ts`. */
|
|
111
|
+
export declare const goGinPreset: RuleDef[];
|
|
112
|
+
export default goGinPlugin;
|
|
113
|
+
//# sourceMappingURL=rules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rules.d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