@salty-css/eslint-plugin-core 0.0.1-alpha.80 → 0.0.1-alpha.82
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.d.ts +1 -1
- package/index.js +75 -52
- package/package.json +2 -2
- package/rules/must-be-exported.d.ts +2 -0
package/index.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";require("esbuild");require("child_process");require("path");require("fs");require("fs/promises");const
|
1
|
+
"use strict";require("esbuild");require("child_process");require("path");require("fs");require("fs/promises");const v=["salty","css","styles","styled"],h=(r=[])=>new RegExp(`\\.(${[...v,...r].join("|")})\\.`),g=(r,o=[])=>h(o).test(r),P={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(r){return g(r.filename)?{CallExpression:l=>{try{const{callee:i,arguments:e}=l;if(!(i.type==="Identifier"&&i.name==="styled"))return;const t=e[1];if(!t||!(t.type==="ObjectExpression"))return;const c=t.properties.find(s=>s.type==="Property"&&s.key.type==="Identifier"&&s.key.name==="base");if(!c)return;const{value:u}=c;if(!(u.type==="ObjectExpression"))return;const n=u.properties.find(s=>s.type==="Property"&&s.key.type==="Identifier"&&s.key.name==="variants");if(!n)return;r.report({node:n,messageId:"nestedVariants",fix:s=>{if(!n.range)return null;const{sourceCode:d}=r,x=d.getText(n),b=t.properties.indexOf(c),y=t.properties[b];if(!y.range)return null;const E=[y.range[1],y.range[1]],f=[n.range[0]-1,n.range[1]];if(u.properties.at(-1)===n){const m=d.text.slice(n.range[1]).match(/^\s*,/);m&&(f[1]+=m[0].length)}return[s.removeRange(f),s.insertTextAfterRange(E,`, ${x}`)]}})}catch(i){console.log("ESlint error",i);return}}}:{}}},S={meta:{type:"problem",fixable:"code",docs:{description:"Salty CSS related function calls or other values must be exported",category:"Errors",recommended:!0},messages:{mustBeExported:"Salty CSS related function calls or other values must be exported"}},create(r){if(!g(r.filename))return{};function l(e){if(e.type==="VariableDeclaration"){const a=e.declarations[0];if(a.type!=="VariableDeclarator")return;const t=a.init;if((t==null?void 0:t.type)!=="CallExpression")return;const p=["styled","keyframes"];if(t.callee.type==="Identifier"&&p.includes(t.callee.name))return!0}return!1}function i(e){const a=e.parent;return a.type==="ExportNamedDeclaration"||a.type==="ExportDefaultDeclaration"}return{VariableDeclaration:e=>{l(e)&&(i(e)||r.report({node:e,messageId:"mustBeExported",fix:a=>a.insertTextBefore(e,"export ")}))}}}},I={rules:{"no-variants-in-base":P,"must-be-exported":S}};module.exports=I;
|
package/index.d.ts
CHANGED
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
|
6
|
+
const v = ["salty", "css", "styles", "styled"], h = (r = []) => new RegExp(`\\.(${[...v, ...r].join("|")})\\.`), g = (r, o = []) => h(o).test(r), P = {
|
7
7
|
meta: {
|
8
8
|
type: "problem",
|
9
9
|
fixable: "code",
|
@@ -16,72 +16,95 @@ const x = ["salty", "css", "styles", "styled"], v = (t = []) => new RegExp(`\\.(
|
|
16
16
|
nestedVariants: "`variants` should not be nested inside `base`."
|
17
17
|
}
|
18
18
|
},
|
19
|
-
create(
|
20
|
-
return
|
21
|
-
CallExpression: (
|
19
|
+
create(r) {
|
20
|
+
return g(r.filename) ? {
|
21
|
+
CallExpression: (l) => {
|
22
22
|
try {
|
23
|
-
const { callee:
|
24
|
-
if (!(
|
25
|
-
const
|
26
|
-
if (!
|
27
|
-
const
|
28
|
-
if (!
|
29
|
-
const { value:
|
30
|
-
if (!(
|
31
|
-
const
|
32
|
-
(
|
23
|
+
const { callee: i, arguments: e } = l;
|
24
|
+
if (!(i.type === "Identifier" && i.name === "styled")) return;
|
25
|
+
const t = e[1];
|
26
|
+
if (!t || !(t.type === "ObjectExpression")) return;
|
27
|
+
const c = t.properties.find((s) => s.type === "Property" && s.key.type === "Identifier" && s.key.name === "base");
|
28
|
+
if (!c) return;
|
29
|
+
const { value: u } = c;
|
30
|
+
if (!(u.type === "ObjectExpression")) return;
|
31
|
+
const n = u.properties.find(
|
32
|
+
(s) => s.type === "Property" && s.key.type === "Identifier" && s.key.name === "variants"
|
33
33
|
);
|
34
|
-
if (!
|
35
|
-
|
36
|
-
node:
|
34
|
+
if (!n) return;
|
35
|
+
r.report({
|
36
|
+
node: n,
|
37
37
|
messageId: "nestedVariants",
|
38
|
-
fix: (
|
39
|
-
if (!
|
40
|
-
const { sourceCode:
|
41
|
-
if (!
|
42
|
-
const
|
43
|
-
|
38
|
+
fix: (s) => {
|
39
|
+
if (!n.range) return null;
|
40
|
+
const { sourceCode: d } = r, x = d.getText(n), b = t.properties.indexOf(c), p = t.properties[b];
|
41
|
+
if (!p.range) return null;
|
42
|
+
const E = [p.range[1], p.range[1]], f = [
|
43
|
+
n.range[0] - 1,
|
44
44
|
// Include the preceding comma (if any)
|
45
|
-
|
45
|
+
n.range[1]
|
46
46
|
];
|
47
|
-
if (
|
48
|
-
const
|
49
|
-
|
47
|
+
if (u.properties.at(-1) === n) {
|
48
|
+
const m = d.text.slice(n.range[1]).match(/^\s*,/);
|
49
|
+
m && (f[1] += m[0].length);
|
50
50
|
}
|
51
|
-
return [
|
51
|
+
return [s.removeRange(f), s.insertTextAfterRange(E, `, ${x}`)];
|
52
52
|
}
|
53
53
|
});
|
54
|
-
} catch (
|
55
|
-
console.log("ESlint error",
|
54
|
+
} catch (i) {
|
55
|
+
console.log("ESlint error", i);
|
56
56
|
return;
|
57
57
|
}
|
58
58
|
}
|
59
59
|
} : {};
|
60
60
|
}
|
61
|
-
},
|
62
|
-
|
63
|
-
|
64
|
-
"
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
plugins: {
|
70
|
-
core: p
|
71
|
-
},
|
72
|
-
rules: {
|
73
|
-
"core/no-variants-in-base": "error"
|
61
|
+
}, S = {
|
62
|
+
meta: {
|
63
|
+
type: "problem",
|
64
|
+
fixable: "code",
|
65
|
+
docs: {
|
66
|
+
description: "Salty CSS related function calls or other values must be exported",
|
67
|
+
category: "Errors",
|
68
|
+
recommended: !0
|
74
69
|
},
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
70
|
+
messages: {
|
71
|
+
mustBeExported: "Salty CSS related function calls or other values must be exported"
|
72
|
+
}
|
73
|
+
},
|
74
|
+
create(r) {
|
75
|
+
if (!g(r.filename)) return {};
|
76
|
+
function l(e) {
|
77
|
+
if (e.type === "VariableDeclaration") {
|
78
|
+
const a = e.declarations[0];
|
79
|
+
if (a.type !== "VariableDeclarator") return;
|
80
|
+
const t = a.init;
|
81
|
+
if ((t == null ? void 0 : t.type) !== "CallExpression") return;
|
82
|
+
const y = ["styled", "keyframes"];
|
83
|
+
if (t.callee.type === "Identifier" && y.includes(t.callee.name))
|
84
|
+
return !0;
|
85
|
+
}
|
86
|
+
return !1;
|
87
|
+
}
|
88
|
+
function i(e) {
|
89
|
+
const a = e.parent;
|
90
|
+
return a.type === "ExportNamedDeclaration" || a.type === "ExportDefaultDeclaration";
|
91
|
+
}
|
92
|
+
return {
|
93
|
+
VariableDeclaration: (e) => {
|
94
|
+
l(e) && (i(e) || r.report({
|
95
|
+
node: e,
|
96
|
+
messageId: "mustBeExported",
|
97
|
+
fix: (a) => a.insertTextBefore(e, "export ")
|
98
|
+
}));
|
81
99
|
}
|
82
|
-
|
100
|
+
};
|
83
101
|
}
|
84
|
-
}
|
102
|
+
}, R = {
|
103
|
+
rules: {
|
104
|
+
"no-variants-in-base": P,
|
105
|
+
"must-be-exported": S
|
106
|
+
}
|
107
|
+
};
|
85
108
|
export {
|
86
|
-
|
109
|
+
R as default
|
87
110
|
};
|
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.82",
|
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.82",
|
38
38
|
"eslint": ">=9.x || >=8.x || >=7.x"
|
39
39
|
}
|
40
40
|
}
|