rtl-analyzer 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 +53 -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 +38 -0
- package/dist/structured-markdown.js +36 -0
- package/dist/tailwind.js +21 -0
- package/dist/typescript.js +191 -0
- package/package.json +26 -4
package/dist/tailwind.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { fact } from './model.js';
|
|
2
|
+
const utilities = {
|
|
3
|
+
ml: 'margin-left', mr: 'margin-right', pl: 'padding-left', pr: 'padding-right',
|
|
4
|
+
left: 'left', right: 'right', 'text-left': 'text-align', 'text-right': 'text-align',
|
|
5
|
+
'border-l': 'border-left', 'border-r': 'border-right',
|
|
6
|
+
};
|
|
7
|
+
export function extractTailwind(path, text, value, valueStart, context) {
|
|
8
|
+
const evidence = [];
|
|
9
|
+
for (const match of value.matchAll(/\S+/g)) {
|
|
10
|
+
const token = match[0];
|
|
11
|
+
const parts = token.split(':');
|
|
12
|
+
const utility = parts.at(-1);
|
|
13
|
+
const key = /^(text-left|text-right)(?:-|$)/.test(utility) ? utility.startsWith('text-left') ? 'text-left' : 'text-right' : utility.match(/^(border-[lr]|(?:ml|mr|pl|pr|left|right))(?:-|$)/)?.[1];
|
|
14
|
+
if (!key || !utilities[key])
|
|
15
|
+
continue;
|
|
16
|
+
const start = valueStart + match.index;
|
|
17
|
+
const value = key === 'text-left' ? 'left' : key === 'text-right' ? 'right' : token;
|
|
18
|
+
evidence.push(fact(path, text, 'css', `${context}/.${token}`, utilities[key], value, start, start + token.length, 'tailwind-utility', [token]));
|
|
19
|
+
}
|
|
20
|
+
return evidence;
|
|
21
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { extractCss } from "./css.js";
|
|
3
|
+
import { fact, range } from "./model.js";
|
|
4
|
+
import { extractTailwind } from './tailwind.js';
|
|
5
|
+
import { extractBootstrap } from './bootstrap.js';
|
|
6
|
+
export function extractTypescript(path, text) {
|
|
7
|
+
const sf = ts.createSourceFile(path, text, ts.ScriptTarget.Latest, true, /\.(?:tsx|jsx)$/.test(path) ? ts.ScriptKind.TSX : /\.js$/.test(path) ? ts.ScriptKind.JSX : ts.ScriptKind.TS);
|
|
8
|
+
const evidence = [], diagnostics = [];
|
|
9
|
+
const imports = new Map();
|
|
10
|
+
const constants = new Map();
|
|
11
|
+
const ambiguousConstants = new Set();
|
|
12
|
+
function pre(n) {
|
|
13
|
+
if (ts.isImportDeclaration(n) && ts.isStringLiteral(n.moduleSpecifier)) {
|
|
14
|
+
const c = n.importClause;
|
|
15
|
+
if (c?.name)
|
|
16
|
+
imports.set(c.name.text, n.moduleSpecifier.text);
|
|
17
|
+
if (c?.namedBindings && ts.isNamedImports(c.namedBindings))
|
|
18
|
+
for (const e of c.namedBindings.elements)
|
|
19
|
+
imports.set(e.name.text, `${n.moduleSpecifier.text}:${e.propertyName?.text ?? e.name.text}`);
|
|
20
|
+
}
|
|
21
|
+
if (ts.isVariableDeclaration(n) && ts.isIdentifier(n.name) && n.initializer && ts.isVariableDeclarationList(n.parent) && (n.parent.flags & ts.NodeFlags.Const)) {
|
|
22
|
+
if (constants.has(n.name.text))
|
|
23
|
+
ambiguousConstants.add(n.name.text);
|
|
24
|
+
else
|
|
25
|
+
constants.set(n.name.text, n.initializer);
|
|
26
|
+
}
|
|
27
|
+
ts.forEachChild(n, pre);
|
|
28
|
+
}
|
|
29
|
+
pre(sf);
|
|
30
|
+
const diag = (n, code, message) => diagnostics.push({ path, code, message, range: range(text, n.getStart(sf), n.end) });
|
|
31
|
+
const context = (n) => { let p = n; while (p) {
|
|
32
|
+
if (ts.isFunctionDeclaration(p) && p.name)
|
|
33
|
+
return p.name.text;
|
|
34
|
+
if (ts.isVariableDeclaration(p) && ts.isIdentifier(p.name))
|
|
35
|
+
return p.name.text;
|
|
36
|
+
p = p.parent;
|
|
37
|
+
} return 'module'; };
|
|
38
|
+
const aliases = { ml: 'marginLeft', mr: 'marginRight', pl: 'paddingLeft', pr: 'paddingRight', mx: 'marginHorizontalAxis', my: 'marginVerticalAxis', px: 'paddingHorizontalAxis', py: 'paddingVerticalAxis', m: 'margin', p: 'padding' };
|
|
39
|
+
function object(n, mechanism, ctx, seen = new Set(), inheritedKey) {
|
|
40
|
+
if (ts.isParenthesizedExpression(n) || ts.isAsExpression(n) || ts.isSatisfiesExpression(n)) {
|
|
41
|
+
object(n.expression, mechanism, ctx, seen);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (ts.isIdentifier(n) && constants.has(n.text) && !ambiguousConstants.has(n.text) && !seen.has(n.text)) {
|
|
45
|
+
object(constants.get(n.text), mechanism, `${ctx}/reference:${n.text}`, new Set([...seen, n.text]));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (ts.isArrayLiteralExpression(n)) {
|
|
49
|
+
n.elements.forEach((e, i) => object(e, mechanism, `${ctx}/array:${i}`, seen));
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (ts.isArrowFunction(n) || ts.isFunctionExpression(n)) {
|
|
53
|
+
diag(n, 'STYLE_CALLBACK', 'Callback is inspected structurally, never invoked.');
|
|
54
|
+
if (ts.isBlock(n.body)) {
|
|
55
|
+
for (const stmt of n.body.statements)
|
|
56
|
+
if (ts.isReturnStatement(stmt) && stmt.expression)
|
|
57
|
+
object(stmt.expression, mechanism, ctx + '/callback', seen);
|
|
58
|
+
}
|
|
59
|
+
else
|
|
60
|
+
object(n.body, mechanism, ctx + '/callback', seen);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (!ts.isObjectLiteralExpression(n)) {
|
|
64
|
+
diag(n, 'UNRESOLVED_STYLE', 'Style expression is not a bounded object/literal; not evaluated.');
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
for (const p of n.properties) {
|
|
68
|
+
if (!ts.isPropertyAssignment(p) || ts.isComputedPropertyName(p.name)) {
|
|
69
|
+
diag(p, 'UNRESOLVED_PROPERTY', 'Spread, shorthand, method or computed style key not resolved.');
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const key = ts.isIdentifier(p.name) || ts.isStringLiteral(p.name) || ts.isNumericLiteral(p.name) ? p.name.text : p.name.getText(sf);
|
|
73
|
+
const v = p.initializer;
|
|
74
|
+
const resolvedKey = inheritedKey ?? (mechanism === 'mui-sx' ? aliases[key] ?? key : key);
|
|
75
|
+
if (ts.isArrayLiteralExpression(v) && mechanism === 'mui-sx' && key !== 'sx') {
|
|
76
|
+
v.elements.forEach((item, i) => { if (item.kind === ts.SyntaxKind.NullKeyword)
|
|
77
|
+
return; const literal = ts.isStringLiteral(item) || ts.isNumericLiteral(item) || (ts.isPrefixUnaryExpression(item) && ts.isNumericLiteral(item.operand)); if (!literal)
|
|
78
|
+
diag(item, 'DYNAMIC_VALUE', `Value for ${resolvedKey} is dynamic; original retained.`); evidence.push(fact(path, text, mechanism, `${ctx}/${key}/responsive:${i}`, resolvedKey, item.getText(sf), item.getStart(sf), item.end, /^(margin|padding|gap)/.test(resolvedKey) ? 'mui-theme-spacing' : 'mui-system')); });
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (ts.isObjectLiteralExpression(v) || ts.isArrayLiteralExpression(v)) {
|
|
82
|
+
const responsive = mechanism === 'mui-sx' && ts.isObjectLiteralExpression(v) && v.properties.length > 0 && v.properties.every(x => ts.isPropertyAssignment(x) && /^(xs|sm|md|lg|xl)$/.test(x.name.getText(sf)));
|
|
83
|
+
object(v, mechanism, `${ctx}/${key}`, seen, responsive ? resolvedKey : undefined);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
const literal = ts.isStringLiteral(v) || ts.isNumericLiteral(v) || ts.isNoSubstitutionTemplateLiteral(v) || (ts.isPrefixUnaryExpression(v) && ts.isNumericLiteral(v.operand));
|
|
87
|
+
if (!literal) {
|
|
88
|
+
diag(v, 'DYNAMIC_VALUE', `Value for ${key} is dynamic; original retained.`);
|
|
89
|
+
}
|
|
90
|
+
const normalized = resolvedKey;
|
|
91
|
+
const spacing = /^(margin|padding|gap|rowGap|columnGap)/.test(normalized) || /(margin|padding|gap)(?:\/|$)/i.test(ctx);
|
|
92
|
+
evidence.push(fact(path, text, mechanism, ctx, normalized, v.getText(sf), p.getStart(sf), p.end, mechanism === 'react-inline' ? 'react-css' : mechanism === 'mui-theme' ? 'emotion-css' : spacing ? 'mui-theme-spacing' : 'mui-system'));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function visit(n) {
|
|
96
|
+
if (ts.isCallExpression(n) && ts.isPropertyAccessExpression(n.expression) && n.expression.getText(sf) === 'React.createElement') {
|
|
97
|
+
const props = n.arguments[1];
|
|
98
|
+
if (props && ts.isObjectLiteralExpression(props))
|
|
99
|
+
for (const p of props.properties)
|
|
100
|
+
if (ts.isPropertyAssignment(p) && p.name.getText(sf) === 'style')
|
|
101
|
+
object(p.initializer, 'react-inline', 'React.createElement/style');
|
|
102
|
+
}
|
|
103
|
+
if (ts.isJsxAttribute(n) && n.initializer && ts.isJsxExpression(n.initializer) && n.initializer.expression) {
|
|
104
|
+
const key = n.name.getText(sf);
|
|
105
|
+
const opening = n.parent.parent;
|
|
106
|
+
const tag = ts.isJsxOpeningElement(opening) || ts.isJsxSelfClosingElement(opening) ? opening.tagName.getText(sf) : '';
|
|
107
|
+
const mui = imports.get(tag)?.startsWith('@mui/') || ['FormField', 'Button'].includes(tag) && imports.get(tag)?.startsWith('@atlas/design-system');
|
|
108
|
+
if (key === 'style')
|
|
109
|
+
object(n.initializer.expression, 'react-inline', `${context(n)}/${tag}`);
|
|
110
|
+
if (key === 'sx') {
|
|
111
|
+
if (mui)
|
|
112
|
+
object(n.initializer.expression, 'mui-sx', `${context(n)}/${tag}`);
|
|
113
|
+
else
|
|
114
|
+
diag(n, 'UNRESOLVED_SX_OWNER', 'sx owner not resolved to a known MUI import/wrapper.');
|
|
115
|
+
}
|
|
116
|
+
if (key === 'css' && ts.isObjectLiteralExpression(n.initializer.expression))
|
|
117
|
+
object(n.initializer.expression, 'react-inline', `${context(n)}/${tag}/css`);
|
|
118
|
+
if (key === 'className' && ts.isStringLiteral(n.initializer.expression)) {
|
|
119
|
+
const valueStart = n.initializer.expression.getStart(sf) + 1;
|
|
120
|
+
evidence.push(...extractTailwind(path, text, n.initializer.expression.text, valueStart, `${context(n)}/${tag}`));
|
|
121
|
+
evidence.push(...extractBootstrap(path, text, n.initializer.expression.text, valueStart, `${context(n)}/${tag}`));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (ts.isJsxAttribute(n) && n.name.getText(sf) === 'className' && n.initializer && ts.isStringLiteral(n.initializer)) {
|
|
125
|
+
const opening = n.parent.parent;
|
|
126
|
+
const tag = ts.isJsxOpeningElement(opening) || ts.isJsxSelfClosingElement(opening) ? opening.tagName.getText(sf) : '';
|
|
127
|
+
evidence.push(...extractTailwind(path, text, n.initializer.text, n.initializer.getStart(sf) + 1, `${context(n)}/${tag}`));
|
|
128
|
+
evidence.push(...extractBootstrap(path, text, n.initializer.text, n.initializer.getStart(sf) + 1, `${context(n)}/${tag}`));
|
|
129
|
+
}
|
|
130
|
+
if (ts.isCallExpression(n) && ts.isIdentifier(n.expression) && imports.get(n.expression.text)?.endsWith(':createTheme')) {
|
|
131
|
+
for (const a of n.arguments)
|
|
132
|
+
if (ts.isObjectLiteralExpression(a))
|
|
133
|
+
for (const p of a.properties)
|
|
134
|
+
if (ts.isPropertyAssignment(p) && p.name.getText(sf) === 'components' && ts.isObjectLiteralExpression(p.initializer)) {
|
|
135
|
+
function overrides(x) { if (ts.isPropertyAssignment(x) && x.name.getText(sf) === 'styleOverrides')
|
|
136
|
+
object(x.initializer, 'mui-theme', context(n) + '/styleOverrides');
|
|
137
|
+
else
|
|
138
|
+
ts.forEachChild(x, overrides); }
|
|
139
|
+
overrides(p.initializer);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (ts.isTaggedTemplateExpression(n)) {
|
|
143
|
+
let tag = n.tag;
|
|
144
|
+
while (ts.isPropertyAccessExpression(tag) || ts.isCallExpression(tag))
|
|
145
|
+
tag = tag.expression;
|
|
146
|
+
const imported = ts.isIdentifier(tag) ? imports.get(tag.text) : undefined;
|
|
147
|
+
const cssProp = ts.isIdentifier(tag) && imported === '@emotion/react:css' && ts.isJsxExpression(n.parent) && ts.isJsxAttribute(n.parent.parent) && n.parent.parent.name.getText(sf) === 'css';
|
|
148
|
+
const muiStyled = ts.isIdentifier(tag) && Boolean(imported && ((imported === '@mui/material/styles:styled') || imported === '@mui/material/styles'));
|
|
149
|
+
if (ts.isIdentifier(tag) && (imported === '@emotion/styled' || cssProp || muiStyled)) {
|
|
150
|
+
if (ts.isNoSubstitutionTemplateLiteral(n.template)) {
|
|
151
|
+
const start = n.template.getStart(sf) + 1;
|
|
152
|
+
const raw = text.slice(start, n.template.end - 1);
|
|
153
|
+
if (raw.includes('\\'))
|
|
154
|
+
diag(n.template, 'TEMPLATE_ESCAPE', 'Escaped template requires cooked/raw mapping; fragment skipped.');
|
|
155
|
+
else {
|
|
156
|
+
const r = extractCss(path, text, raw, start, 'emotion-template', context(n));
|
|
157
|
+
evidence.push(...r.evidence);
|
|
158
|
+
diagnostics.push(...r.diagnostics);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
diag(n.template, 'EMOTION_INTERPOLATION', 'Interpolated template not evaluated; independent declarations extracted conservatively.');
|
|
163
|
+
const chunks = [n.template.head, ...n.template.templateSpans.map(s => s.literal)];
|
|
164
|
+
for (const chunk of chunks) {
|
|
165
|
+
const start = chunk.getStart(sf) + 1;
|
|
166
|
+
const end = chunk.end - (chunk.kind === ts.SyntaxKind.TemplateTail ? 1 : 2);
|
|
167
|
+
const raw = text.slice(start, end);
|
|
168
|
+
if (raw.includes('\\')) {
|
|
169
|
+
diag(chunk, 'TEMPLATE_ESCAPE', 'Escaped interpolated fragment skipped.');
|
|
170
|
+
continue;
|
|
171
|
+
} // Only standalone semicolon-terminated declarations; no crossing holes.
|
|
172
|
+
const regex = /(?:^|[;\n])\s*([a-z-]+\s*:[^;{}$]+;)/g;
|
|
173
|
+
let m;
|
|
174
|
+
while ((m = regex.exec(raw))) {
|
|
175
|
+
const offset = start + m.index + m[0].indexOf(m[1]);
|
|
176
|
+
const r = extractCss(path, text, m[1], offset, 'emotion-template', context(n));
|
|
177
|
+
evidence.push(...r.evidence);
|
|
178
|
+
diagnostics.push(...r.diagnostics);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
ts.forEachChild(n, visit);
|
|
185
|
+
}
|
|
186
|
+
visit(sf);
|
|
187
|
+
const parsed = sf;
|
|
188
|
+
for (const d of parsed.parseDiagnostics)
|
|
189
|
+
diagnostics.push({ path, code: 'TS_PARSE', message: ts.flattenDiagnosticMessageText(d.messageText, ' '), range: range(text, d.start ?? 0, (d.start ?? 0) + (d.length ?? 0)) });
|
|
190
|
+
return { evidence, diagnostics };
|
|
191
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rtl-analyzer",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Conservative RTL risk scanning and report generation",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"rtl-analyzer": "dist/standalone-cli.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist/**",
|
|
11
|
+
"README.md",
|
|
12
|
+
"LICENSE"
|
|
13
|
+
],
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=22.12.0"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc -p tsconfig.json",
|
|
19
|
+
"prepack": "npm run build"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"parse5": "7.3.0",
|
|
23
|
+
"postcss": "8.5.29",
|
|
24
|
+
"postcss-scss": "4.0.9",
|
|
25
|
+
"postcss-value-parser": "4.2.0",
|
|
26
|
+
"typescript": "~5.9.0"
|
|
27
|
+
}
|
|
28
|
+
}
|