@justinmoto/frontend-guardian-core 0.1.4 → 0.1.5
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/dist/scanEngine.d.ts.map +1 -1
- package/dist/scanEngine.js +26 -9
- package/package.json +10 -7
package/dist/scanEngine.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scanEngine.d.ts","sourceRoot":"","sources":["../src/scanEngine.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC7C,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AACF,MAAM,MAAM,SAAS,GAAG;IAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAClF,MAAM,MAAM,UAAU,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,EAAE,CAAC;IAAC,UAAU,EAAE,SAAS,EAAE,CAAA;CAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"scanEngine.d.ts","sourceRoot":"","sources":["../src/scanEngine.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC7C,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AACF,MAAM,MAAM,SAAS,GAAG;IAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAClF,MAAM,MAAM,UAAU,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,EAAE,CAAC;IAAC,UAAU,EAAE,SAAS,EAAE,CAAA;CAAE,CAAC;AA8T/G,wBAAsB,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAajE;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,GAAG,UAAU,CAG7E"}
|
package/dist/scanEngine.js
CHANGED
|
@@ -142,16 +142,26 @@ function getUnusedVariablesWithLine(ast) {
|
|
|
142
142
|
});
|
|
143
143
|
return unused;
|
|
144
144
|
}
|
|
145
|
+
function isCardLike(className) {
|
|
146
|
+
const hasRounded = /\brounded[\w-]*/.test(className);
|
|
147
|
+
const hasBg = /\bbg-/.test(className) || /\bbackdrop-/.test(className);
|
|
148
|
+
return !!(hasRounded && hasBg);
|
|
149
|
+
}
|
|
145
150
|
function runAnalysis(fileContents) {
|
|
146
151
|
const sourceOnly = fileContents.filter((f) => isSourcePath(f.path));
|
|
147
152
|
const warnings = [];
|
|
148
153
|
const jsxHashes = new Map();
|
|
149
|
-
const
|
|
154
|
+
const spacingByContext = new Map();
|
|
150
155
|
const radiusByFile = new Map();
|
|
151
156
|
const colorClassesByFile = new Map();
|
|
152
157
|
const arbitraryColorByFile = new Map();
|
|
153
158
|
const buttonDataByFile = new Map();
|
|
154
159
|
const MAX_LOCATIONS = 25;
|
|
160
|
+
function getSpacingMap(context) {
|
|
161
|
+
if (!spacingByContext.has(context))
|
|
162
|
+
spacingByContext.set(context, new Map());
|
|
163
|
+
return spacingByContext.get(context);
|
|
164
|
+
}
|
|
155
165
|
for (const { path: filePath, code } of sourceOnly) {
|
|
156
166
|
try {
|
|
157
167
|
const ast = parser.parse(code, { sourceType: "module", plugins: ["jsx", "typescript"], attachComment: false });
|
|
@@ -175,6 +185,8 @@ function runAnalysis(fileContents) {
|
|
|
175
185
|
}
|
|
176
186
|
const classEntries = extractClassNamesWithLines(ast);
|
|
177
187
|
for (const { value: cn, line } of classEntries) {
|
|
188
|
+
const context = isCardLike(cn) ? "card" : "default";
|
|
189
|
+
const spacingData = getSpacingMap(context);
|
|
178
190
|
const parts = cn.split(/\s+/).filter(Boolean);
|
|
179
191
|
for (const p of parts) {
|
|
180
192
|
if (/^p[xy]?-[a-z0-9]+$/.test(p) || /^m[xy]?-[a-z0-9]+$/.test(p)) {
|
|
@@ -219,14 +231,19 @@ function runAnalysis(fileContents) {
|
|
|
219
231
|
});
|
|
220
232
|
}
|
|
221
233
|
}
|
|
222
|
-
for (const [,
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
234
|
+
for (const [context, spacingData] of spacingByContext) {
|
|
235
|
+
for (const [, data] of spacingData) {
|
|
236
|
+
if (data.values.size > 1) {
|
|
237
|
+
const label = context === "card" ? " (cards/boxes)" : "";
|
|
238
|
+
warnings.push({
|
|
239
|
+
file: "(project)",
|
|
240
|
+
locations: data.locations.slice(0, MAX_LOCATIONS),
|
|
241
|
+
message: `Mixed spacing values${label}: ${[...data.values].join(", ")}`,
|
|
242
|
+
suggestion: context === "card"
|
|
243
|
+
? "Use one padding for all cards/boxes (e.g. p-6)."
|
|
244
|
+
: "Pick one spacing scale for containers/layout (e.g. p-4) and use it consistently.",
|
|
245
|
+
});
|
|
246
|
+
}
|
|
230
247
|
}
|
|
231
248
|
}
|
|
232
249
|
const radiusFileList = [...radiusByFile.entries()];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justinmoto/frontend-guardian-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Scan engine for Frontend Guardian. To run scans from the CLI use: npx frontend-guardian .",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
"default": "./dist/index.js"
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
|
-
"files": [
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/parser": "^7.26.0",
|
|
21
21
|
"@babel/traverse": "^7.26.0",
|
|
@@ -35,5 +35,8 @@
|
|
|
35
35
|
"components",
|
|
36
36
|
"ast"
|
|
37
37
|
],
|
|
38
|
-
"license": "MIT"
|
|
39
|
-
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsc"
|
|
41
|
+
}
|
|
42
|
+
}
|