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