@salty-css/eslint-plugin-core 0.0.1-alpha.12 → 0.0.1-alpha.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/index.cjs +1 -1
  2. package/index.js +42 -26
  3. package/package.json +1 -1
package/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";require("esbuild");const d=require("winston");require("child_process");require("path");require("fs");require("fs/promises");function y(e){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const t=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,t.get?t:{enumerable:!0,get:()=>e[n]})}}return r.default=e,Object.freeze(r)}const a=y(d);a.createLogger({level:"info",format:a.format.combine(a.format.colorize(),a.format.cli()),transports:[new a.transports.Console({})]});const f=["salty","css","styles","styled"],m=(e=[])=>new RegExp(`\\.(${[...f,...e].join("|")})\\.`),p=(e,r=[])=>m(r).test(e),b={meta:{type:"problem",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(e){return p(e.filename)?{CallExpression:n=>{try{const{callee:t,arguments:u}=n;if(!(t.type==="Identifier"&&t.name==="styled"))return;const i=u[0];if(!i||!(i.type==="ObjectExpression"))return;const o=i.properties.find(s=>s.type==="Property"&&s.key.type==="Identifier"&&s.key.name==="base");if(!o)return;const{value:l}=o;if(!(l.type==="ObjectExpression"))return;const c=l.properties.find(s=>s.type==="Property"&&s.key.type==="Identifier"&&s.key.name==="variants");if(!c)return;e.report({node:c,messageId:"nestedVariants"})}catch(t){console.log("ESlint error",t);return}}}:{}}},g={rules:{"no-variants-in-base":b}};module.exports=g;
1
+ "use strict";require("esbuild");const x=require("winston");require("child_process");require("path");require("fs");require("fs/promises");function P(e){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const a in e)if(a!=="default"){const s=Object.getOwnPropertyDescriptor(e,a);Object.defineProperty(n,a,s.get?s:{enumerable:!0,get:()=>e[a]})}}return n.default=e,Object.freeze(n)}const i=P(x);i.createLogger({level:"info",format:i.format.combine(i.format.colorize(),i.format.cli()),transports:[new i.transports.Console({})]});const v=["salty","css","styles","styled"],E=(e=[])=>new RegExp(`\\.(${[...v,...e].join("|")})\\.`),O=(e,n=[])=>E(n).test(e),h={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(e){return O(e.filename)?{CallExpression:a=>{try{const{callee:s,arguments:p}=a;if(!(s.type==="Identifier"&&s.name==="styled"))return;const o=p[1];if(!o||!(o.type==="ObjectExpression"))return;const c=o.properties.find(t=>t.type==="Property"&&t.key.type==="Identifier"&&t.key.name==="base");if(!c)return;const{value:l}=c;if(!(l.type==="ObjectExpression"))return;const r=l.properties.find(t=>t.type==="Property"&&t.key.type==="Identifier"&&t.key.name==="variants");if(!r)return;e.report({node:r,messageId:"nestedVariants",fix:t=>{if(!r.range)return null;const{sourceCode:f}=e,m=f.getText(r),g=o.properties.indexOf(c),u=o.properties[g];if(!u.range)return null;const b=[u.range[1],u.range[1]],d=[r.range[0]-1,r.range[1]];if(l.properties.at(-1)===r){const y=f.text.slice(r.range[1]).match(/^\s*,/);y&&(d[1]+=y[0].length)}return[t.removeRange(d),t.insertTextAfterRange(b,`, ${m}`)]}})}catch(s){console.log("ESlint error",s);return}}}:{}}},j={rules:{"no-variants-in-base":h}};module.exports=j;
package/index.js CHANGED
@@ -1,17 +1,18 @@
1
1
  import "esbuild";
2
- import * as s from "winston";
2
+ import * as n from "winston";
3
3
  import "child_process";
4
4
  import "path";
5
5
  import "fs";
6
6
  import "fs/promises";
