@salty-css/eslint-plugin-core 0.0.1-alpha.76 → 0.0.1-alpha.78
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/index.cjs +1 -1
- package/index.js +25 -17
- package/package.json +2 -2
package/index.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";require("esbuild");require("child_process");require("path");require("fs");require("fs/promises");const x=["salty","css","styles","styled"],
|
1
|
+
"use strict";require("esbuild");require("child_process");require("path");require("fs");require("fs/promises");const x=["salty","css","styles","styled"],v=(t=[])=>new RegExp(`\\.(${[...x,...t].join("|")})\\.`),P=(t,l=[])=>v(l).test(t),E={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(t){return P(t.filename)?{CallExpression:g=>{try{const{callee:n,arguments:f}=g;if(!(n.type==="Identifier"&&n.name==="styled"))return;const r=f[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 s=i.properties.find(e=>e.type==="Property"&&e.key.type==="Identifier"&&e.key.name==="variants");if(!s)return;t.report({node:s,messageId:"nestedVariants",fix:e=>{if(!s.range)return null;const{sourceCode:d}=t,p=d.getText(s),m=r.properties.indexOf(a),o=r.properties[m];if(!o.range)return null;const b=[o.range[1],o.range[1]],y=[s.range[0]-1,s.range[1]];if(i.properties.at(-1)===s){const u=d.text.slice(s.range[1]).match(/^\s*,/);u&&(y[1]+=u[0].length)}return[e.removeRange(y),e.insertTextAfterRange(b,`, ${p}`)]}})}catch(n){console.log("ESlint error",n);return}}}:{}}},c={configs:{},rules:{"no-variants-in-base":E}};Object.assign(c.configs,{recommended:{plugins:{core:c},rules:{"core/no-variants-in-base":"error"},overrides:[{files:["*.css.ts","*.css.tsx"],rules:{"@salty-css/core/no-variants-in-base":["warn"]}}]}});module.exports=c;
|
package/index.js
CHANGED
@@ -3,7 +3,7 @@ import "child_process";
|
|
3
3
|
import "path";
|
4
4
|
import "fs";
|
5
5
|
import "fs/promises";
|
6
|
-
const x = ["salty", "css", "styles", "styled"],
|
6
|
+
const x = ["salty", "css", "styles", "styled"], v = (t = []) => new RegExp(`\\.(${[...x, ...t].join("|")})\\.`), P = (t, c = []) => v(c).test(t), E = {
|
7
7
|
meta: {
|
8
8
|
type: "problem",
|
9
9
|
fixable: "code",
|
@@ -16,39 +16,39 @@ const x = ["salty", "css", "styles", "styled"], P = (s = []) => new RegExp(`\\.(
|
|
16
16
|
nestedVariants: "`variants` should not be nested inside `base`."
|
17
17
|
}
|
18
18
|
},
|
19
|
-
create(
|
20
|
-
return
|
19
|
+
create(t) {
|
20
|
+
return P(t.filename) ? {
|
21
21
|
CallExpression: (m) => {
|
22
22
|
try {
|
23
|
-
const { callee: n, arguments:
|
23
|
+
const { callee: n, arguments: f } = m;
|
24
24
|
if (!(n.type === "Identifier" && n.name === "styled")) return;
|
25
|
-
const r =
|
25
|
+
const r = f[1];
|
26
26
|
if (!r || !(r.type === "ObjectExpression")) return;
|
27
27
|
const a = r.properties.find((e) => e.type === "Property" && e.key.type === "Identifier" && e.key.name === "base");
|
28
28
|
if (!a) return;
|
29
29
|
const { value: i } = a;
|
30
30
|
if (!(i.type === "ObjectExpression")) return;
|
31
|
-
const
|
31
|
+
const s = i.properties.find(
|
32
32
|
(e) => e.type === "Property" && e.key.type === "Identifier" && e.key.name === "variants"
|
33
33
|
);
|
34
|
-
if (!
|
35
|
-
|
36
|
-
node:
|
34
|
+
if (!s) return;
|
35
|
+
t.report({
|
36
|
+
node: s,
|
37
37
|
messageId: "nestedVariants",
|
38
38
|
fix: (e) => {
|
39
|
-
if (!
|
40
|
-
const { sourceCode: l } =
|
39
|
+
if (!s.range) return null;
|
40
|
+
const { sourceCode: l } = t, g = l.getText(s), u = r.properties.indexOf(a), o = r.properties[u];
|
41
41
|
if (!o.range) return null;
|
42
42
|
const b = [o.range[1], o.range[1]], d = [
|
43
|
-
|
43
|
+
s.range[0] - 1,
|
44
44
|
// Include the preceding comma (if any)
|
45
|
-
|
45
|
+
s.range[1]
|
46
46
|
];
|
47
|
-
if (i.properties.at(-1) ===
|
48
|
-
const y = l.text.slice(
|
47
|
+
if (i.properties.at(-1) === s) {
|
48
|
+
const y = l.text.slice(s.range[1]).match(/^\s*,/);
|
49
49
|
y && (d[1] += y[0].length);
|
50
50
|
}
|
51
|
-
return [e.removeRange(d), e.insertTextAfterRange(b, `, ${
|
51
|
+
return [e.removeRange(d), e.insertTextAfterRange(b, `, ${g}`)];
|
52
52
|
}
|
53
53
|
});
|
54
54
|
} catch (n) {
|
@@ -71,7 +71,15 @@ Object.assign(p.configs, {
|
|
71
71
|
},
|
72
72
|
rules: {
|
73
73
|
"core/no-variants-in-base": "error"
|
74
|
-
}
|
74
|
+
},
|
75
|
+
overrides: [
|
76
|
+
{
|
77
|
+
files: ["*.css.ts", "*.css.tsx"],
|
78
|
+
rules: {
|
79
|
+
"@salty-css/core/no-variants-in-base": ["warn"]
|
80
|
+
}
|
81
|
+
}
|
82
|
+
]
|
75
83
|
}
|
76
84
|
});
|
77
85
|
export {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@salty-css/eslint-plugin-core",
|
3
|
-
"version": "0.0.1-alpha.
|
3
|
+
"version": "0.0.1-alpha.78",
|
4
4
|
"main": "./dist/index.js",
|
5
5
|
"module": "./dist/index.mjs",
|
6
6
|
"typings": "./dist/index.d.ts",
|
@@ -34,7 +34,7 @@
|
|
34
34
|
}
|
35
35
|
},
|
36
36
|
"dependencies": {
|
37
|
-
"@salty-css/core": "^0.0.1-alpha.
|
37
|
+
"@salty-css/core": "^0.0.1-alpha.78",
|
38
38
|
"eslint": ">=9.x || >=8.x || >=7.x"
|
39
39
|
}
|
40
40
|
}
|