@salty-css/eslint-plugin-core 0.0.1-alpha.12 → 0.0.1-alpha.14
Sign up to get free protection for your applications and to get access to all the features.
- package/index.cjs +1 -1
- package/index.js +42 -26
- package/package.json +1 -1
package/index.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";require("esbuild");const
|
1
|
+
"use strict";require("esbuild");const x=require("winston");require("child_process");require("path");require("fs");require("fs/promises");function P(e){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const a in e)if(a!=="default"){const s=Object.getOwnPropertyDescriptor(e,a);Object.defineProperty(n,a,s.get?s:{enumerable:!0,get:()=>e[a]})}}return n.default=e,Object.freeze(n)}const i=P(x);i.createLogger({level:"info",format:i.format.combine(i.format.colorize(),i.format.cli()),transports:[new i.transports.Console({})]});const v=["salty","css","styles","styled"],E=(e=[])=>new RegExp(`\\.(${[...v,...e].join("|")})\\.`),O=(e,n=[])=>E(n).test(e),h={meta:{type:"problem",fixable:"code",docs:{description:"Ensure `variants` are not nested inside `base` in styled calls",category:"Errors",recommended:!0},messages:{nestedVariants:"`variants` should not be nested inside `base`."}},create(e){return O(e.filename)?{CallExpression:a=>{try{const{callee:s,arguments:p}=a;if(!(s.type==="Identifier"&&s.name==="styled"))return;const o=p[1];if(!o||!(o.type==="ObjectExpression"))return;const c=o.properties.find(t=>t.type==="Property"&&t.key.type==="Identifier"&&t.key.name==="base");if(!c)return;const{value:l}=c;if(!(l.type==="ObjectExpression"))return;const r=l.properties.find(t=>t.type==="Property"&&t.key.type==="Identifier"&&t.key.name==="variants");if(!r)return;e.report({node:r,messageId:"nestedVariants",fix:t=>{if(!r.range)return null;const{sourceCode:f}=e,m=f.getText(r),g=o.properties.indexOf(c),u=o.properties[g];if(!u.range)return null;const b=[u.range[1],u.range[1]],d=[r.range[0]-1,r.range[1]];if(l.properties.at(-1)===r){const y=f.text.slice(r.range[1]).match(/^\s*,/);y&&(d[1]+=y[0].length)}return[t.removeRange(d),t.insertTextAfterRange(b,`, ${m}`)]}})}catch(s){console.log("ESlint error",s);return}}}:{}}},j={rules:{"no-variants-in-base":h}};module.exports=j;
|
package/index.js
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
import "esbuild";
|
2
|
-
import * as
|
2
|
+
import * as n from "winston";
|
3
3
|
import "child_process";
|
4
4
|
import "path";
|
5
5
|
import "fs";
|
6
6
|
import "fs/promises";
|
7
|
-
|
7
|
+
n.createLogger({
|
8
8
|
level: "info",
|
9
|
-
format:
|
10
|
-
transports: [new
|
9
|
+
format: n.format.combine(n.format.colorize(), n.format.cli()),
|
10
|
+
transports: [new n.transports.Console({})]
|
11
11
|
});
|
12
|
-
const
|
12
|
+
const x = ["salty", "css", "styles", "styled"], v = (s = []) => new RegExp(`\\.(${[...x, ...s].join("|")})\\.`), P = (s, c = []) => v(c).test(s), E = {
|
13
13
|
meta: {
|
14
14
|
type: "problem",
|
15
|
+
fixable: "code",
|
15
16
|
docs: {
|
16
17
|
description: "Ensure `variants` are not nested inside `base` in styled calls",
|
17
18
|
category: "Errors",
|
@@ -21,38 +22,53 @@ const d = ["salty", "css", "styles", "styled"], m = (t = []) => new RegExp(`\\.(
|
|
21
22
|
nestedVariants: "`variants` should not be nested inside `base`."
|
22
23
|
}
|
23
24
|
},
|
24
|
-
create(
|
25
|
-
return
|
26
|
-
CallExpression: (
|
25
|
+
create(s) {
|
26
|
+
return P(s.filename) ? {
|
27
|
+
CallExpression: (y) => {
|
27
28
|
try {
|
28
|
-
const { callee:
|
29
|
-
if (!(
|
30
|
-
const
|
31
|
-
if (!
|
32
|
-
const
|
33
|
-
if (!
|
34
|
-
const { value:
|
35
|
-
if (!(
|
36
|
-
const
|
29
|
+
const { callee: a, arguments: f } = y;
|
30
|
+
if (!(a.type === "Identifier" && a.name === "styled")) return;
|
31
|
+
const r = f[1];
|
32
|
+
if (!r || !(r.type === "ObjectExpression")) return;
|
33
|
+
const o = r.properties.find((e) => e.type === "Property" && e.key.type === "Identifier" && e.key.name === "base");
|
34
|
+
if (!o) return;
|
35
|
+
const { value: i } = o;
|
36
|
+
if (!(i.type === "ObjectExpression")) return;
|
37
|
+
const t = i.properties.find(
|
37
38
|
(e) => e.type === "Property" && e.key.type === "Identifier" && e.key.name === "variants"
|
38
39
|
);
|
39
|
-
if (!
|
40
|
-
|
41
|
-
node:
|
42
|
-
messageId: "nestedVariants"
|
40
|
+
if (!t) return;
|
41
|
+
s.report({
|
42
|
+
node: t,
|
43
|
+
messageId: "nestedVariants",
|
44
|
+
fix: (e) => {
|
45
|
+
if (!t.range) return null;
|
46
|
+
const { sourceCode: m } = s, g = m.getText(t), u = r.properties.indexOf(o), l = r.properties[u];
|
47
|
+
if (!l.range) return null;
|
48
|
+
const b = [l.range[1], l.range[1]], p = [
|
49
|
+
t.range[0] - 1,
|
50
|
+
// Include the preceding comma (if any)
|
51
|
+
t.range[1]
|
52
|
+
];
|
53
|
+
if (i.properties.at(-1) === t) {
|
54
|
+
const d = m.text.slice(t.range[1]).match(/^\s*,/);
|
55
|
+
d && (p[1] += d[0].length);
|
56
|
+
}
|
57
|
+
return [e.removeRange(p), e.insertTextAfterRange(b, `, ${g}`)];
|
58
|
+
}
|
43
59
|
});
|
44
|
-
} catch (
|
45
|
-
console.log("ESlint error",
|
60
|
+
} catch (a) {
|
61
|
+
console.log("ESlint error", a);
|
46
62
|
return;
|
47
63
|
}
|
48
64
|
}
|
49
65
|
} : {};
|
50
66
|
}
|
51
|
-
},
|
67
|
+
}, T = {
|
52
68
|
rules: {
|
53
|
-
"no-variants-in-base":
|
69
|
+
"no-variants-in-base": E
|
54
70
|
}
|
55
71
|
};
|
56
72
|
export {
|
57
|
-
|
73
|
+
T as default
|
58
74
|
};
|