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