@salty-css/eslint-plugin-core 0.0.1-alpha.81 → 0.0.1-alpha.83

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 CHANGED
@@ -1 +1 @@
1
- "use strict";require("esbuild");require("child_process");require("path");require("fs");require("fs/promises");const x=["salty","css","styles","styled"],v=(t=[])=>new RegExp(`\\.(${[...x,...t].join("|")})\\.`),P=(t,l=[])=>v(l).test(t),E={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(t){return P(t.filename)?{CallExpression:g=>{try{const{callee:n,arguments:f}=g;if(!(n.type==="Identifier"&&n.name==="styled"))return;const r=f[1];if(!r||!(r.type==="ObjectExpression"))return;const a=r.properties.find(e=>e.type==="Property"&&e.key.type==="Identifier"&&e.key.name==="base");if(!a)return;const{value:i}=a;if(!(i.type==="ObjectExpression"))return;const s=i.properties.find(e=>e.type==="Property"&&e.key.type==="Identifier"&&e.key.name==="variants");if(!s)return;t.report({node:s,messageId:"nestedVariants",fix:e=>{if(!s.range)return null;const{sourceCode:d}=t,p=d.getText(s),m=r.properties.indexOf(a),o=r.properties[m];if(!o.range)return null;const b=[o.range[1],o.range[1]],y=[s.range[0]-1,s.range[1]];if(i.properties.at(-1)===s){const u=d.text.slice(s.range[1]).match(/^\s*,/);u&&(y[1]+=u[0].length)}return[e.removeRange(y),e.insertTextAfterRange(b,`, ${p}`)]}})}catch(n){console.log("ESlint error",n);return}}}:{}}},c={configs:{},rules:{"no-variants-in-base":E}};Object.assign(c.configs,{recommended:{plugins:{core:c},rules:{"core/no-variants-in-base":"error"},overrides:[{files:["*.css.ts","*.css.tsx"],rules:{"@salty-css/core/no-variants-in-base":["warn"]}}]}});module.exports=c;
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
@@ -1,7 +1,7 @@
1
1
  declare const eslintPluginCore: {
2
- configs: {};
3
2
  rules: {
4
3
  'no-variants-in-base': import("eslint").Rule.RuleModule;
4
+ 'must-be-exported': import("eslint").Rule.RuleModule;
5
5
  };
6
6
  };
7
7
  export default eslintPluginCore;
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 x = ["salty", "css", "styles", "styled"], v = (t = []) => new RegExp(`\\.(${[...x, ...t].join("|")})\\.`), P = (t, c = []) => v(c).test(t), E = {
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(t) {
20
- return P(t.filename) ? {
21
- CallExpression: (m) => {
19
+ create(r) {
20
+ return g(r.filename) ? {
21
+ CallExpression: (l) => {
22
22
  try {
23
- const { callee: n, arguments: f } = m;
24
- if (!(n.type === "Identifier" && n.name === "styled")) return;
25
- const r = f[1];
26
- if (!r || !(r.type === "ObjectExpression")) return;
27
- const a = r.properties.find((e) => e.type === "Property" && e.key.type === "Identifier" && e.key.name === "base");
28
- if (!a) return;
29
- const { value: i } = a;
30
- if (!(i.type === "ObjectExpression")) return;
31
- const s = i.properties.find(
32
- (e) => e.type === "Property" && e.key.type === "Identifier" && e.key.name === "variants"
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 (!s) return;
35
- t.report({
36
- node: s,
34
+ if (!n) return;
35
+ r.report({
36
+ node: n,
37
37
  messageId: "nestedVariants",
38
- fix: (e) => {
39
- if (!s.range) return null;
40
- const { sourceCode: l } = t, g = l.getText(s), u = r.properties.indexOf(a), o = r.properties[u];
41
- if (!o.range) return null;
42
- const b = [o.range[1], o.range[1]], d = [
43
- s.range[0] - 1,
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
- s.range[1]
45
+ n.range[1]
46
46
  ];
47
- if (i.properties.at(-1) === s) {
48
- const y = l.text.slice(s.range[1]).match(/^\s*,/);
49
- y && (d[1] += y[0].length);
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 [e.removeRange(d), e.insertTextAfterRange(b, `, ${g}`)];
51
+ return [s.removeRange(f), s.insertTextAfterRange(E, `, ${x}`)];
52
52
  }
53
53
  });
54
- } catch (n) {
55
- console.log("ESlint error", n);
54
+ } catch (i) {
55
+ console.log("ESlint error", i);
56
56
  return;
57
57
  }
58
58
  }
59
59
  } : {};
60
60
  }
61
- }, p = {
62
- configs: {},
63
- rules: {
64
- "no-variants-in-base": E
65
- }
66
- };
67
- Object.assign(p.configs, {
68
- recommended: {
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
- overrides: [
76
- {
77
- files: ["*.css.ts", "*.css.tsx"],
78
- rules: {
79
- "@salty-css/core/no-variants-in-base": ["warn"]
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
- p as default
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.81",
3
+ "version": "0.0.1-alpha.83",
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.81",
37
+ "@salty-css/core": "^0.0.1-alpha.83",
38
38
  "eslint": ">=9.x || >=8.x || >=7.x"
39
39
  }
40
40
  }
@@ -0,0 +1,2 @@
1
+ import { Rule } from 'eslint';
2
+ export declare const mustBeExported: Rule.RuleModule;