@salty-css/eslint-config-core 0.0.1-alpha.152 → 0.0.1-alpha.153
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/flat.cjs +1 -1
- package/flat.js +40 -37
- package/package.json +3 -3
package/flat.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 l=require("winston");l.createLogger({level:"debug",format:l.format.combine(l.format.colorize(),l.format.cli()),transports:[new l.transports.Console({})]});const h=["salty","css","styles","styled"],C=(r=[])=>new RegExp(`\\.(${[...h,...r].join("|")})\\.`),x=(r,c=[])=>C(c).test(r),I={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 x(r.filename)?{CallExpression:u=>{try{const{callee:i,arguments:t}=u;if(!(i.type==="Identifier"&&i.name==="styled"))return;const e=t[1];if(!e||!(e.type==="ObjectExpression"))return;const o=e.properties.find(s=>s.type==="Property"&&s.key.type==="Identifier"&&s.key.name==="base");if(!o)return;const{value:f}=o;if(!(f.type==="ObjectExpression"))return;const a=f.properties.find(s=>s.type==="Property"&&s.key.type==="Identifier"&&s.key.name==="variants");if(!a)return;r.report({node:a,messageId:"nestedVariants",fix:s=>{if(!a.range)return null;const{sourceCode:y}=r,b=y.getText(a),E=e.properties.indexOf(o),d=e.properties[E];if(!d.range)return null;const v=[d.range[1],d.range[1]],m=[a.range[0]-1,a.range[1]];if(f.properties.at(-1)===a){const g=y.text.slice(a.range[1]).match(/^\s*,/);g&&(m[1]+=g[0].length)}return[s.removeRange(m),s.insertTextAfterRange(v,`, ${b}`)]}})}catch(i){console.log("ESlint error",i);return}}}:{}}},P={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(!x(r.filename))return{};function u(t){if(t.type==="VariableDeclaration"){const n=t.declarations[0];if(n.type!=="VariableDeclarator")return;const e=n.init;if((e==null?void 0:e.type)!=="CallExpression")return;const p=["styled","keyframes"];if(e.callee.type==="Identifier"&&p.includes(e.callee.name))return!0;const o=/^define[A-Z]/;if(e.callee.type==="Identifier"&&o.test(e.callee.name))return!0}return!1}function i(t){const n=t.parent;return n.type==="ExportNamedDeclaration"||n.type==="ExportDefaultDeclaration"}return{VariableDeclaration:t=>{u(t)&&(i(t)||r.report({node:t,messageId:"mustBeExported",fix:n=>n.insertTextBefore(t,"export ")}))}}}},S={rules:{"no-variants-in-base":I,"must-be-exported":P}},F={files:["**/*.ts","**/*.tsx"],plugins:{"@salty-css/core":S},rules:{"@salty-css/core/no-variants-in-base":"error","@salty-css/core/must-be-exported":"error"}};module.exports=F;
|
package/flat.js
CHANGED
|
@@ -9,7 +9,7 @@ h({
|
|
|
9
9
|
format: f.combine(f.colorize(), f.cli()),
|
|
10
10
|
transports: [new C.Console({})]
|
|
11
11
|
});
|
|
12
|
-
const
|
|
12
|
+
const I = ["salty", "css", "styles", "styled"], P = (r = []) => new RegExp(`\\.(${[...I, ...r].join("|")})\\.`), x = (r, l = []) => P(l).test(r), S = {
|
|
13
13
|
meta: {
|
|
14
14
|
type: "problem",
|
|
15
15
|
fixable: "code",
|
|
@@ -24,34 +24,34 @@ const P = ["salty", "css", "styles", "styled"], S = (r = []) => new RegExp(`\\.(
|
|
|
24
24
|
},
|
|
25
25
|
create(r) {
|
|
26
26
|
return x(r.filename) ? {
|
|
27
|
-
CallExpression: (
|
|
27
|
+
CallExpression: (c) => {
|
|
28
28
|
try {
|
|
29
|
-
const { callee: o, arguments:
|
|
29
|
+
const { callee: o, arguments: t } = c;
|
|
30
30
|
if (!(o.type === "Identifier" && o.name === "styled")) return;
|
|
31
|
-
const
|
|
32
|
-
if (!
|
|
33
|
-
const
|
|
34
|
-
if (!
|
|
35
|
-
const { value: u } =
|
|
31
|
+
const e = t[1];
|
|
32
|
+
if (!e || !(e.type === "ObjectExpression")) return;
|
|
33
|
+
const i = e.properties.find((s) => s.type === "Property" && s.key.type === "Identifier" && s.key.name === "base");
|
|
34
|
+
if (!i) return;
|
|
35
|
+
const { value: u } = i;
|
|
36
36
|
if (!(u.type === "ObjectExpression")) return;
|
|
37
|
-
const
|
|
37
|
+
const a = u.properties.find(
|
|
38
38
|
(s) => s.type === "Property" && s.key.type === "Identifier" && s.key.name === "variants"
|
|
39
39
|
);
|
|
40
|
-
if (!
|
|
40
|
+
if (!a) return;
|
|
41
41
|
r.report({
|
|
42
|
-
node:
|
|
42
|
+
node: a,
|
|
43
43
|
messageId: "nestedVariants",
|
|
44
44
|
fix: (s) => {
|
|
45
|
-
if (!
|
|
46
|
-
const { sourceCode:
|
|
45
|
+
if (!a.range) return null;
|
|
46
|
+
const { sourceCode: y } = r, b = y.getText(a), E = e.properties.indexOf(i), p = e.properties[E];
|
|
47
47
|
if (!p.range) return null;
|
|
48
48
|
const v = [p.range[1], p.range[1]], m = [
|
|
49
|
-
|
|
49
|
+
a.range[0] - 1,
|
|
50
50
|
// Include the preceding comma (if any)
|
|
51
|
-
|
|
51
|
+
a.range[1]
|
|
52
52
|
];
|
|
53
|
-
if (u.properties.at(-1) ===
|
|
54
|
-
const g =
|
|
53
|
+
if (u.properties.at(-1) === a) {
|
|
54
|
+
const g = y.text.slice(a.range[1]).match(/^\s*,/);
|
|
55
55
|
g && (m[1] += g[0].length);
|
|
56
56
|
}
|
|
57
57
|
return [s.removeRange(m), s.insertTextAfterRange(v, `, ${b}`)];
|
|
@@ -64,7 +64,7 @@ const P = ["salty", "css", "styles", "styled"], S = (r = []) => new RegExp(`\\.(
|
|
|
64
64
|
}
|
|
65
65
|
} : {};
|
|
66
66
|
}
|
|
67
|
-
},
|
|
67
|
+
}, F = {
|
|
68
68
|
meta: {
|
|
69
69
|
type: "problem",
|
|
70
70
|
fixable: "code",
|
|
@@ -79,41 +79,44 @@ const P = ["salty", "css", "styles", "styled"], S = (r = []) => new RegExp(`\\.(
|
|
|
79
79
|
},
|
|
80
80
|
create(r) {
|
|
81
81
|
if (!x(r.filename)) return {};
|
|
82
|
-
function
|
|
83
|
-
if (
|
|
84
|
-
const
|
|
85
|
-
if (
|
|
86
|
-
const
|
|
87
|
-
if ((
|
|
88
|
-
const
|
|
89
|
-
if (
|
|
82
|
+
function c(t) {
|
|
83
|
+
if (t.type === "VariableDeclaration") {
|
|
84
|
+
const n = t.declarations[0];
|
|
85
|
+
if (n.type !== "VariableDeclarator") return;
|
|
86
|
+
const e = n.init;
|
|
87
|
+
if ((e == null ? void 0 : e.type) !== "CallExpression") return;
|
|
88
|
+
const d = ["styled", "keyframes"];
|
|
89
|
+
if (e.callee.type === "Identifier" && d.includes(e.callee.name))
|
|
90
|
+
return !0;
|
|
91
|
+
const i = /^define[A-Z]/;
|
|
92
|
+
if (e.callee.type === "Identifier" && i.test(e.callee.name))
|
|
90
93
|
return !0;
|
|
91
94
|
}
|
|
92
95
|
return !1;
|
|
93
96
|
}
|
|
94
|
-
function o(
|
|
95
|
-
const
|
|
96
|
-
return
|
|
97
|
+
function o(t) {
|
|
98
|
+
const n = t.parent;
|
|
99
|
+
return n.type === "ExportNamedDeclaration" || n.type === "ExportDefaultDeclaration";
|
|
97
100
|
}
|
|
98
101
|
return {
|
|
99
|
-
VariableDeclaration: (
|
|
100
|
-
|
|
101
|
-
node:
|
|
102
|
+
VariableDeclaration: (t) => {
|
|
103
|
+
c(t) && (o(t) || r.report({
|
|
104
|
+
node: t,
|
|
102
105
|
messageId: "mustBeExported",
|
|
103
|
-
fix: (
|
|
106
|
+
fix: (n) => n.insertTextBefore(t, "export ")
|
|
104
107
|
}));
|
|
105
108
|
}
|
|
106
109
|
};
|
|
107
110
|
}
|
|
108
|
-
},
|
|
111
|
+
}, V = {
|
|
109
112
|
rules: {
|
|
110
|
-
"no-variants-in-base":
|
|
111
|
-
"must-be-exported":
|
|
113
|
+
"no-variants-in-base": S,
|
|
114
|
+
"must-be-exported": F
|
|
112
115
|
}
|
|
113
116
|
}, O = {
|
|
114
117
|
files: ["**/*.ts", "**/*.tsx"],
|
|
115
118
|
plugins: {
|
|
116
|
-
"@salty-css/core":
|
|
119
|
+
"@salty-css/core": V
|
|
117
120
|
},
|
|
118
121
|
rules: {
|
|
119
122
|
"@salty-css/core/no-variants-in-base": "error",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salty-css/eslint-config-core",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.153",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"typings": "./dist/index.d.ts",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@salty-css/core": "^0.0.1-alpha.
|
|
42
|
-
"@salty-css/eslint-plugin-core": "^0.0.1-alpha.
|
|
41
|
+
"@salty-css/core": "^0.0.1-alpha.153",
|
|
42
|
+
"@salty-css/eslint-plugin-core": "^0.0.1-alpha.153",
|
|
43
43
|
"eslint": ">=9.x || >=8.x || >=7.x"
|
|
44
44
|
}
|
|
45
45
|
}
|