rtl-analyzer 0.0.0-stage → 0.2.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 +82 -2
- package/dist/bootstrap.js +27 -0
- package/dist/cli.js +76 -0
- package/dist/codemod.js +53 -0
- package/dist/coverage.js +36 -0
- package/dist/css.js +61 -0
- package/dist/dashboard-client.js +167 -0
- package/dist/dashboard-data.js +22 -0
- package/dist/dashboard-html.js +27 -0
- package/dist/discovery.js +71 -0
- package/dist/eligibility.js +19 -0
- package/dist/html.js +34 -0
- package/dist/model.js +9 -0
- package/dist/policy-audit.js +109 -0
- package/dist/policy-validation.js +137 -0
- package/dist/policy.js +32 -0
- package/dist/presentation-adapter.js +52 -0
- package/dist/preview-manifest.js +15 -0
- package/dist/report-publisher.js +110 -0
- package/dist/report.js +8 -0
- package/dist/review-session.js +153 -0
- package/dist/rules.js +215 -0
- package/dist/runtime-direction.js +334 -0
- package/dist/scan.js +59 -0
- package/dist/source-snippets.js +177 -0
- package/dist/standalone-cli.js +107 -0
- package/dist/structured-markdown.js +36 -0
- package/dist/tailwind.js +21 -0
- package/dist/typescript.js +191 -0
- package/package.json +30 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ahmed Fouad
|
|
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 THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,83 @@
|
|
|
1
|
-
#
|
|
1
|
+
# RTL Analyzer CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
RTL Analyzer performs read-only RTL risk scans and can emit JSON, Markdown, structured Markdown, or a self-contained dashboard HTML report.
|
|
4
|
+
|
|
5
|
+
## Quick start
|
|
6
|
+
|
|
7
|
+
No global installation is required:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx rtl-analyzer
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
With no arguments, RTL Analyzer recursively scans the current working directory, writes JSON, Markdown, structured Markdown, and HTML dashboard files to a unique temporary directory outside the project, then opens the dashboard in your default browser. When the dashboard is successfully generated, the CLI prints its path. If the browser cannot be opened, use that printed path instead.
|
|
14
|
+
|
|
15
|
+
On the first run, npm may ask for confirmation before installing the package. Confirm the prompt, or use `npx --yes rtl-analyzer` in scripts and other non-interactive environments.
|
|
16
|
+
|
|
17
|
+
Use `--help` to see the available options:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npx rtl-analyzer --help
|
|
21
|
+
npx rtl-analyzer --version
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
For explicit scans, preserve control over the root, format, and output directory:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npx rtl-analyzer scan . --format json
|
|
28
|
+
npx rtl-analyzer scan ./src --format markdown --output-dir ./rtl-report
|
|
29
|
+
npx rtl-analyzer scan . --format dashboard --output-dir ./rtl-report
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Options include `--root <path>`, `--format <format>`, `--output-dir <path>`, `--fail-on-findings`, and `--embed-source-snippets` (dashboard output only). Explicit scans do not open a browser automatically.
|
|
33
|
+
|
|
34
|
+
## Developer build and pack
|
|
35
|
+
|
|
36
|
+
From a fresh checkout, install the repository dependencies, then build and pack the standalone package:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npm ci
|
|
40
|
+
npm run build --prefix packages/rtl-analyzer
|
|
41
|
+
cd packages/rtl-analyzer
|
|
42
|
+
npm pack --dry-run
|
|
43
|
+
npm pack
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The package `prepack` hook rebuilds `dist/` automatically, so packing cannot silently use a missing or stale CLI build. The tarball contains only the compiled scanner/reporting runtime, this README, and the MIT license.
|
|
47
|
+
|
|
48
|
+
## Confirmed syntax coverage
|
|
49
|
+
|
|
50
|
+
The standalone CLI supports the following tested patterns. These are syntax-level results, not claims of complete framework compatibility:
|
|
51
|
+
|
|
52
|
+
| Area | Status | Tested scope |
|
|
53
|
+
| --- | --- | --- |
|
|
54
|
+
| React inline JSX/TSX styles | Verified | Static object properties including physical margins, padding, and text alignment. |
|
|
55
|
+
| Emotion `styled` templates | Verified | Static tagged templates imported from `@emotion/styled`. |
|
|
56
|
+
| Emotion `css` prop | Verified | `@emotion/react` tagged templates and static object expressions. |
|
|
57
|
+
| MUI `sx` | Partial | Supported MUI imports and aliases such as `ml` and `pr`; wrapper semantics remain conservative. |
|
|
58
|
+
| MUI `styled` templates | Verified | Static tagged templates imported from `@mui/material/styles`. |
|
|
59
|
+
| Vanilla CSS/HTML | Verified | Tested physical declarations and HTML direction attributes. |
|
|
60
|
+
| CSS Modules | Verified | Physical declarations in discovered `.module.css` files. |
|
|
61
|
+
| Tailwind utilities | Partial | Static class strings recognize `ml-*`, `mr-*`, `pl-*`, `pr-*`, `left-*`, `right-*`, `border-l-*`, `border-r-*`, `text-left`, `text-right`, and identifiable `rtl:`/`ltr:` variants. Dynamic composition is not evaluated. |
|
|
62
|
+
| Bootstrap 4 directional utilities | Partial | Static class strings recognize Bootstrap 4 `float-left/right`, responsive `float-{sm,md,lg,xl}-left/right`, `text-{sm,md,lg,xl}-left/right`, and `border-left/right[-0]`. Shared physical classes such as `ml-*` remain framework-neutral; Bootstrap version and runtime semantics are not inferred. |
|
|
63
|
+
| SCSS/Sass | Unsupported with diagnostic | Files are skipped and reported through `SOURCE_COVERAGE`. |
|
|
64
|
+
|
|
65
|
+
MUI `styled` object syntax is unsupported. Tailwind responsive/state prefixes and arbitrary values are covered only when the final utility is statically identifiable; dynamic `clsx`, `classnames`, and template expressions are intentionally not guessed. Next.js `app/`, `src/app/`, `pages/`, and `src/pages/` layouts can be discovered as ordinary files, but this does not certify Next.js-specific behavior.
|
|
66
|
+
|
|
67
|
+
Bootstrap support is limited to the listed Bootstrap 4 physical utility forms. Bootstrap 5 logical utilities such as `ms-*`, `me-*`, `ps-*`, and `pe-*`, custom classes, project configuration, and dynamic class composition are not interpreted.
|
|
68
|
+
|
|
69
|
+
To verify the tarball in an independent disposable project:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
npm run rtl:cli:package:smoke
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The smoke test installs with `npm install --ignore-scripts`, checks `--help` and `--version`, scans a disposable project in JSON, Markdown, and Dashboard formats, and checks that installed files contain no source-checkout paths.
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
npm install rtl-analyzer
|
|
79
|
+
rtl-analyzer --help
|
|
80
|
+
rtl-analyzer scan . --format json
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Candidate Preview and Apply/Rollback are not included in this standalone CLI milestone.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { fact } from './model.js';
|
|
2
|
+
const utilities = {
|
|
3
|
+
'float-left': 'float',
|
|
4
|
+
'float-right': 'float',
|
|
5
|
+
'text-left': 'text-align',
|
|
6
|
+
'text-right': 'text-align',
|
|
7
|
+
'border-left': 'border-left',
|
|
8
|
+
'border-right': 'border-right',
|
|
9
|
+
};
|
|
10
|
+
export function extractBootstrap(path, text, value, valueStart, context) {
|
|
11
|
+
const evidence = [];
|
|
12
|
+
for (const match of value.matchAll(/\S+/g)) {
|
|
13
|
+
const token = match[0];
|
|
14
|
+
const utility = token;
|
|
15
|
+
const key = utility.match(/^(?:float|border)-(?:left|right)(?:-0)?$|^(?:float|text)-(?:sm|md|lg|xl)-(?:left|right)$/)?.[0];
|
|
16
|
+
if (!key)
|
|
17
|
+
continue;
|
|
18
|
+
const base = key.replace(/^(?:float|text)-(?:sm|md|lg|xl)-/, (key.startsWith('float-') ? 'float-' : 'text-')).replace(/-0$/, '');
|
|
19
|
+
if (!utilities[base])
|
|
20
|
+
continue;
|
|
21
|
+
const property = utilities[base];
|
|
22
|
+
const normalized = property === 'text-align' ? base.endsWith('left') ? 'left' : 'right' : token;
|
|
23
|
+
const start = valueStart + match.index;
|
|
24
|
+
evidence.push(fact(path, text, 'css', `${context}/.${token}`, property, normalized, start, start + token.length, 'bootstrap-utility', [token]));
|
|
25
|
+
}
|
|
26
|
+
return evidence;
|
|
27
|
+
}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { exitCode } from './coverage.js';
|
|
2
|
+
import { scan } from './scan.js';
|
|
3
|
+
import { json, markdown } from './report.js';
|
|
4
|
+
import { publishReports } from './report-publisher.js';
|
|
5
|
+
import { publishArtifacts } from './report-publisher.js';
|
|
6
|
+
import { toSchemaV2Presentation } from './presentation-adapter.js';
|
|
7
|
+
import { structuredMarkdown } from './structured-markdown.js';
|
|
8
|
+
import { dashboardHtml } from './dashboard-html.js';
|
|
9
|
+
import { extractSourceSnippets } from './source-snippets.js';
|
|
10
|
+
import { pathToFileURL } from 'node:url';
|
|
11
|
+
const defaultDependencies = { scan, json, markdown, publishReports, publishArtifacts, extractSourceSnippets };
|
|
12
|
+
export async function runCli(argv, io, dependencies = defaultDependencies) {
|
|
13
|
+
let root = process.cwd();
|
|
14
|
+
let format = 'json';
|
|
15
|
+
let gate = false;
|
|
16
|
+
let outputDir;
|
|
17
|
+
let embedSource = false;
|
|
18
|
+
try {
|
|
19
|
+
const args = argv.filter(a => { if (a === '--fail-on-findings') {
|
|
20
|
+
gate = true;
|
|
21
|
+
return false;
|
|
22
|
+
} return true; });
|
|
23
|
+
for (let i = 0; i < args.length; i += 2) {
|
|
24
|
+
const key = args[i], value = args[i + 1];
|
|
25
|
+
if (key === '--embed-source-snippets') {
|
|
26
|
+
if (value && !value.startsWith('--'))
|
|
27
|
+
throw new Error('Flag --embed-source-snippets does not take a value');
|
|
28
|
+
embedSource = true;
|
|
29
|
+
i--;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (!value || value.startsWith('--'))
|
|
33
|
+
throw new Error('Missing option value');
|
|
34
|
+
if (key === '--root')
|
|
35
|
+
root = value;
|
|
36
|
+
else if (key === '--output-dir')
|
|
37
|
+
outputDir = value;
|
|
38
|
+
else if (key === '--format' && ['json', 'markdown', 'markdown-structured', 'dashboard'].includes(value))
|
|
39
|
+
format = value;
|
|
40
|
+
else
|
|
41
|
+
throw new Error('Unknown option or format');
|
|
42
|
+
}
|
|
43
|
+
if (embedSource && (!outputDir || format !== 'dashboard'))
|
|
44
|
+
throw new Error('--embed-source-snippets requires --format dashboard and --output-dir');
|
|
45
|
+
const r = await dependencies.scan(root);
|
|
46
|
+
const jsonBytes = dependencies.json(r);
|
|
47
|
+
const markdownBytes = dependencies.markdown(r);
|
|
48
|
+
const needsPresentation = ['markdown-structured', 'dashboard'].includes(format);
|
|
49
|
+
const presentation = needsPresentation ? toSchemaV2Presentation(r) : undefined;
|
|
50
|
+
const structuredBytes = needsPresentation ? structuredMarkdown(presentation) : '';
|
|
51
|
+
const snippets = embedSource ? await (dependencies.extractSourceSnippets ?? extractSourceSnippets)(root, r.findings) : undefined;
|
|
52
|
+
const dashboardBytes = format === 'dashboard' ? dashboardHtml(presentation, Boolean(outputDir), snippets) : '';
|
|
53
|
+
if (outputDir) {
|
|
54
|
+
if (format === 'markdown-structured' && dependencies.publishArtifacts)
|
|
55
|
+
await dependencies.publishArtifacts(root, outputDir, [{ name: 'rtl-report.json', contents: jsonBytes }, { name: 'rtl-report.md', contents: markdownBytes }, { name: 'rtl-report-structured.md', contents: structuredBytes }]);
|
|
56
|
+
else if (format === 'dashboard' && dependencies.publishArtifacts)
|
|
57
|
+
await dependencies.publishArtifacts(root, outputDir, [{ name: 'rtl-report.json', contents: jsonBytes }, { name: 'rtl-report.md', contents: markdownBytes }, { name: 'rtl-report-structured.md', contents: structuredBytes }, { name: 'rtl-report-dashboard.html', contents: dashboardBytes }]);
|
|
58
|
+
else
|
|
59
|
+
await dependencies.publishReports(root, outputDir, jsonBytes, markdownBytes);
|
|
60
|
+
}
|
|
61
|
+
io.writeStdout(format === 'markdown' ? markdownBytes : format === 'markdown-structured' ? structuredBytes : format === 'dashboard' ? dashboardBytes : jsonBytes);
|
|
62
|
+
const findings = r.findings.filter((f) => !['INFORMATIONAL', 'INTENTIONAL_LTR'].includes(f.category)).length;
|
|
63
|
+
const code = exitCode(r.complete, findings, gate);
|
|
64
|
+
if (outputDir)
|
|
65
|
+
io.writeStderr(`RTL scan: ${r.complete ? 'complete' : 'incomplete'}; files=${r.files.length}; findings=${findings}; output=${outputDir}`);
|
|
66
|
+
return code;
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
io.writeStderr(e instanceof Error ? e.message : String(e ?? 'Scan failed'));
|
|
70
|
+
return 2;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
74
|
+
const io = { writeStdout: (s) => process.stdout.write(s), writeStderr: (s) => console.error(s) };
|
|
75
|
+
process.exitCode = await runCli(process.argv.slice(2), io);
|
|
76
|
+
}
|
package/dist/codemod.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { REVIEW_SOURCE } from './review-session.js';
|
|
4
|
+
import { applyReviewPatch } from './review-session.js';
|
|
5
|
+
export const BIDI_TRANSFORMATION_ID = 'bidi-isolate-auto';
|
|
6
|
+
export class TransformationRejected extends Error {
|
|
7
|
+
code;
|
|
8
|
+
constructor(code) {
|
|
9
|
+
super(code);
|
|
10
|
+
this.code = code;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
const sha = (value) => createHash('sha256').update(value).digest('hex');
|
|
14
|
+
function hasIsolation(node) {
|
|
15
|
+
for (let parent = node.parent; parent; parent = parent.parent) {
|
|
16
|
+
if (ts.isJsxElement(parent) || ts.isJsxSelfClosingElement(parent)) {
|
|
17
|
+
const opening = ts.isJsxElement(parent) ? parent.openingElement : parent;
|
|
18
|
+
const tag = opening.tagName.getText();
|
|
19
|
+
if (tag === 'bdi' || opening.attributes.properties.some(p => ts.isJsxAttribute(p) && p.name.getText() === 'dir'))
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
export function proposeBidiIsolation(finding, source) {
|
|
26
|
+
if (finding.id !== 'RTL.BIDI.ISOLATION:741d2ce2aec3a86cf2db37ea' || finding.path !== REVIEW_SOURCE)
|
|
27
|
+
throw new TransformationRejected('UNSUPPORTED_FINDING_IDENTITY');
|
|
28
|
+
const file = ts.createSourceFile(REVIEW_SOURCE, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
|
|
29
|
+
let target;
|
|
30
|
+
function visit(node) { if (ts.isJsxExpression(node) && node.getStart(file) === finding.range.start.offset && node.end === finding.range.end.offset)
|
|
31
|
+
target = node; ts.forEachChild(node, visit); }
|
|
32
|
+
visit(file);
|
|
33
|
+
if (!target)
|
|
34
|
+
throw new TransformationRejected('UNSUPPORTED_AST_RANGE');
|
|
35
|
+
if (!target.expression || !ts.isPropertyAccessExpression(target.expression) || target.expression.name.text !== 'id')
|
|
36
|
+
throw new TransformationRejected('AMBIGUOUS_TOKEN_EXPRESSION');
|
|
37
|
+
if (hasIsolation(target))
|
|
38
|
+
throw new TransformationRejected('ALREADY_ISOLATED');
|
|
39
|
+
if (!target.parent || !(ts.isJsxElement(target.parent) || ts.isJsxFragment(target.parent)))
|
|
40
|
+
throw new TransformationRejected('UNSUPPORTED_WRAPPER');
|
|
41
|
+
const original = source.slice(finding.range.start.offset, finding.range.end.offset);
|
|
42
|
+
if (original !== '{i.id}')
|
|
43
|
+
throw new TransformationRejected('SOURCE_RANGE_MISMATCH');
|
|
44
|
+
return { transformationId: BIDI_TRANSFORMATION_ID, reason: 'Direct invoice ID property access in JSX; wrap the exact expression in auto-direction bidi isolation.', patch: { findingId: finding.id, path: REVIEW_SOURCE, startOffset: finding.range.start.offset, endOffset: finding.range.end.offset, expectedSha256: sha(original), replacement: '<bdi dir="auto">{i.id}</bdi>' } };
|
|
45
|
+
}
|
|
46
|
+
export async function dryRunBidiIsolation(session, finding, source) {
|
|
47
|
+
const proposal = proposeBidiIsolation(finding, source);
|
|
48
|
+
const candidate = await applyReviewPatch(session, proposal.patch);
|
|
49
|
+
return { proposal, candidate };
|
|
50
|
+
}
|
|
51
|
+
export function analyzeBidiIsolation(finding, source) {
|
|
52
|
+
return proposeBidiIsolation(finding, source);
|
|
53
|
+
}
|
package/dist/coverage.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { hash } from './model.js';
|
|
3
|
+
const presentation = new Set(['color', 'bgcolor', 'backgroundColor', 'borderColor', 'fill', 'stroke', 'fontSize', 'fontWeight', 'opacity']);
|
|
4
|
+
export function classifyDiagnostics(diagnostics, evidence, sources, policy) {
|
|
5
|
+
return diagnostics.map(d => {
|
|
6
|
+
let blocking = true, impact = 'DIRECTIONAL_UNSUPPORTED', rationale = 'Unresolved styling may contain directional declarations; safe classification is incomplete.';
|
|
7
|
+
if (d.code.endsWith('_PARSE') || d.code === 'SOURCE_COVERAGE') {
|
|
8
|
+
impact = 'SOURCE_FAILURE';
|
|
9
|
+
rationale = 'Source/parser coverage failed.';
|
|
10
|
+
}
|
|
11
|
+
else if (d.code === 'DYNAMIC_VALUE') {
|
|
12
|
+
const e = evidence.find(e => e.path === d.path && e.range.start.offset <= d.range.start.offset && e.range.end.offset >= d.range.end.offset);
|
|
13
|
+
const exception = e ? policy.dynamicExceptions.find(x => x.path === e.path && x.property === e.property && x.valueDigest === hash(e.value) && x.sourceDigest === hash(sources.get(e.path) ?? '')) : undefined;
|
|
14
|
+
if (e && (presentation.has(e.property) || exception)) {
|
|
15
|
+
blocking = false;
|
|
16
|
+
impact = 'NONBLOCKING_DYNAMIC';
|
|
17
|
+
rationale = exception ? exception.reason + ' Source and expression fingerprints match the data-only review exception.' : 'Dynamic presentation value does not block the current directional rules; expression is retained and not evaluated.';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
else if (d.code === 'UNRESOLVED_SX_OWNER') {
|
|
21
|
+
const raw = (sources.get(d.path) ?? '').slice(d.range.start.offset, d.range.end.offset);
|
|
22
|
+
const sf = ts.createSourceFile('fragment.tsx', `<X ${raw}/>`, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
|
|
23
|
+
let safe = false;
|
|
24
|
+
function visit(n) { if (ts.isJsxAttribute(n) && n.name.getText(sf) === 'sx' && n.initializer && ts.isJsxExpression(n.initializer) && n.initializer.expression && ts.isObjectLiteralExpression(n.initializer.expression))
|
|
25
|
+
safe = n.initializer.expression.properties.every(p => ts.isPropertyAssignment(p) && ts.isIdentifier(p.name) && presentation.has(p.name.text) && (ts.isNumericLiteral(p.initializer) || ts.isStringLiteral(p.initializer))); ts.forEachChild(n, visit); }
|
|
26
|
+
visit(sf);
|
|
27
|
+
if (safe) {
|
|
28
|
+
blocking = false;
|
|
29
|
+
impact = 'NONBLOCKING_DYNAMIC';
|
|
30
|
+
rationale = 'Unknown component owner, but the entire literal sx object contains only non-directional presentation keys.';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return { ...d, impact, blocking, rationale };
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
export const exitCode = (complete, findings, gate) => !complete ? 2 : gate && findings > 0 ? 1 : 0;
|
package/dist/css.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import postcss from "postcss";
|
|
2
|
+
import scss from "postcss-scss";
|
|
3
|
+
import valueParser from "postcss-value-parser";
|
|
4
|
+
import { fact, range } from "./model.js";
|
|
5
|
+
export function extractCss(path, original, fragment = original, base = 0, mechanism = "css", context = "stylesheet") {
|
|
6
|
+
const evidence = [], diagnostics = [];
|
|
7
|
+
try {
|
|
8
|
+
const root = postcss.parse(fragment, { from: undefined });
|
|
9
|
+
root.walkDecls(d => {
|
|
10
|
+
const start = base + d.source.start.offset, end = base + d.source.end.offset;
|
|
11
|
+
const parents = [];
|
|
12
|
+
let p = d.parent;
|
|
13
|
+
while (p && p.type !== "root") {
|
|
14
|
+
parents.unshift(p.type === "rule" ? p.selector : p.type === "atrule" ? `@${p.name} ${p.params}` : 'container');
|
|
15
|
+
p = p.parent;
|
|
16
|
+
}
|
|
17
|
+
evidence.push(fact(path, original, mechanism, `${context}/${parents.join("/")}`, d.prop, d.value, start, end, "css", valueParser(d.value).nodes.map(n => valueParser.stringify(n))));
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
diagnostics.push({ path, code: "CSS_PARSE", message: "CSS fragment could not be parsed; coverage incomplete.", range: range(original, base, base + fragment.length) });
|
|
22
|
+
}
|
|
23
|
+
return { evidence, diagnostics };
|
|
24
|
+
}
|
|
25
|
+
export function extractScss(path, original) {
|
|
26
|
+
const evidence = [], diagnostics = [];
|
|
27
|
+
const coverage = (message, start, end) => diagnostics.push({ path, code: 'SOURCE_COVERAGE', message, range: range(original, start, end) });
|
|
28
|
+
if (/@(?:use|forward|import)\b/.test(original))
|
|
29
|
+
coverage('SCSS imports are not resolved; coverage is incomplete.', 0, original.length);
|
|
30
|
+
if (/#\{/.test(original))
|
|
31
|
+
coverage('SCSS interpolation is not evaluated; coverage is incomplete.', 0, original.length);
|
|
32
|
+
if (/@(?:mixin|include)\b/.test(original))
|
|
33
|
+
coverage('SCSS mixins are not expanded; coverage is incomplete.', 0, original.length);
|
|
34
|
+
try {
|
|
35
|
+
const root = scss.parse(original, { from: undefined });
|
|
36
|
+
root.walkDecls(d => {
|
|
37
|
+
if (/#\{/.test(original))
|
|
38
|
+
return;
|
|
39
|
+
let parent = d.parent, insideMixin = false;
|
|
40
|
+
while (parent && parent.type !== 'root') {
|
|
41
|
+
if (parent.type === 'atrule' && parent.name === 'mixin')
|
|
42
|
+
insideMixin = true;
|
|
43
|
+
parent = parent.parent;
|
|
44
|
+
}
|
|
45
|
+
if (insideMixin || /#\{/.test(d.toString()))
|
|
46
|
+
return;
|
|
47
|
+
const start = d.source.start.offset, end = d.source.end.offset;
|
|
48
|
+
const parents = [];
|
|
49
|
+
let p = d.parent;
|
|
50
|
+
while (p && p.type !== 'root') {
|
|
51
|
+
parents.unshift(p.type === 'rule' ? p.selector : p.type === 'atrule' ? `@${p.name} ${p.params}` : 'container');
|
|
52
|
+
p = p.parent;
|
|
53
|
+
}
|
|
54
|
+
evidence.push(fact(path, original, 'css', `stylesheet/${parents.join('/')}`, d.prop, d.value, start, end, 'scss-css', valueParser(d.value).nodes.map(n => valueParser.stringify(n))));
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
coverage('SCSS source could not be parsed; coverage is incomplete.', 0, original.length);
|
|
59
|
+
}
|
|
60
|
+
return { evidence, diagnostics };
|
|
61
|
+
}
|