@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.
Files changed (3) hide show
  1. package/index.cjs +1 -1
  2. package/index.js +41 -52
  3. package/package.json +2 -2
package/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";require("esbuild");require("child_process");require("path");require("fs");require("fs/promises");const o=require("winston");require("typescript");o.createLogger({level:"debug",format:o.format.combine(o.format.colorize(),o.format.cli()),transports:[new o.transports.Console({})]});const F=["salty","css","styles","styled"],S=(r=[])=>new RegExp(`\\.(${[...F,...r].join("|")})\\.`),x=(r,c=[])=>S(c).test(r),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(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}}}:{}}},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:"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 ")})}}}},h={rules:{"no-variants-in-base":E,"must-be-exported":P}};module.exports=h;
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 "esbuild";
2
- import "child_process";
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(r) {
27
- return x(r.filename) ? {
15
+ create(a) {
16
+ return d(a.filename) ? {
28
17
  CallExpression: (o) => {
29
18
  try {
30
- const { callee: a, arguments: c } = o;
31
- if (!(a.type === "Identifier" && a.name === "styled")) return;
32
- const t = c[1];
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((n) => n.type === "Property" && n.key.type === "Identifier" && n.key.name === "base");
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: f } = i;
37
- if (!(f.type === "ObjectExpression")) return;
38
- const s = f.properties.find(
39
- (n) => n.type === "Property" && n.key.type === "Identifier" && n.key.name === "variants"
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 (!s) return;
42
- r.report({
43
- node: s,
30
+ if (!n) return;
31
+ a.report({
32
+ node: n,
44
33
  messageId: "nestedVariants",
45
- fix: (n) => {
46
- if (!s.range) return null;
47
- const { sourceCode: y } = r, b = y.getText(s), v = t.properties.indexOf(i), p = t.properties[v];
48
- if (!p.range) return null;
49
- const I = [p.range[1], p.range[1]], d = [
50
- s.range[0] - 1,
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
- s.range[1]
41
+ n.range[1]
53
42
  ];
54
- if (f.properties.at(-1) === s) {
55
- const g = y.text.slice(s.range[1]).match(/^\s*,/);
56
- g && (d[1] += g[0].length);
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 [n.removeRange(d), n.insertTextAfterRange(I, `, ${b}`)];
47
+ return [r.removeRange(y), r.insertTextAfterRange(I, `, ${b}`)];
59
48
  }
60
49
  });
61
- } catch (a) {
62
- console.log("ESlint error", a);
50
+ } catch (s) {
51
+ console.log("ESlint error", s);
63
52
  return;
64
53
  }
65
54
  }
66
55
  } : {};
67
56
  }
68
- }, C = {
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(r) {
82
- if (!x(r.filename)) return {};
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 u = /^define[A-Z]/;
89
- return !!(e.callee.type === "Identifier" && u.test(e.callee.name));
77
+ const c = /^define[A-Z]/;
78
+ return !!(e.callee.type === "Identifier" && c.test(e.callee.name));
90
79
  }
91
- function a(e) {
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 c(e) {
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
- a(e) && (c(e) || r.report({
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") || r.report({
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
- }, N = {
108
+ }, V = {
120
109
  rules: {
121
- "no-variants-in-base": h,
122
- "must-be-exported": C
110
+ "no-variants-in-base": v,
111
+ "must-be-exported": S
123
112
  }
124
113
  };
125
114
  export {
126
- N as default
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.268",
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.268",
37
+ "@salty-css/core": "^0.0.1-alpha.269",
38
38
  "eslint": ">=9.x || >=8.x || >=7.x"
39
39
  }
40
40
  }