@joseimsss/launchlint 0.0.0-stage → 0.1.0
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 +21 -0
- package/README.md +85 -2
- package/action.yml +32 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +69 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +41 -0
- package/dist/mcp.d.ts +3 -0
- package/dist/mcp.js +64 -0
- package/dist/reporter.d.ts +3 -0
- package/dist/reporter.js +50 -0
- package/dist/rules/index.d.ts +2 -0
- package/dist/rules/index.js +12 -0
- package/dist/rules/links.d.ts +2 -0
- package/dist/rules/links.js +89 -0
- package/dist/rules/meta.d.ts +2 -0
- package/dist/rules/meta.js +147 -0
- package/dist/rules/utm.d.ts +2 -0
- package/dist/rules/utm.js +133 -0
- package/dist/scanner/files.d.ts +2 -0
- package/dist/scanner/files.js +42 -0
- package/dist/scanner/html.d.ts +3 -0
- package/dist/scanner/html.js +103 -0
- package/dist/scanner/url.d.ts +5 -0
- package/dist/scanner/url.js +82 -0
- package/dist/types.d.ts +54 -0
- package/dist/types.js +1 -0
- package/package.json +60 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 joseimsss
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,86 @@
|
|
|
1
|
-
#
|
|
1
|
+
# launchlint
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Pre-launch auditor for web apps, landing pages, and marketing campaigns — **CLI + TypeScript SDK + GitHub Action + MCP Server**.
|
|
4
|
+
|
|
5
|
+
Catch attribution-breaking mistakes, broken social previews, and privacy leaks **before** you ship.
|
|
6
|
+
|
|
7
|
+
## Why `launchlint`?
|
|
8
|
+
|
|
9
|
+
Most linters ignore marketing & growth correctness. One typo in a campaign link or an internal `utm_source` silently ruins GA4 attribution, breaks WhatsApp/LinkedIn link previews, or leaks user emails into analytics logs.
|
|
10
|
+
|
|
11
|
+
`launchlint` checks your local codebase (`.html`, `.astro`, `.tsx`, `.jsx`, `.md`, `.mdx`) or any live URL for:
|
|
12
|
+
|
|
13
|
+
- **UTM & GA4 Attribution**
|
|
14
|
+
- `utm/internal-link` — flags internal links carrying `utm_*` (which overwrite original attribution and split GA4 sessions).
|
|
15
|
+
- `utm/typo-parameter` — catches `utm_sources`, `utm_campaing`, `utm-medium`, etc.
|
|
16
|
+
- `utm/missing-required-pair` — ensures `utm_source` and `utm_medium` appear together.
|
|
17
|
+
- `utm/uppercase-or-whitespace` — flags unnormalized casing/spaces that fragment GA4 reports.
|
|
18
|
+
- `utm/duplicate-parameter` — catches repeated `utm_*` keys.
|
|
19
|
+
- `utm/stripped-on-redirect` — *(live mode)* detects 301/302 redirects that drop UTM query params.
|
|
20
|
+
- **Open Graph, Canonical & JSON-LD**
|
|
21
|
+
- `meta/missing-title`, `meta/missing-description`, `meta/missing-canonical`
|
|
22
|
+
- `meta/relative-canonical`, `meta/relative-og-image` *(catches relative `og:image` paths ignored by X/LinkedIn/WhatsApp)*
|
|
23
|
+
- `meta/missing-og-core`, `meta/missing-twitter-card`
|
|
24
|
+
- `schema/invalid-jsonld`, `schema/missing-context`
|
|
25
|
+
- **Link Security & Privacy**
|
|
26
|
+
- `links/pii-leak` — blocks emails, phone numbers, or API tokens in query strings.
|
|
27
|
+
- `links/unsafe-target-blank` — checks `rel="noopener"` on `target="_blank"`.
|
|
28
|
+
- `links/insecure-http`, `links/empty-href`, `links/broken-link`
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# Audit a local project directory
|
|
34
|
+
npx @joseimsss/launchlint ./dist
|
|
35
|
+
|
|
36
|
+
# Audit a live landing page + check external links & redirect UTM preservation
|
|
37
|
+
npx @joseimsss/launchlint https://example.com --live-links --origin https://example.com
|
|
38
|
+
|
|
39
|
+
# Output JSON or GitHub Actions annotations
|
|
40
|
+
npx @joseimsss/launchlint ./src --json
|
|
41
|
+
npx @joseimsss/launchlint ./dist --gha --strict
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Programmatic SDK
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { auditTarget, auditHtmlString } from '@joseimsss/launchlint';
|
|
48
|
+
|
|
49
|
+
const report = await auditTarget('./dist', {
|
|
50
|
+
siteOrigin: 'https://example.com',
|
|
51
|
+
failOnWarn: false
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
console.log(report.score, report.summary, report.findings);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## MCP Server (Claude / Cursor / Antigravity)
|
|
58
|
+
|
|
59
|
+
`launchlint` ships a built-in [Model Context Protocol](https://modelcontextprotocol.io) server (`launchlint-mcp`) exposing:
|
|
60
|
+
|
|
61
|
+
- `audit_target` — audit a local path or live URL.
|
|
62
|
+
- `audit_campaign_url` — validate and normalize a campaign URL.
|
|
63
|
+
|
|
64
|
+
```json
|
|
65
|
+
{
|
|
66
|
+
"mcpServers": {
|
|
67
|
+
"launchlint": {
|
|
68
|
+
"command": "npx",
|
|
69
|
+
"args": ["-y", "--package=@joseimsss/launchlint", "launchlint-mcp"]
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## GitHub Action
|
|
76
|
+
|
|
77
|
+
```yaml
|
|
78
|
+
- uses: joseimsss/launchlint@v0.1.0
|
|
79
|
+
with:
|
|
80
|
+
target: ./dist
|
|
81
|
+
origin: https://example.com
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## License
|
|
85
|
+
|
|
86
|
+
[MIT](./LICENSE) © 2026 joseimsss
|
package/action.yml
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
name: 'LaunchLint Pre-Launch Auditor'
|
|
2
|
+
description: 'Audit HTML, Astro, TSX, Markdown, or live URLs for UTM/GA4 attribution bugs, Open Graph, canonicals, JSON-LD, and PII leaks.'
|
|
3
|
+
author: 'joseimsss'
|
|
4
|
+
inputs:
|
|
5
|
+
target:
|
|
6
|
+
description: 'Local directory/file or live URL to audit'
|
|
7
|
+
required: true
|
|
8
|
+
default: '.'
|
|
9
|
+
origin:
|
|
10
|
+
description: 'Site origin (e.g. https://acme.com) to detect internal UTM links'
|
|
11
|
+
required: false
|
|
12
|
+
live-links:
|
|
13
|
+
description: 'Set to true to check live external links and redirect UTM preservation'
|
|
14
|
+
required: false
|
|
15
|
+
default: 'false'
|
|
16
|
+
strict:
|
|
17
|
+
description: 'Fail on warnings as well as errors'
|
|
18
|
+
required: false
|
|
19
|
+
default: 'false'
|
|
20
|
+
runs:
|
|
21
|
+
using: 'composite'
|
|
22
|
+
steps:
|
|
23
|
+
- uses: actions/setup-node@v4
|
|
24
|
+
with:
|
|
25
|
+
node-version: '22'
|
|
26
|
+
- shell: bash
|
|
27
|
+
run: |
|
|
28
|
+
ARGS="${{ inputs.target }} --gha"
|
|
29
|
+
if [ -n "${{ inputs.origin }}" ]; then ARGS="$ARGS --origin ${{ inputs.origin }}"; fi
|
|
30
|
+
if [ "${{ inputs.live-links }}" = "true" ]; then ARGS="$ARGS --live-links"; fi
|
|
31
|
+
if [ "${{ inputs.strict }}" = "true" ]; then ARGS="$ARGS --strict"; fi
|
|
32
|
+
npx --yes @joseimsss/launchlint $ARGS
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { auditTarget } from './index.js';
|
|
3
|
+
import { formatGitHubAnnotations, formatPrettyReport } from './reporter.js';
|
|
4
|
+
function printHelp() {
|
|
5
|
+
console.log(`
|
|
6
|
+
launchlint v0.1.0 — Pre-launch auditor for UTMs, GA4 attribution, Open Graph, JSON-LD & links
|
|
7
|
+
|
|
8
|
+
Usage:
|
|
9
|
+
launchlint <path-or-url> [options]
|
|
10
|
+
|
|
11
|
+
Options:
|
|
12
|
+
--live-links Check external HTTP links & detect UTM stripping on redirects
|
|
13
|
+
--origin <url> Site origin (e.g. https://acme.com) to flag internal UTM links
|
|
14
|
+
--strict Treat warnings as failures (exit code 1)
|
|
15
|
+
--ignore <rules> Comma-separated rule IDs to ignore
|
|
16
|
+
--json Output machine-readable JSON report
|
|
17
|
+
--gha Output GitHub Actions workflow annotations
|
|
18
|
+
-h, --help Show this help
|
|
19
|
+
`);
|
|
20
|
+
}
|
|
21
|
+
async function main() {
|
|
22
|
+
const args = process.argv.slice(2);
|
|
23
|
+
if (args.length === 0 || args.includes('-h') || args.includes('--help')) {
|
|
24
|
+
printHelp();
|
|
25
|
+
process.exit(0);
|
|
26
|
+
}
|
|
27
|
+
let target = '';
|
|
28
|
+
let json = false;
|
|
29
|
+
let gha = false;
|
|
30
|
+
const options = {};
|
|
31
|
+
for (let i = 0; i < args.length; i++) {
|
|
32
|
+
const arg = args[i];
|
|
33
|
+
if (arg === '--live-links')
|
|
34
|
+
options.checkLiveLinks = true;
|
|
35
|
+
else if (arg === '--strict')
|
|
36
|
+
options.failOnWarn = true;
|
|
37
|
+
else if (arg === '--json')
|
|
38
|
+
json = true;
|
|
39
|
+
else if (arg === '--gha')
|
|
40
|
+
gha = true;
|
|
41
|
+
else if (arg === '--origin')
|
|
42
|
+
options.siteOrigin = args[++i];
|
|
43
|
+
else if (arg === '--ignore')
|
|
44
|
+
options.ignoreRules = (args[++i] ?? '').split(',').map(s => s.trim()).filter(Boolean);
|
|
45
|
+
else if (!arg.startsWith('-'))
|
|
46
|
+
target = arg;
|
|
47
|
+
}
|
|
48
|
+
if (!target) {
|
|
49
|
+
console.error('Error: missing <path-or-url> target.');
|
|
50
|
+
process.exit(2);
|
|
51
|
+
}
|
|
52
|
+
const report = await auditTarget(target, options);
|
|
53
|
+
if (json) {
|
|
54
|
+
console.log(JSON.stringify(report, null, 2));
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
console.log(formatPrettyReport(report));
|
|
58
|
+
if (gha) {
|
|
59
|
+
const annotations = formatGitHubAnnotations(report);
|
|
60
|
+
if (annotations)
|
|
61
|
+
console.log(annotations);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
process.exit(report.passed ? 0 : 1);
|
|
65
|
+
}
|
|
66
|
+
main().catch(err => {
|
|
67
|
+
console.error('launchlint failed:', err instanceof Error ? err.message : String(err));
|
|
68
|
+
process.exit(2);
|
|
69
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AuditOptions, AuditReport, Finding } from './types.js';
|
|
2
|
+
export * from './types.js';
|
|
3
|
+
export { evaluateDocument } from './rules/index.js';
|
|
4
|
+
export { parseHtmlDocument, parseMarkdownDocument } from './scanner/html.js';
|
|
5
|
+
export declare function buildReport(target: string, scannedCount: number, findings: Finding[], options?: AuditOptions): AuditReport;
|
|
6
|
+
export declare function auditTarget(target: string, options?: AuditOptions): Promise<AuditReport>;
|
|
7
|
+
export declare function auditHtmlString(html: string, source?: string, options?: AuditOptions): AuditReport;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { evaluateDocument } from './rules/index.js';
|
|
2
|
+
import { scanLocalTarget } from './scanner/files.js';
|
|
3
|
+
import { parseHtmlDocument } from './scanner/html.js';
|
|
4
|
+
import { scanLiveUrl } from './scanner/url.js';
|
|
5
|
+
export * from './types.js';
|
|
6
|
+
export { evaluateDocument } from './rules/index.js';
|
|
7
|
+
export { parseHtmlDocument, parseMarkdownDocument } from './scanner/html.js';
|
|
8
|
+
export function buildReport(target, scannedCount, findings, options = {}) {
|
|
9
|
+
const errors = findings.filter(f => f.severity === 'error').length;
|
|
10
|
+
const warnings = findings.filter(f => f.severity === 'warn').length;
|
|
11
|
+
const infos = findings.filter(f => f.severity === 'info').length;
|
|
12
|
+
const penalty = errors * 18 + warnings * 6 + infos * 1;
|
|
13
|
+
const score = Math.max(0, Math.min(100, 100 - penalty));
|
|
14
|
+
const passed = options.failOnWarn ? errors === 0 && warnings === 0 : errors === 0;
|
|
15
|
+
return {
|
|
16
|
+
target,
|
|
17
|
+
scannedCount,
|
|
18
|
+
score,
|
|
19
|
+
summary: { errors, warnings, infos },
|
|
20
|
+
findings,
|
|
21
|
+
passed
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export async function auditTarget(target, options = {}) {
|
|
25
|
+
const isUrl = target.startsWith('http://') || target.startsWith('https://');
|
|
26
|
+
const ignored = new Set(options.ignoreRules ?? []);
|
|
27
|
+
if (isUrl) {
|
|
28
|
+
const { doc, findings: liveFindings } = await scanLiveUrl(target, options);
|
|
29
|
+
const ruleFindings = evaluateDocument(doc, options);
|
|
30
|
+
const all = [...ruleFindings, ...liveFindings].filter(f => !ignored.has(f.ruleId));
|
|
31
|
+
return buildReport(target, 1, all, options);
|
|
32
|
+
}
|
|
33
|
+
const docs = await scanLocalTarget(target, options.siteOrigin);
|
|
34
|
+
const findings = docs.flatMap(d => evaluateDocument(d, options));
|
|
35
|
+
return buildReport(target, docs.length, findings, options);
|
|
36
|
+
}
|
|
37
|
+
export function auditHtmlString(html, source = 'inline.html', options = {}) {
|
|
38
|
+
const doc = parseHtmlDocument(source, html, 'html', options.siteOrigin);
|
|
39
|
+
const findings = evaluateDocument(doc, options);
|
|
40
|
+
return buildReport(source, 1, findings, options);
|
|
41
|
+
}
|
package/dist/mcp.d.ts
ADDED
package/dist/mcp.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { auditHtmlString, auditTarget } from './index.js';
|
|
6
|
+
export function createLaunchLintMcpServer() {
|
|
7
|
+
const server = new McpServer({
|
|
8
|
+
name: 'launchlint',
|
|
9
|
+
version: '0.1.0'
|
|
10
|
+
});
|
|
11
|
+
server.tool('audit_target', 'Audit a local directory/file (HTML, Astro, TSX, Markdown) or a live URL for UTM attribution bugs, Open Graph/canonical/JSON-LD issues, PII leaks, and broken links.', {
|
|
12
|
+
target: z.string().describe('Local path or https:// URL to audit'),
|
|
13
|
+
checkLiveLinks: z.boolean().optional().describe('Check external links and redirect UTM preservation (URL targets only)'),
|
|
14
|
+
siteOrigin: z.string().optional().describe('Canonical site origin (e.g. https://example.com) to detect internal UTM links')
|
|
15
|
+
}, async ({ target, checkLiveLinks, siteOrigin }) => {
|
|
16
|
+
const report = await auditTarget(target, { checkLiveLinks, siteOrigin });
|
|
17
|
+
return {
|
|
18
|
+
content: [
|
|
19
|
+
{
|
|
20
|
+
type: 'text',
|
|
21
|
+
text: JSON.stringify(report, null, 2)
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
server.tool('audit_campaign_url', 'Validate and normalize a single marketing campaign URL (UTMs, casing, typos, PII leaks).', {
|
|
27
|
+
url: z.string().describe('Full campaign URL to validate')
|
|
28
|
+
}, async ({ url }) => {
|
|
29
|
+
const html = `<a href="${url.replace(/"/g, '"')}">campaign</a>`;
|
|
30
|
+
const report = auditHtmlString(html, 'campaign-url');
|
|
31
|
+
let normalized = url;
|
|
32
|
+
try {
|
|
33
|
+
const u = new URL(url);
|
|
34
|
+
for (const [k, v] of [...u.searchParams.entries()]) {
|
|
35
|
+
if (k.toLowerCase().startsWith('utm_')) {
|
|
36
|
+
u.searchParams.delete(k);
|
|
37
|
+
u.searchParams.set(k.toLowerCase(), v.trim().toLowerCase().replace(/\s+/g, '_'));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
normalized = u.toString();
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
// Keep original if unparseable
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
content: [
|
|
47
|
+
{
|
|
48
|
+
type: 'text',
|
|
49
|
+
text: JSON.stringify({ ...report, normalizedUrl: normalized }, null, 2)
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
return server;
|
|
55
|
+
}
|
|
56
|
+
const isDirectRun = process.argv[1]?.endsWith('mcp.js') || process.argv[1]?.endsWith('launchlint-mcp');
|
|
57
|
+
if (isDirectRun) {
|
|
58
|
+
const server = createLaunchLintMcpServer();
|
|
59
|
+
const transport = new StdioServerTransport();
|
|
60
|
+
server.connect(transport).catch(err => {
|
|
61
|
+
console.error('launchlint-mcp error:', err);
|
|
62
|
+
process.exit(1);
|
|
63
|
+
});
|
|
64
|
+
}
|
package/dist/reporter.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const useColor = !process.env.NO_COLOR && process.stdout.isTTY;
|
|
2
|
+
const c = {
|
|
3
|
+
reset: useColor ? '\x1b[0m' : '',
|
|
4
|
+
bold: useColor ? '\x1b[1m' : '',
|
|
5
|
+
dim: useColor ? '\x1b[2m' : '',
|
|
6
|
+
red: useColor ? '\x1b[31m' : '',
|
|
7
|
+
yellow: useColor ? '\x1b[33m' : '',
|
|
8
|
+
cyan: useColor ? '\x1b[36m' : '',
|
|
9
|
+
green: useColor ? '\x1b[32m' : ''
|
|
10
|
+
};
|
|
11
|
+
function badge(sev) {
|
|
12
|
+
if (sev === 'error')
|
|
13
|
+
return `${c.red}ERR ${c.reset}`;
|
|
14
|
+
if (sev === 'warn')
|
|
15
|
+
return `${c.yellow}WARN${c.reset}`;
|
|
16
|
+
return `${c.cyan}INFO${c.reset}`;
|
|
17
|
+
}
|
|
18
|
+
export function formatPrettyReport(report) {
|
|
19
|
+
const lines = [];
|
|
20
|
+
const scoreColor = report.score >= 85 ? c.green : report.score >= 60 ? c.yellow : c.red;
|
|
21
|
+
lines.push('');
|
|
22
|
+
lines.push(`${c.bold}launchlint${c.reset} · ${report.target} (${report.scannedCount} scanned)`);
|
|
23
|
+
lines.push(`Score: ${scoreColor}${c.bold}${report.score}/100${c.reset} · ${report.summary.errors} errors · ${report.summary.warnings} warnings · ${report.summary.infos} info`);
|
|
24
|
+
lines.push('');
|
|
25
|
+
if (report.findings.length === 0) {
|
|
26
|
+
lines.push(`${c.green}✓ Sin incidencias. Listo para lanzamiento.${c.reset}`);
|
|
27
|
+
lines.push('');
|
|
28
|
+
return lines.join('\n');
|
|
29
|
+
}
|
|
30
|
+
for (const f of report.findings) {
|
|
31
|
+
const loc = f.line ? `${f.source}:${f.line}` : f.source;
|
|
32
|
+
lines.push(` ${badge(f.severity)} ${c.dim}[${f.ruleId}]${c.reset} ${f.message}`);
|
|
33
|
+
lines.push(` ${c.dim}at ${loc}${c.reset}`);
|
|
34
|
+
if (f.suggestion) {
|
|
35
|
+
lines.push(` ${c.dim}fix: ${f.suggestion}${c.reset}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
lines.push('');
|
|
39
|
+
return lines.join('\n');
|
|
40
|
+
}
|
|
41
|
+
export function formatGitHubAnnotations(report) {
|
|
42
|
+
return report.findings
|
|
43
|
+
.filter(f => f.severity !== 'info')
|
|
44
|
+
.map(f => {
|
|
45
|
+
const level = f.severity === 'error' ? 'error' : 'warning';
|
|
46
|
+
const linePart = f.line ? `,line=${f.line}` : '';
|
|
47
|
+
return `::${level} file=${f.source}${linePart},title=${f.ruleId}::${f.message}`;
|
|
48
|
+
})
|
|
49
|
+
.join('\n');
|
|
50
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { checkLinkRules } from './links.js';
|
|
2
|
+
import { checkMetaRules } from './meta.js';
|
|
3
|
+
import { checkUtmRules } from './utm.js';
|
|
4
|
+
export function evaluateDocument(doc, options = {}) {
|
|
5
|
+
const ignored = new Set(options.ignoreRules ?? []);
|
|
6
|
+
const all = [
|
|
7
|
+
...checkUtmRules(doc, options),
|
|
8
|
+
...checkMetaRules(doc),
|
|
9
|
+
...checkLinkRules(doc)
|
|
10
|
+
];
|
|
11
|
+
return all.filter(f => !ignored.has(f.ruleId));
|
|
12
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
const PII_PARAM_KEYS = new Set([
|
|
2
|
+
'email',
|
|
3
|
+
'e-mail',
|
|
4
|
+
'mail',
|
|
5
|
+
'phone',
|
|
6
|
+
'tel',
|
|
7
|
+
'telephone',
|
|
8
|
+
'mobile',
|
|
9
|
+
'token',
|
|
10
|
+
'api_key',
|
|
11
|
+
'apikey',
|
|
12
|
+
'secret',
|
|
13
|
+
'password',
|
|
14
|
+
'passwd',
|
|
15
|
+
'ssn',
|
|
16
|
+
'dni'
|
|
17
|
+
]);
|
|
18
|
+
const EMAIL_IN_VALUE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
19
|
+
export function checkLinkRules(doc) {
|
|
20
|
+
const findings = [];
|
|
21
|
+
for (const link of doc.links) {
|
|
22
|
+
const href = link.href.trim();
|
|
23
|
+
if (href === '' || href === '#') {
|
|
24
|
+
findings.push({
|
|
25
|
+
ruleId: 'links/empty-href',
|
|
26
|
+
category: 'links',
|
|
27
|
+
severity: 'warn',
|
|
28
|
+
message: `Enlace vacío o placeholder ("${href || '(vacío)'}").`,
|
|
29
|
+
suggestion: 'Usa una URL real, un ancla válida (#seccion) o un <button> si es una acción JS.',
|
|
30
|
+
source: doc.source,
|
|
31
|
+
line: link.line,
|
|
32
|
+
snippet: href
|
|
33
|
+
});
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (link.target === '_blank') {
|
|
37
|
+
const relTokens = (link.rel ?? '').toLowerCase().split(/\s+/).filter(Boolean);
|
|
38
|
+
if (!relTokens.includes('noopener')) {
|
|
39
|
+
findings.push({
|
|
40
|
+
ruleId: 'links/unsafe-target-blank',
|
|
41
|
+
category: 'links',
|
|
42
|
+
severity: 'warn',
|
|
43
|
+
message: `Enlace con target="_blank" sin rel="noopener" ("${href}").`,
|
|
44
|
+
suggestion: 'Añade rel="noopener noreferrer" para evitar reverse tabnabbing.',
|
|
45
|
+
source: doc.source,
|
|
46
|
+
line: link.line,
|
|
47
|
+
snippet: href
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (href.startsWith('http://') && !/^http:\/\/(localhost|127\.0\.0\.1|0\.0\.0\.0)(:|\/|$)/i.test(href)) {
|
|
52
|
+
findings.push({
|
|
53
|
+
ruleId: 'links/insecure-http',
|
|
54
|
+
category: 'links',
|
|
55
|
+
severity: 'warn',
|
|
56
|
+
message: `Enlace externo sin HTTPS ("${href}").`,
|
|
57
|
+
suggestion: 'Actualiza a https:// para evitar advertencias de seguridad y pérdida de referrer.',
|
|
58
|
+
source: doc.source,
|
|
59
|
+
line: link.line,
|
|
60
|
+
snippet: href
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
const qIdx = href.indexOf('?');
|
|
64
|
+
if (qIdx >= 0) {
|
|
65
|
+
const query = href.slice(qIdx + 1).split('#')[0] ?? '';
|
|
66
|
+
for (const pair of query.split('&')) {
|
|
67
|
+
if (!pair)
|
|
68
|
+
continue;
|
|
69
|
+
const eqIdx = pair.indexOf('=');
|
|
70
|
+
const key = decodeURIComponent((eqIdx >= 0 ? pair.slice(0, eqIdx) : pair).replace(/\+/g, ' ')).toLowerCase();
|
|
71
|
+
const val = eqIdx >= 0 ? decodeURIComponent(pair.slice(eqIdx + 1).replace(/\+/g, ' ')) : '';
|
|
72
|
+
if (PII_PARAM_KEYS.has(key) || EMAIL_IN_VALUE.test(val)) {
|
|
73
|
+
findings.push({
|
|
74
|
+
ruleId: 'links/pii-leak',
|
|
75
|
+
category: 'links',
|
|
76
|
+
severity: 'error',
|
|
77
|
+
message: `Posible fuga de PII/secreto en query string ("${key}") dentro de "${href}".`,
|
|
78
|
+
suggestion: 'Nunca incluyas emails, teléfonos ni tokens en URLs públicas o rastreadas por analytics (viola GDPR y políticas de GA4).',
|
|
79
|
+
source: doc.source,
|
|
80
|
+
line: link.line,
|
|
81
|
+
snippet: `${key}=...`
|
|
82
|
+
});
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return findings;
|
|
89
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
function isAbsoluteHttpsUrl(value) {
|
|
2
|
+
return /^https?:\/\/[^\s/$.?#].[^\s]*$/i.test(value.trim());
|
|
3
|
+
}
|
|
4
|
+
export function checkMetaRules(doc) {
|
|
5
|
+
const findings = [];
|
|
6
|
+
// Validate JSON-LD in any document containing script ld+json
|
|
7
|
+
for (const block of doc.jsonLd) {
|
|
8
|
+
try {
|
|
9
|
+
const parsed = JSON.parse(block.raw);
|
|
10
|
+
const items = Array.isArray(parsed) ? parsed : [parsed];
|
|
11
|
+
for (const item of items) {
|
|
12
|
+
if (!item || typeof item !== 'object' || !('@context' in item) || !('@type' in item)) {
|
|
13
|
+
findings.push({
|
|
14
|
+
ruleId: 'schema/missing-context',
|
|
15
|
+
category: 'schema',
|
|
16
|
+
severity: 'warn',
|
|
17
|
+
message: 'Bloque JSON-LD sin "@context" o "@type".',
|
|
18
|
+
suggestion: 'Añade "@context": "https://schema.org" y un "@type" válido (Organization, Product, WebPage, etc.).',
|
|
19
|
+
source: doc.source,
|
|
20
|
+
line: block.line
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
findings.push({
|
|
27
|
+
ruleId: 'schema/invalid-jsonld',
|
|
28
|
+
category: 'schema',
|
|
29
|
+
severity: 'error',
|
|
30
|
+
message: 'JSON-LD mal formado: no se puede parsear como JSON válido.',
|
|
31
|
+
suggestion: 'Corrige la sintaxis JSON dentro de <script type="application/ld+json">.',
|
|
32
|
+
source: doc.source,
|
|
33
|
+
line: block.line
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (!doc.isFullDocument)
|
|
38
|
+
return findings;
|
|
39
|
+
const title = doc.title?.trim() ?? '';
|
|
40
|
+
if (!title) {
|
|
41
|
+
findings.push({
|
|
42
|
+
ruleId: 'meta/missing-title',
|
|
43
|
+
category: 'meta',
|
|
44
|
+
severity: 'error',
|
|
45
|
+
message: 'Falta la etiqueta <title> o está vacía.',
|
|
46
|
+
suggestion: 'Define un <title> único y descriptivo (50–60 caracteres).',
|
|
47
|
+
source: doc.source
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
else if (title.length > 65) {
|
|
51
|
+
findings.push({
|
|
52
|
+
ruleId: 'meta/title-length',
|
|
53
|
+
category: 'meta',
|
|
54
|
+
severity: 'info',
|
|
55
|
+
message: `<title> tiene ${title.length} caracteres (recomendado ≤ 65 para evitar truncado en SERP).`,
|
|
56
|
+
source: doc.source,
|
|
57
|
+
snippet: title
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
const desc = (doc.meta['description'] ?? '').trim();
|
|
61
|
+
if (!desc) {
|
|
62
|
+
findings.push({
|
|
63
|
+
ruleId: 'meta/missing-description',
|
|
64
|
+
category: 'meta',
|
|
65
|
+
severity: 'warn',
|
|
66
|
+
message: 'Falta <meta name="description">.',
|
|
67
|
+
suggestion: 'Añade una meta descripción persuasiva de 120–155 caracteres.',
|
|
68
|
+
source: doc.source
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
else if (desc.length < 50 || desc.length > 160) {
|
|
72
|
+
findings.push({
|
|
73
|
+
ruleId: 'meta/description-length',
|
|
74
|
+
category: 'meta',
|
|
75
|
+
severity: 'info',
|
|
76
|
+
message: `La meta description tiene ${desc.length} caracteres (óptimo: 50–160).`,
|
|
77
|
+
source: doc.source
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
if (!doc.canonical) {
|
|
81
|
+
findings.push({
|
|
82
|
+
ruleId: 'meta/missing-canonical',
|
|
83
|
+
category: 'meta',
|
|
84
|
+
severity: 'warn',
|
|
85
|
+
message: 'Falta <link rel="canonical">.',
|
|
86
|
+
suggestion: 'Declara la URL canónica absoluta para evitar contenido duplicado por parámetros ?utm_*.',
|
|
87
|
+
source: doc.source
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
else if (!isAbsoluteHttpsUrl(doc.canonical)) {
|
|
91
|
+
findings.push({
|
|
92
|
+
ruleId: 'meta/relative-canonical',
|
|
93
|
+
category: 'meta',
|
|
94
|
+
severity: 'error',
|
|
95
|
+
message: `<link rel="canonical" href="${doc.canonical}"> debe ser una URL absoluta.`,
|
|
96
|
+
suggestion: 'Usa la URL completa con https://...',
|
|
97
|
+
source: doc.source,
|
|
98
|
+
snippet: doc.canonical
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
const requiredOg = ['og:title', 'og:description', 'og:image', 'og:url'];
|
|
102
|
+
const missingOg = requiredOg.filter(key => !(doc.meta[key] ?? '').trim());
|
|
103
|
+
if (missingOg.length > 0) {
|
|
104
|
+
findings.push({
|
|
105
|
+
ruleId: 'meta/missing-og-core',
|
|
106
|
+
category: 'meta',
|
|
107
|
+
severity: 'warn',
|
|
108
|
+
message: `Faltan etiquetas Open Graph esenciales: ${missingOg.join(', ')}.`,
|
|
109
|
+
suggestion: 'Completa og:title, og:description, og:image y og:url para que el enlace previsualice bien al compartirse.',
|
|
110
|
+
source: doc.source
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
const ogImage = (doc.meta['og:image'] ?? '').trim();
|
|
114
|
+
if (ogImage && !isAbsoluteHttpsUrl(ogImage)) {
|
|
115
|
+
findings.push({
|
|
116
|
+
ruleId: 'meta/relative-og-image',
|
|
117
|
+
category: 'meta',
|
|
118
|
+
severity: 'error',
|
|
119
|
+
message: `og:image ("${ogImage}") es relativa; plataformas como X, LinkedIn y WhatsApp la ignorarán.`,
|
|
120
|
+
suggestion: 'Usa una URL absoluta https://... para og:image.',
|
|
121
|
+
source: doc.source,
|
|
122
|
+
snippet: ogImage
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
const twImage = (doc.meta['twitter:image'] ?? '').trim();
|
|
126
|
+
if (twImage && !isAbsoluteHttpsUrl(twImage)) {
|
|
127
|
+
findings.push({
|
|
128
|
+
ruleId: 'meta/relative-og-image',
|
|
129
|
+
category: 'meta',
|
|
130
|
+
severity: 'error',
|
|
131
|
+
message: `twitter:image ("${twImage}") debe ser una URL absoluta.`,
|
|
132
|
+
suggestion: 'Usa una URL absoluta https://... para twitter:image.',
|
|
133
|
+
source: doc.source,
|
|
134
|
+
snippet: twImage
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
if (!(doc.meta['twitter:card'] ?? '').trim()) {
|
|
138
|
+
findings.push({
|
|
139
|
+
ruleId: 'meta/missing-twitter-card',
|
|
140
|
+
category: 'meta',
|
|
141
|
+
severity: 'info',
|
|
142
|
+
message: 'Falta <meta name="twitter:card"> (ej. summary_large_image).',
|
|
143
|
+
source: doc.source
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
return findings;
|
|
147
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
const VALID_UTM_KEYS = new Set([
|
|
2
|
+
'utm_source',
|
|
3
|
+
'utm_medium',
|
|
4
|
+
'utm_campaign',
|
|
5
|
+
'utm_term',
|
|
6
|
+
'utm_content',
|
|
7
|
+
'utm_id',
|
|
8
|
+
'utm_source_platform',
|
|
9
|
+
'utm_creative_format',
|
|
10
|
+
'utm_marketing_tactic'
|
|
11
|
+
]);
|
|
12
|
+
const TYPO_PATTERN = /^(utm[-_](?:sources?|meduim|mediun|campaing|campagin|campain|contnet|contet|tems|trm)|utm-(?:source|medium|campaign|term|content))$/i;
|
|
13
|
+
function parseUrlSafe(href) {
|
|
14
|
+
try {
|
|
15
|
+
if (href.startsWith('http://') || href.startsWith('https://')) {
|
|
16
|
+
return new URL(href);
|
|
17
|
+
}
|
|
18
|
+
if (href.startsWith('/') || href.startsWith('?') || href.startsWith('./') || href.startsWith('../')) {
|
|
19
|
+
return new URL(href, 'https://launchlint.local');
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function checkUtmRules(doc, options = {}) {
|
|
28
|
+
const findings = [];
|
|
29
|
+
for (const link of doc.links) {
|
|
30
|
+
const parsed = parseUrlSafe(link.href);
|
|
31
|
+
if (!parsed)
|
|
32
|
+
continue;
|
|
33
|
+
const rawQuery = parsed.search.replace(/^\?/, '');
|
|
34
|
+
if (!rawQuery)
|
|
35
|
+
continue;
|
|
36
|
+
const utmParams = [];
|
|
37
|
+
const seenUtm = new Set();
|
|
38
|
+
for (const pair of rawQuery.split('&')) {
|
|
39
|
+
if (!pair)
|
|
40
|
+
continue;
|
|
41
|
+
const eqIdx = pair.indexOf('=');
|
|
42
|
+
const rawKey = decodeURIComponent((eqIdx >= 0 ? pair.slice(0, eqIdx) : pair).replace(/\+/g, ' '));
|
|
43
|
+
const rawVal = eqIdx >= 0 ? decodeURIComponent(pair.slice(eqIdx + 1).replace(/\+/g, ' ')) : '';
|
|
44
|
+
const lowerKey = rawKey.toLowerCase();
|
|
45
|
+
if (TYPO_PATTERN.test(rawKey) && !VALID_UTM_KEYS.has(lowerKey)) {
|
|
46
|
+
findings.push({
|
|
47
|
+
ruleId: 'utm/typo-parameter',
|
|
48
|
+
category: 'utm',
|
|
49
|
+
severity: 'error',
|
|
50
|
+
message: `Parámetro UTM mal escrito "${rawKey}" en "${link.href}".`,
|
|
51
|
+
suggestion: 'Usa nombres estándar en minúsculas con guion bajo: utm_source, utm_medium, utm_campaign, utm_content, utm_term.',
|
|
52
|
+
source: doc.source,
|
|
53
|
+
line: link.line,
|
|
54
|
+
snippet: link.href
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
if (lowerKey.startsWith('utm_')) {
|
|
58
|
+
if (seenUtm.has(lowerKey)) {
|
|
59
|
+
findings.push({
|
|
60
|
+
ruleId: 'utm/duplicate-parameter',
|
|
61
|
+
category: 'utm',
|
|
62
|
+
severity: 'warn',
|
|
63
|
+
message: `Parámetro "${lowerKey}" duplicado en "${link.href}".`,
|
|
64
|
+
suggestion: `Elimina las apariciones repetidas de ${lowerKey} para evitar atribución ambigua.`,
|
|
65
|
+
source: doc.source,
|
|
66
|
+
line: link.line,
|
|
67
|
+
snippet: link.href
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
seenUtm.add(lowerKey);
|
|
71
|
+
utmParams.push([rawKey, rawVal]);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (utmParams.length === 0)
|
|
75
|
+
continue;
|
|
76
|
+
const isSameOrigin = options.siteOrigin
|
|
77
|
+
? link.href.startsWith(options.siteOrigin)
|
|
78
|
+
: false;
|
|
79
|
+
if (link.isInternal || isSameOrigin) {
|
|
80
|
+
findings.push({
|
|
81
|
+
ruleId: 'utm/internal-link',
|
|
82
|
+
category: 'utm',
|
|
83
|
+
severity: 'error',
|
|
84
|
+
message: `Enlace interno con parámetros UTM ("${link.href}"). Esto rompe la sesión y sobrescribe la atribución original en GA4.`,
|
|
85
|
+
suggestion: 'Elimina los parámetros utm_* de enlaces internos y usa eventos personalizados o parámetros internos (ej. ref=).',
|
|
86
|
+
source: doc.source,
|
|
87
|
+
line: link.line,
|
|
88
|
+
snippet: link.href
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
const keysLower = new Set(utmParams.map(([k]) => k.toLowerCase()));
|
|
92
|
+
if ((keysLower.has('utm_campaign') || keysLower.has('utm_medium')) && !keysLower.has('utm_source')) {
|
|
93
|
+
findings.push({
|
|
94
|
+
ruleId: 'utm/missing-required-pair',
|
|
95
|
+
category: 'utm',
|
|
96
|
+
severity: 'warn',
|
|
97
|
+
message: `Falta "utm_source" en enlace con atribución ("${link.href}").`,
|
|
98
|
+
suggestion: 'Incluye siempre utm_source junto con utm_medium y utm_campaign para que GA4 clasifique el tráfico.',
|
|
99
|
+
source: doc.source,
|
|
100
|
+
line: link.line,
|
|
101
|
+
snippet: link.href
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
else if (keysLower.has('utm_source') && !keysLower.has('utm_medium')) {
|
|
105
|
+
findings.push({
|
|
106
|
+
ruleId: 'utm/missing-required-pair',
|
|
107
|
+
category: 'utm',
|
|
108
|
+
severity: 'warn',
|
|
109
|
+
message: `Falta "utm_medium" junto a "utm_source" en "${link.href}".`,
|
|
110
|
+
suggestion: 'Añade utm_medium (ej. cpc, email, social) para evitar que el tráfico caiga en Unassigned en GA4.',
|
|
111
|
+
source: doc.source,
|
|
112
|
+
line: link.line,
|
|
113
|
+
snippet: link.href
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
for (const [key, val] of utmParams) {
|
|
117
|
+
if (key !== key.toLowerCase() || val !== val.toLowerCase() || /\s/.test(val)) {
|
|
118
|
+
findings.push({
|
|
119
|
+
ruleId: 'utm/uppercase-or-whitespace',
|
|
120
|
+
category: 'utm',
|
|
121
|
+
severity: 'warn',
|
|
122
|
+
message: `Valor o clave UTM no normalizado (${key}=${val}) en "${link.href}".`,
|
|
123
|
+
suggestion: 'Usa solo minúsculas y guiones/guiones bajos sin espacios (ej. utm_source=linkedin&utm_medium=paid_social).',
|
|
124
|
+
source: doc.source,
|
|
125
|
+
line: link.line,
|
|
126
|
+
snippet: `${key}=${val}`
|
|
127
|
+
});
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return findings;
|
|
133
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { readdir, readFile, stat } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { parseHtmlDocument, parseMarkdownDocument } from './html.js';
|
|
4
|
+
const SUPPORTED_EXT = new Set(['.html', '.htm', '.astro', '.tsx', '.jsx', '.md', '.mdx']);
|
|
5
|
+
const IGNORED_DIRS = new Set(['node_modules', '.git', 'dist', 'build', '.next', '.astro', '.turbo', 'coverage']);
|
|
6
|
+
async function collectFiles(targetPath) {
|
|
7
|
+
const info = await stat(targetPath);
|
|
8
|
+
if (info.isFile()) {
|
|
9
|
+
return SUPPORTED_EXT.has(path.extname(targetPath).toLowerCase()) ? [targetPath] : [];
|
|
10
|
+
}
|
|
11
|
+
const entries = await readdir(targetPath, { withFileTypes: true });
|
|
12
|
+
const results = [];
|
|
13
|
+
for (const entry of entries) {
|
|
14
|
+
if (entry.isDirectory()) {
|
|
15
|
+
if (IGNORED_DIRS.has(entry.name))
|
|
16
|
+
continue;
|
|
17
|
+
results.push(...(await collectFiles(path.join(targetPath, entry.name))));
|
|
18
|
+
}
|
|
19
|
+
else if (entry.isFile()) {
|
|
20
|
+
if (SUPPORTED_EXT.has(path.extname(entry.name).toLowerCase())) {
|
|
21
|
+
results.push(path.join(targetPath, entry.name));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return results;
|
|
26
|
+
}
|
|
27
|
+
export async function scanLocalTarget(targetPath, siteOrigin) {
|
|
28
|
+
const files = await collectFiles(targetPath);
|
|
29
|
+
const docs = [];
|
|
30
|
+
for (const filePath of files) {
|
|
31
|
+
const raw = await readFile(filePath, 'utf8');
|
|
32
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
33
|
+
if (ext === '.md' || ext === '.mdx') {
|
|
34
|
+
docs.push(parseMarkdownDocument(filePath, raw, siteOrigin));
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
const kind = ext === '.tsx' || ext === '.jsx' ? 'jsx' : 'html';
|
|
38
|
+
docs.push(parseHtmlDocument(filePath, raw, kind, siteOrigin));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return docs;
|
|
42
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { DocumentContext } from '../types.js';
|
|
2
|
+
export declare function parseHtmlDocument(source: string, content: string, kind?: 'html' | 'jsx' | 'url', siteOrigin?: string): DocumentContext;
|
|
3
|
+
export declare function parseMarkdownDocument(source: string, content: string, siteOrigin?: string): DocumentContext;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { parse } from 'node-html-parser';
|
|
2
|
+
function isInternalHref(href, siteOrigin) {
|
|
3
|
+
const trimmed = href.trim();
|
|
4
|
+
if (!trimmed)
|
|
5
|
+
return true;
|
|
6
|
+
if (trimmed.startsWith('/') && !trimmed.startsWith('//'))
|
|
7
|
+
return true;
|
|
8
|
+
if (trimmed.startsWith('#') || trimmed.startsWith('?') || trimmed.startsWith('./') || trimmed.startsWith('../')) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
if (siteOrigin && trimmed.startsWith(siteOrigin))
|
|
12
|
+
return true;
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
function findLineNumber(content, needle, fromIndex = 0) {
|
|
16
|
+
if (!needle)
|
|
17
|
+
return { nextIndex: fromIndex };
|
|
18
|
+
const idx = content.indexOf(needle, fromIndex);
|
|
19
|
+
if (idx < 0)
|
|
20
|
+
return { nextIndex: fromIndex };
|
|
21
|
+
const line = content.slice(0, idx).split('\n').length;
|
|
22
|
+
return { line, nextIndex: idx + needle.length };
|
|
23
|
+
}
|
|
24
|
+
export function parseHtmlDocument(source, content, kind = 'html', siteOrigin) {
|
|
25
|
+
const root = parse(content, { comment: false });
|
|
26
|
+
const isFullDocument = /<html[\s>]|<head[\s>]/i.test(content);
|
|
27
|
+
const title = root.querySelector('title')?.text?.trim();
|
|
28
|
+
const canonical = root.querySelector('link[rel="canonical"]')?.getAttribute('href')?.trim();
|
|
29
|
+
const meta = {};
|
|
30
|
+
for (const el of root.querySelectorAll('meta')) {
|
|
31
|
+
const key = (el.getAttribute('property') ?? el.getAttribute('name') ?? '').trim().toLowerCase();
|
|
32
|
+
const val = el.getAttribute('content') ?? '';
|
|
33
|
+
if (key)
|
|
34
|
+
meta[key] = val;
|
|
35
|
+
}
|
|
36
|
+
const jsonLd = [];
|
|
37
|
+
let cursor = 0;
|
|
38
|
+
for (const script of root.querySelectorAll('script[type="application/ld+json"]')) {
|
|
39
|
+
const raw = script.text.trim();
|
|
40
|
+
const pos = findLineNumber(content, raw.slice(0, 40), cursor);
|
|
41
|
+
cursor = pos.nextIndex;
|
|
42
|
+
jsonLd.push({ raw, line: pos.line });
|
|
43
|
+
}
|
|
44
|
+
const links = [];
|
|
45
|
+
let linkCursor = 0;
|
|
46
|
+
for (const a of root.querySelectorAll('a')) {
|
|
47
|
+
const href = a.getAttribute('href');
|
|
48
|
+
if (href === undefined)
|
|
49
|
+
continue;
|
|
50
|
+
const pos = findLineNumber(content, href, linkCursor);
|
|
51
|
+
linkCursor = pos.nextIndex;
|
|
52
|
+
links.push({
|
|
53
|
+
href,
|
|
54
|
+
text: a.text.trim(),
|
|
55
|
+
rel: a.getAttribute('rel') ?? undefined,
|
|
56
|
+
target: a.getAttribute('target') ?? undefined,
|
|
57
|
+
isInternal: isInternalHref(href, siteOrigin),
|
|
58
|
+
line: pos.line
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
source,
|
|
63
|
+
kind,
|
|
64
|
+
isFullDocument,
|
|
65
|
+
links,
|
|
66
|
+
meta,
|
|
67
|
+
title,
|
|
68
|
+
canonical,
|
|
69
|
+
jsonLd
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export function parseMarkdownDocument(source, content, siteOrigin) {
|
|
73
|
+
const links = [];
|
|
74
|
+
const mdLinkRe = /(?<!!)\[([^\]]*)\]\(([^)\s]+)(?:\s+"[^"]*")?\)/g;
|
|
75
|
+
let match;
|
|
76
|
+
while ((match = mdLinkRe.exec(content)) !== null) {
|
|
77
|
+
const text = match[1] ?? '';
|
|
78
|
+
const href = match[2] ?? '';
|
|
79
|
+
const line = content.slice(0, match.index).split('\n').length;
|
|
80
|
+
links.push({
|
|
81
|
+
href,
|
|
82
|
+
text,
|
|
83
|
+
isInternal: isInternalHref(href, siteOrigin),
|
|
84
|
+
line
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
// Also inspect inline HTML anchors inside markdown/MDX
|
|
88
|
+
const htmlDoc = parseHtmlDocument(source, content, 'html', siteOrigin);
|
|
89
|
+
const seen = new Set(links.map(l => `${l.line}:${l.href}`));
|
|
90
|
+
for (const l of htmlDoc.links) {
|
|
91
|
+
const key = `${l.line}:${l.href}`;
|
|
92
|
+
if (!seen.has(key))
|
|
93
|
+
links.push(l);
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
source,
|
|
97
|
+
kind: 'markdown',
|
|
98
|
+
isFullDocument: false,
|
|
99
|
+
links,
|
|
100
|
+
meta: {},
|
|
101
|
+
jsonLd: []
|
|
102
|
+
};
|
|
103
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { parseHtmlDocument } from './html.js';
|
|
2
|
+
export async function scanLiveUrl(url, options = {}) {
|
|
3
|
+
const timeoutMs = options.timeoutMs ?? 8000;
|
|
4
|
+
const res = await fetch(url, {
|
|
5
|
+
redirect: 'follow',
|
|
6
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
7
|
+
headers: { 'User-Agent': 'launchlint/0.1 (+https://github.com/joseimsss/launchlint)' }
|
|
8
|
+
});
|
|
9
|
+
const html = await res.text();
|
|
10
|
+
const parsedUrl = new URL(res.url || url);
|
|
11
|
+
const doc = parseHtmlDocument(res.url || url, html, 'url', parsedUrl.origin);
|
|
12
|
+
const findings = [];
|
|
13
|
+
if (!res.ok) {
|
|
14
|
+
findings.push({
|
|
15
|
+
ruleId: 'links/http-status',
|
|
16
|
+
category: 'links',
|
|
17
|
+
severity: 'error',
|
|
18
|
+
message: `La URL objetivo devolvió HTTP ${res.status}.`,
|
|
19
|
+
source: url
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (options.checkLiveLinks) {
|
|
23
|
+
const externalUrls = Array.from(new Set(doc.links
|
|
24
|
+
.map(l => l.href)
|
|
25
|
+
.filter(h => h.startsWith('http://') || h.startsWith('https://')))).slice(0, 25);
|
|
26
|
+
const checks = await Promise.all(externalUrls.map(async (targetHref) => {
|
|
27
|
+
const out = [];
|
|
28
|
+
try {
|
|
29
|
+
const orig = new URL(targetHref);
|
|
30
|
+
const origUtms = [...orig.searchParams.keys()].filter(k => k.toLowerCase().startsWith('utm_'));
|
|
31
|
+
const linkRes = await fetch(targetHref, {
|
|
32
|
+
method: 'GET',
|
|
33
|
+
redirect: 'manual',
|
|
34
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
35
|
+
headers: { 'User-Agent': 'launchlint/0.1' }
|
|
36
|
+
});
|
|
37
|
+
if (linkRes.status >= 400) {
|
|
38
|
+
out.push({
|
|
39
|
+
ruleId: 'links/broken-link',
|
|
40
|
+
category: 'links',
|
|
41
|
+
severity: 'error',
|
|
42
|
+
message: `Enlace roto (HTTP ${linkRes.status}): "${targetHref}".`,
|
|
43
|
+
source: doc.source,
|
|
44
|
+
snippet: targetHref
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
else if (linkRes.status >= 300 && linkRes.status < 400 && origUtms.length > 0) {
|
|
48
|
+
const loc = linkRes.headers.get('location');
|
|
49
|
+
if (loc) {
|
|
50
|
+
const dest = new URL(loc, orig);
|
|
51
|
+
const lostUtms = origUtms.filter(k => !dest.searchParams.has(k));
|
|
52
|
+
if (lostUtms.length > 0) {
|
|
53
|
+
out.push({
|
|
54
|
+
ruleId: 'utm/stripped-on-redirect',
|
|
55
|
+
category: 'utm',
|
|
56
|
+
severity: 'error',
|
|
57
|
+
message: `La redirección (${linkRes.status}) de "${targetHref}" hacia "${dest.toString()}" elimina parámetros UTM (${lostUtms.join(', ')}).`,
|
|
58
|
+
suggestion: 'Configura la redirección para preservar query strings o enlaza directamente al destino final.',
|
|
59
|
+
source: doc.source,
|
|
60
|
+
snippet: targetHref
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
out.push({
|
|
68
|
+
ruleId: 'links/unreachable',
|
|
69
|
+
category: 'links',
|
|
70
|
+
severity: 'warn',
|
|
71
|
+
message: `No se pudo verificar el enlace "${targetHref}" (timeout o error de red).`,
|
|
72
|
+
source: doc.source,
|
|
73
|
+
snippet: targetHref
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return out;
|
|
77
|
+
}));
|
|
78
|
+
for (const list of checks)
|
|
79
|
+
findings.push(...list);
|
|
80
|
+
}
|
|
81
|
+
return { doc, findings };
|
|
82
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export type Severity = 'error' | 'warn' | 'info';
|
|
2
|
+
export type Category = 'utm' | 'meta' | 'links' | 'schema';
|
|
3
|
+
export interface Finding {
|
|
4
|
+
ruleId: string;
|
|
5
|
+
category: Category;
|
|
6
|
+
severity: Severity;
|
|
7
|
+
message: string;
|
|
8
|
+
suggestion?: string;
|
|
9
|
+
source: string;
|
|
10
|
+
line?: number;
|
|
11
|
+
snippet?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface ExtractedLink {
|
|
14
|
+
href: string;
|
|
15
|
+
text?: string;
|
|
16
|
+
rel?: string;
|
|
17
|
+
target?: string;
|
|
18
|
+
isInternal: boolean;
|
|
19
|
+
line?: number;
|
|
20
|
+
}
|
|
21
|
+
export interface JsonLdBlock {
|
|
22
|
+
raw: string;
|
|
23
|
+
line?: number;
|
|
24
|
+
}
|
|
25
|
+
export interface DocumentContext {
|
|
26
|
+
source: string;
|
|
27
|
+
kind: 'html' | 'jsx' | 'markdown' | 'url';
|
|
28
|
+
isFullDocument: boolean;
|
|
29
|
+
links: ExtractedLink[];
|
|
30
|
+
meta: Record<string, string>;
|
|
31
|
+
title?: string;
|
|
32
|
+
canonical?: string;
|
|
33
|
+
jsonLd: JsonLdBlock[];
|
|
34
|
+
}
|
|
35
|
+
export interface AuditOptions {
|
|
36
|
+
checkLiveLinks?: boolean;
|
|
37
|
+
timeoutMs?: number;
|
|
38
|
+
ignoreRules?: string[];
|
|
39
|
+
siteOrigin?: string;
|
|
40
|
+
failOnWarn?: boolean;
|
|
41
|
+
}
|
|
42
|
+
export interface AuditSummary {
|
|
43
|
+
errors: number;
|
|
44
|
+
warnings: number;
|
|
45
|
+
infos: number;
|
|
46
|
+
}
|
|
47
|
+
export interface AuditReport {
|
|
48
|
+
target: string;
|
|
49
|
+
scannedCount: number;
|
|
50
|
+
score: number;
|
|
51
|
+
summary: AuditSummary;
|
|
52
|
+
findings: Finding[];
|
|
53
|
+
passed: boolean;
|
|
54
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,62 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@joseimsss/launchlint",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Pre-launch auditor for web apps, landing pages, and marketing campaigns: UTMs, GA4 attribution, Open Graph, JSON-LD, broken links, and PII leaks (CLI + SDK + GitHub Action + MCP Server).",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"launchlint": "dist/cli.js",
|
|
10
|
+
"launchlint-mcp": "dist/mcp.js"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"action.yml",
|
|
21
|
+
"README.md",
|
|
22
|
+
"LICENSE"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc -p tsconfig.json && chmod +x dist/cli.js dist/mcp.js",
|
|
26
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
27
|
+
"test": "vitest run",
|
|
28
|
+
"test:watch": "vitest",
|
|
29
|
+
"prepublishOnly": "npm run build && npm test"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"utm",
|
|
33
|
+
"ga4",
|
|
34
|
+
"analytics",
|
|
35
|
+
"seo",
|
|
36
|
+
"open-graph",
|
|
37
|
+
"marketing",
|
|
38
|
+
"linter",
|
|
39
|
+
"cli",
|
|
40
|
+
"mcp",
|
|
41
|
+
"launch"
|
|
42
|
+
],
|
|
43
|
+
"author": "joseimsss",
|
|
44
|
+
"license": "MIT",
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "git+https://github.com/joseimsss/launchlint.git"
|
|
48
|
+
},
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=20.0.0"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@modelcontextprotocol/sdk": "^1.12.1",
|
|
54
|
+
"node-html-parser": "^7.0.1",
|
|
55
|
+
"zod": "^3.25.32"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@types/node": "^22.15.29",
|
|
59
|
+
"typescript": "^5.8.3",
|
|
60
|
+
"vitest": "^3.2.4"
|
|
61
|
+
}
|
|
62
|
+
}
|