7
- s.createLogger({
7
+ n.createLogger({
8
8
  level: "info",
9
- format: s.format.combine(s.format.colorize(), s.format.cli()),
10
- transports: [new s.transports.Console({})]
9
+ format: n.format.combine(n.format.colorize(), n.format.cli()),
10
+ transports: [new n.transports.Console({})]
11
11
  });
12
- const d = ["salty", "css", "styles", "styled"], m = (t = []) => new RegExp(`\\.(${[...d, ...t].join("|")})\\.`), p = (t, a = []) => m(a).test(t), f = {
12
+ const x = ["salty", "css", "styles", "styled"], v = (s = []) => new RegExp(`\\.(${[...x, ...s].join("|")})\\.`), P = (s, c = []) => v(c).test(s), E = {
13
13
  meta: {
14
14
  type: "problem",
15
+ fixable: "code",
15
16
  docs: {
16
17
  description: "Ensure `variants` are not nested inside `base` in styled calls",
17
18
  category: "Errors",
@@ -21,38 +22,53 @@ const d = ["salty", "css", "styles", "styled"], m = (t = []) => new RegExp(`\\.(
21
22
  nestedVariants: "`variants` should not be nested inside `base`."
22
23
  }
23
24
  },
24
- create(t) {
25
- return p(t.filename) ? {
26
- CallExpression: (c) => {
25
+ create(s) {
26
+ return P(s.filename) ? {
27
+ CallExpression: (y) => {
27
28
  try {
28
- const { callee: r, arguments: y } = c;
29
- if (!(r.type === "Identifier" && r.name === "styled")) return;
30
- const n = y[0];
31
- if (!n || !(n.type === "ObjectExpression")) return;
32
- const i = n.properties.find((e) => e.type === "Property" && e.key.type === "Identifier" && e.key.name === "base");
33
- if (!i) return;
34
- const { value: o } = i;
35
- if (!(o.type === "ObjectExpression")) return;
36
- const l = o.properties.find(
29
+ const { callee: a, arguments: f } = y;
30
+ if (!(a.type === "Identifier" && a.name === "styled")) return;
31
+ const r = f[1];
32
+ if (!r || !(r.type === "ObjectExpression")) return;
33
+ const o = r.properties.find((e) => e.type === "Property" && e.key.type === "Identifier" && e.key.name === "base");
34
+ if (!o) return;
35
+ const { value: i } = o;
36
+ if (!(i.type === "ObjectExpression")) return;
37
+ const t = i.properties.find(
37
38
  (e) => e.type === "Property" && e.key.type === "Identifier" && e.key.name === "variants"
38
39
  );
39
- if (!l) return;
40
- t.report({
41
- node: l,
42
- messageId: "nestedVariants"
40
+ if (!t) return;
41
+ s.report({
42
+ node: t,
43
+ messageId: "nestedVariants",
44
+ fix: (e) => {
45
+ if (!t.range) return null;
46
+ const { sourceCode: m } = s, g = m.getText(t), u = r.properties.indexOf(o), l = r.properties[u];
47
+ if (!l.range) return null;
48
+ const b = [l.range[1], l.range[1]], p = [
49
+ t.range[0] - 1,
50
+ // Include the preceding comma (if any)
51
+ t.range[1]
52
+ ];
53
+ if (i.properties.at(-1) === t) {
54
+ const d = m.text.slice(t.range[1]).match(/^\s*,/);
55
+ d && (p[1] += d[0].length);
56
+ }
57
+ return [e.removeRange(p), e.insertTextAfterRange(b, `, ${g}`)];
58
+ }
43
59
  });
44
- } catch (r) {
45
- console.log("ESlint error", r);
60
+ } catch (a) {
61
+ console.log("ESlint error", a);
46
62
  return;
47
63
  }
48
64
  }
49
65
  } : {};
50
66
  }
51
- }, I = {
67
+ }, T = {
52
68
  rules: {
53
- "no-variants-in-base": f
69
+ "no-variants-in-base": E
54
70
  }
55
71
  };
56
72
  export {
57
- I as default
73
+ T as default
58
74
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/eslint-plugin-core",
3
- "version": "0.0.1-alpha.12",
3
+ "version": "0.0.1-alpha.13",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",