@salty-css/eslint-config-core 0.0.1-alpha.81 → 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.
Files changed (4) hide show
  1. package/index.cjs +1 -1
  2. package/index.d.ts +11 -8
  3. package/index.js +113 -11
  4. package/package.json +3 -3
package/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";const s={plugins:["@salty-css/core"],rules:{"core/no-variants-in-base":"error"},overrides:[{files:["*.css.ts","*.css.tsx"],rules:{"@salty-css/core/no-variants-in-base":["error"]}}]};module.exports=s;
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:f}=r,x=f.getText(n),b=t.properties.indexOf(c),y=t.properties[b];if(!y.range)return null;const E=[y.range[1],y.range[1]],d=[n.range[0]-1,n.range[1]];if(u.properties.at(-1)===n){const m=f.text.slice(n.range[1]).match(/^\s*,/);m&&(d[1]+=m[0].length)}return[s.removeRange(d),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 ")}))}}}},C={rules:{"no-variants-in-base":P,"must-be-exported":S}},I={files:["**/*.ts","**/*.tsx"],plugins:{"@salty-css/core":C},rules:{"@salty-css/core/no-variants-in-base":"error","@salty-css/core/must-be-exported":"error"}};module.exports=I;
package/index.d.ts CHANGED
@@ -1,13 +1,16 @@
1
1
  declare const eslintConfigCore: {
2
- plugins: string[];
2
+ files: string[];
3
+ plugins: {
4
+ '@salty-css/core': {
5
+ rules: {
6
+ 'no-variants-in-base': import("eslint").Rule.RuleModule;
7
+ 'must-be-exported': import("eslint").Rule.RuleModule;
8
+ };
9
+ };
10
+ };
3
11
  rules: {
4
- 'core/no-variants-in-base': "error";
12
+ '@salty-css/core/no-variants-in-base': "error";
13
+ '@salty-css/core/must-be-exported': "error";
5
14
  };
6
- overrides: {
7
- files: string[];
8
- rules: {
9
- '@salty-css/core/no-variants-in-base': ["error"];
10
- };
11
- }[];
12
15
  };
13
16
  export default eslintConfigCore;
package/index.js CHANGED
@@ -1,17 +1,119 @@
1
- const s = {
2
- plugins: ["@salty-css/core"],
3
- rules: {
4
- "core/no-variants-in-base": "error"
1
+ import "esbuild";
2
+ import "child_process";
3
+ import "path";
4
+ import "fs";
5
+ import "fs/promises";
6
+ const v = ["salty", "css", "styles", "styled"], h = (r = []) => new RegExp(`\\.(${[...v, ...r].join("|")})\\.`), g = (r, o = []) => h(o).test(r), P = {
7
+ meta: {
8
+ type: "problem",
9
+ fixable: "code",
10
+ docs: {
11
+ description: "Ensure `variants` are not nested inside `base` in styled calls",
12
+ category: "Errors",
13
+ recommended: !0
14
+ },
15
+ messages: {
16
+ nestedVariants: "`variants` should not be nested inside `base`."
17
+ }
18
+ },
19
+ create(r) {
20
+ return g(r.filename) ? {
21
+ CallExpression: (l) => {
22
+ try {
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
+ );
34
+ if (!n) return;
35
+ r.report({
36
+ node: n,
37
+ messageId: "nestedVariants",
38
+ fix: (s) => {
39
+ if (!n.range) return null;
40
+ const { sourceCode: f } = r, x = f.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]], d = [
43
+ n.range[0] - 1,
44
+ // Include the preceding comma (if any)
45
+ n.range[1]
46
+ ];
47
+ if (u.properties.at(-1) === n) {
48
+ const m = f.text.slice(n.range[1]).match(/^\s*,/);
49
+ m && (d[1] += m[0].length);
50
+ }
51
+ return [s.removeRange(d), s.insertTextAfterRange(E, `, ${x}`)];
52
+ }
53
+ });
54
+ } catch (i) {
55
+ console.log("ESlint error", i);
56
+ return;
57
+ }
58
+ }
59
+ } : {};
60
+ }
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
69
+ },
70
+ messages: {
71
+ mustBeExported: "Salty CSS related function calls or other values must be exported"
72
+ }
5
73
  },
6
- overrides: [
7
- {
8
- files: ["*.css.ts", "*.css.tsx"],
9
- rules: {
10
- "@salty-css/core/no-variants-in-base": ["error"]
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;
11
85
  }
86
+ return !1;
12
87
  }
13
- ]
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
+ }));
99
+ }
100
+ };
101
+ }
102
+ }, C = {
103
+ rules: {
104
+ "no-variants-in-base": P,
105
+ "must-be-exported": S
106
+ }
107
+ }, T = {
108
+ files: ["**/*.ts", "**/*.tsx"],
109
+ plugins: {
110
+ "@salty-css/core": C
111
+ },
112
+ rules: {
113
+ "@salty-css/core/no-variants-in-base": "error",
114
+ "@salty-css/core/must-be-exported": "error"
115
+ }
14
116
  };
15
117
  export {
16
- s as default
118
+ T as default
17
119
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/eslint-config-core",
3
- "version": "0.0.1-alpha.81",
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,8 +34,8 @@
34
34
  }
35
35
  },
36
36
  "dependencies": {
37
- "@salty-css/core": "^0.0.1-alpha.81",
38
- "@salty-css/eslint-plugin-core": "^0.0.1-alpha.81",
37
+ "@salty-css/core": "^0.0.1-alpha.82",
38
+ "@salty-css/eslint-plugin-core": "^0.0.1-alpha.82",
39
39
  "eslint": ">=9.x || >=8.x || >=7.x"
40
40
  }
41
41
  }