@salty-css/eslint-plugin-core 0.0.1-alpha.152 → 0.0.1-alpha.154

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