@salty-css/eslint-plugin-core 0.0.1-alpha.14 → 0.0.1-alpha.15
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +1 -1
- package/index.cjs +1 -1
- package/index.js +19 -25
- package/package.json +1 -1
package/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
### Initial requirements
|
6
6
|
|
7
7
|
1. Add `saltyPlugin` to vite or webpack config from `@salty-css/vite` or `@salty-css/webpack`
|
8
|
-
2. Create `salty
|
8
|
+
2. Create `salty.config.ts` to the root of your project
|
9
9
|
3. Import global styles to any regular .css file from `saltygen/index.css` (does not exist during first run, cli command coming later)
|
10
10
|
4. Create salty components with styled only inside files that end with `.css.ts`, `.salty.ts` `.styled.ts` or `.styles.ts`
|
11
11
|
|
package/index.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";require("esbuild");
|
1
|
+
"use strict";require("esbuild");require("child_process");require("path");require("fs");require("fs/promises");const x=["salty","css","styles","styled"],b=(s=[])=>new RegExp(`\\.(${[...x,...s].join("|")})\\.`),P=(s,c=[])=>b(c).test(s),v={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(s){return P(s.filename)?{CallExpression:u=>{try{const{callee:n,arguments:p}=u;if(!(n.type==="Identifier"&&n.name==="styled"))return;const r=p[1];if(!r||!(r.type==="ObjectExpression"))return;const a=r.properties.find(e=>e.type==="Property"&&e.key.type==="Identifier"&&e.key.name==="base");if(!a)return;const{value:i}=a;if(!(i.type==="ObjectExpression"))return;const t=i.properties.find(e=>e.type==="Property"&&e.key.type==="Identifier"&&e.key.name==="variants");if(!t)return;s.report({node:t,messageId:"nestedVariants",fix:e=>{if(!t.range)return null;const{sourceCode:l}=s,f=l.getText(t),g=r.properties.indexOf(a),o=r.properties[g];if(!o.range)return null;const m=[o.range[1],o.range[1]],y=[t.range[0]-1,t.range[1]];if(i.properties.at(-1)===t){const d=l.text.slice(t.range[1]).match(/^\s*,/);d&&(y[1]+=d[0].length)}return[e.removeRange(y),e.insertTextAfterRange(m,`, ${f}`)]}})}catch(n){console.log("ESlint error",n);return}}}:{}}},E={rules:{"no-variants-in-base":v}};module.exports=E;
|
package/index.js
CHANGED
@@ -1,15 +1,9 @@
|
|
1
1
|
import "esbuild";
|
2
|
-
import * as n from "winston";
|
3
2
|
import "child_process";
|
4
3
|
import "path";
|
5
4
|
import "fs";
|
6
5
|
import "fs/promises";
|
7
|
-
|
8
|
-
level: "info",
|
9
|
-
format: n.format.combine(n.format.colorize(), n.format.cli()),
|
10
|
-
transports: [new n.transports.Console({})]
|
11
|
-
});
|
12
|
-
const x = ["salty", "css", "styles", "styled"], v = (s = []) => new RegExp(`\\.(${[...x, ...s].join("|")})\\.`), P = (s, c = []) => v(c).test(s), E = {
|
6
|
+
const x = ["salty", "css", "styles", "styled"], b = (s = []) => new RegExp(`\\.(${[...x, ...s].join("|")})\\.`), P = (s, l = []) => b(l).test(s), v = {
|
13
7
|
meta: {
|
14
8
|
type: "problem",
|
15
9
|
fixable: "code",
|
@@ -24,15 +18,15 @@ const x = ["salty", "css", "styles", "styled"], v = (s = []) => new RegExp(`\\.(
|
|
24
18
|
},
|
25
19
|
create(s) {
|
26
20
|
return P(s.filename) ? {
|
27
|
-
CallExpression: (
|
21
|
+
CallExpression: (p) => {
|
28
22
|
try {
|
29
|
-
const { callee:
|
30
|
-
if (!(
|
31
|
-
const r =
|
23
|
+
const { callee: n, arguments: m } = p;
|
24
|
+
if (!(n.type === "Identifier" && n.name === "styled")) return;
|
25
|
+
const r = m[1];
|
32
26
|
if (!r || !(r.type === "ObjectExpression")) return;
|
33
|
-
const
|
34
|
-
if (!
|
35
|
-
const { value: i } =
|
27
|
+
const a = r.properties.find((e) => e.type === "Property" && e.key.type === "Identifier" && e.key.name === "base");
|
28
|
+
if (!a) return;
|
29
|
+
const { value: i } = a;
|
36
30
|
if (!(i.type === "ObjectExpression")) return;
|
37
31
|
const t = i.properties.find(
|
38
32
|
(e) => e.type === "Property" && e.key.type === "Identifier" && e.key.name === "variants"
|
@@ -43,32 +37,32 @@ const x = ["salty", "css", "styles", "styled"], v = (s = []) => new RegExp(`\\.(
|
|
43
37
|
messageId: "nestedVariants",
|
44
38
|
fix: (e) => {
|
45
39
|
if (!t.range) return null;
|
46
|
-
const { sourceCode:
|
47
|
-
if (!
|
48
|
-
const
|
40
|
+
const { sourceCode: c } = s, f = c.getText(t), u = r.properties.indexOf(a), o = r.properties[u];
|
41
|
+
if (!o.range) return null;
|
42
|
+
const g = [o.range[1], o.range[1]], d = [
|
49
43
|
t.range[0] - 1,
|
50
44
|
// Include the preceding comma (if any)
|
51
45
|
t.range[1]
|
52
46
|
];
|
53
47
|
if (i.properties.at(-1) === t) {
|
54
|
-
const
|
55
|
-
|
48
|
+
const y = c.text.slice(t.range[1]).match(/^\s*,/);
|
49
|
+
y && (d[1] += y[0].length);
|
56
50
|
}
|
57
|
-
return [e.removeRange(
|
51
|
+
return [e.removeRange(d), e.insertTextAfterRange(g, `, ${f}`)];
|
58
52
|
}
|
59
53
|
});
|
60
|
-
} catch (
|
61
|
-
console.log("ESlint error",
|
54
|
+
} catch (n) {
|
55
|
+
console.log("ESlint error", n);
|
62
56
|
return;
|
63
57
|
}
|
64
58
|
}
|
65
59
|
} : {};
|
66
60
|
}
|
67
|
-
},
|
61
|
+
}, j = {
|
68
62
|
rules: {
|
69
|
-
"no-variants-in-base":
|
63
|
+
"no-variants-in-base": v
|
70
64
|
}
|
71
65
|
};
|
72
66
|
export {
|
73
|
-
|
67
|
+
j as default
|
74
68
|
};
|