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

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/README.md CHANGED
@@ -1,15 +1,91 @@
1
- # Salty Css
1
+ # Salty CSS - Kinda sweet but yet spicy CSS-in-JS library
2
2
 
3
- ## Basic usage example with Button
3
+ In the world of frontend dev is there anything saltier than CSS? Salty CSS is built to provide better developer experience for developers looking for performant and feature rich CSS-in-JS solutions.
4
4
 
5
- ### Initial requirements
5
+ ## Features
6
6
 
7
- 1. Add `saltyPlugin` to vite or webpack config from `@salty-css/vite` or `@salty-css/webpack`
8
- 2. Create `salty-config.ts` to the root of your project
9
- 3. Import global styles to any regular .css file from `saltygen/index.css` (does not exist during first run, cli command coming later)
10
- 4. Create salty components with styled only inside files that end with `.css.ts`, `.salty.ts` `.styled.ts` or `.styles.ts`
7
+ - Build time compilation to achieve awesome runtime performance and minimal size
8
+ - Next.js, React Server Components, Vite and Webpack support
9
+ - Type safety with out of the box TypeScript and ESLint plugin
10
+ - Advanced CSS variables configuration to allow smooth token usage
11
+ - Style templates to create reusable styles easily
11
12
 
12
- ### Code examples
13
+ ## Get started
14
+
15
+ - Initialize: `npx salty-css init [directory]`
16
+ - Create component: `npx salty-css generate [filePath]`
17
+ - Build: `npx salty-css build [directory]`
18
+
19
+ ### Initialize
20
+
21
+ Fastest way to get started with any framework is [npx salty-css init [directory]](#initialize-salty-css-for-a-project) command
22
+
23
+ - Next.js → [Next.js guide](#nextjs) + [Next.js example app](https://github.com/margarita-form/salty-css-website)
24
+ - React → [React guide](#react) + [React example code](#code-examples)
25
+ - Vite → [Vite guide](#vite)
26
+ - Webpack → Guide coming soon
27
+ - ESLint → Guide coming soon
28
+
29
+ ### Salty CSS CLI
30
+
31
+ In your existing repository you can use `npx salty-css [command]` to initialize a project, generate components, update related packages and build required files.
32
+
33
+ - Initialize project → `npx salty-css init [directory]` - Installs required packages, detects framework in use and creates project files to the provided directory. Directory can be left blank if you want files to be created to the current directory.
34
+ - Generate component → `npx salty-css update [version]` - Update @salty-css packages in your repository. Default version is "latest". Additional options like `--dir`, `--tag`, `--name` and `--className` are also supported.
35
+ - Build files → `npx salty-css build [directory]` - Compile Salty CSS related files in your project. This should not be needed if you are using tools like Next.js or Vite
36
+
37
+ ### Guides
38
+
39
+ #### Next.js
40
+
41
+ In your existing Next.js repository you can run `npx salty-css init` to automatically configure Salty CSS.
42
+
43
+ ##### Manual configuration
44
+
45
+ 1. For Next.js support install `npm i @salty-css/next @salty-css/core @salty-css/react`
46
+ 2. Create `salty.config.ts` to your app directory
47
+ 3. Add Salty CSS plugin to next.js config
48
+
49
+ - **Next.js 15:** In `next.config.ts` add import for salty plugin `import { withSaltyCss } from '@salty-css/next';` and then add `withSaltyCss` to wrap your nextConfig export like so `export default withSaltyCss(nextConfig);`
50
+ - **Next.js 14 and older:** In `next.config.js` add import for salty plugin `const { withSaltyCss } = require('@salty-css/next');` and then add `withSaltyCss` to wrap your nextConfig export like so `module.exports = withSaltyCss(nextConfig);`
51
+
52
+ 4. Make sure that `salty.config.ts` and `next.config.ts` are in the same folder!
53
+ 5. Build `saltygen` directory by running your app once or with cli `npx salty-css build [directory]`
54
+ 6. Import global styles from `saltygen/index.css` to some global css file with `@import 'insert_path_to_index_css';`.
55
+
56
+ [Check out Next.js demo project](https://github.com/margarita-form/salty-css-website) or [react example code](#code-examples)
57
+
58
+ #### Vite
59
+
60
+ In your existing Vite repository you can run `npx salty-css init` to automatically configure Salty CSS.
61
+
62
+ ##### Manual configuration
63
+
64
+ 1. For Vite support install `npm i @salty-css/vite @salty-css/core`
65
+ 2. In `vite.config` add import for salty plugin `import { saltyPlugin } from '@salty-css/vite';` and then add `saltyPlugin(__dirname)` to your vite configuration plugins
66
+ 3. Make sure that `salty.config.ts` and `vite.config.ts` are in the same folder!
67
+ 4. Build `saltygen` directory by running your app once or with cli `npx salty-css build [directory]`
68
+ 5. Import global styles from `saltygen/index.css` to some global css file with `@import 'insert_path_to_index_css';`.
69
+
70
+ #### React
71
+
72
+ In your existing React repository you can run `npx salty-css init` to automatically configure Salty CSS.
73
+
74
+ ##### Manual configuration
75
+
76
+ 1. Install related dependencies: `npm i @salty-css/core @salty-css/react`
77
+ 2. Create `salty.config.ts` to your app directory
78
+ 3. Configure your build tool to support Salty CSS ([Vite](#vite) or Webpack) or after changes run `npx salty-css build`
79
+
80
+ [Check out react example code](#code-examples)
81
+
82
+ ### Create components
83
+
84
+ 1. Create salty components with styled only inside files that end with `.css.ts`, `.salty.ts` `.styled.ts` or `.styles.ts`
85
+
86
+ ## Code examples
87
+
88
+ ### Basic usage example with Button
13
89
 
14
90
  **Salty config**
15
91
 
@@ -31,23 +107,6 @@ export const config = defineConfig({
31
107
  });
32
108
  ```
33
109
 
34
- **Your React component file**
35
-
36
- ```tsx
37
- import { Wrapper } from '../components/wrapper/wrapper.css';
38
- import { Button } from '../components/button/button.css';
39
-
40
- export const IndexPage = () => {
41
- return (
42
- <Wrapper>
43
- <Button variant="solid" onClick={() => alert('It is a button.')}>
44
- Outlined
45
- </Button>
46
- </Wrapper>
47
- );
48
- };
49
- ```
50
-
51
110
  **Wrapper** (`components/wrapper/wrapper.css.ts`)
52
111
 
53
112
  ```tsx
@@ -72,7 +131,7 @@ export const Button = styled('button', {
72
131
  padding: `0.6em 1.2em`,
73
132
  border: '1px solid currentColor',
74
133
  background: 'transparent',
75
- color: 'currentColor/40',
134
+ color: 'currentColor',
76
135
  cursor: 'pointer',
77
136
  transition: '200ms',
78
137
  textDecoration: 'none',
@@ -108,4 +167,21 @@ export const Button = styled('button', {
108
167
  });
109
168
  ```
110
169
 
170
+ **Your React component file**
171
+
172
+ ```tsx
173
+ import { Wrapper } from '../components/wrapper/wrapper.css';
174
+ import { Button } from '../components/button/button.css';
175
+
176
+ export const IndexPage = () => {
177
+ return (
178
+ <Wrapper>
179
+ <Button variant="solid" onClick={() => alert('It is a button.')}>
180
+ Outlined
181
+ </Button>
182
+ </Wrapper>
183
+ );
184
+ };
185
+ ```
186
+
111
187
  More examples coming soon
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");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;
package/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- declare const _default: {
1
+ declare const eslintPluginCore: {
2
2
  rules: {
3
3
  'no-variants-in-base': import("eslint").Rule.RuleModule;
4
+ 'must-be-exported': import("eslint").Rule.RuleModule;
4
5
  };
5
6
  };
6
- export default _default;
7
+ export default eslintPluginCore;
package/index.js CHANGED
@@ -1,17 +1,18 @@
1
1
  import "esbuild";
2
- import * as s from "winston";
3
2
  import "child_process";
4
3
  import "path";
5
4
  import "fs";
6
5
  import "fs/promises";
7
- s.createLogger({
8
- level: "info",
9
- format: s.format.combine(s.format.colorize(), s.format.cli()),
10
- transports: [new s.transports.Console({})]
6
+ import { createLogger as h, format as f, transports as P } from "winston";
7
+ h({
8
+ level: "debug",
9
+ format: f.combine(f.colorize(), f.cli()),
10
+ transports: [new P.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 S = ["salty", "css", "styles", "styled"], I = (r = []) => new RegExp(`\\.(${[...S, ...r].join("|")})\\.`), x = (r, i = []) => I(i).test(r), V = {
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,95 @@ 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(r) {
26
+ return x(r.filename) ? {
27
+ CallExpression: (l) => {
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(
37
- (e) => e.type === "Property" && e.key.type === "Identifier" && e.key.name === "variants"
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(
38
+ (s) => s.type === "Property" && s.key.type === "Identifier" && s.key.name === "variants"
38
39
  );
39
- if (!l) return;
40
- t.report({
41
- node: l,
42
- messageId: "nestedVariants"
40
+ if (!n) return;
41
+ r.report({
42
+ node: n,
43
+ messageId: "nestedVariants",
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,
50
+ // Include the preceding comma (if any)
51
+ n.range[1]
52
+ ];
53
+ if (p.properties.at(-1) === n) {
54
+ const g = m.text.slice(n.range[1]).match(/^\s*,/);
55
+ g && (y[1] += g[0].length);
56
+ }
57
+ return [s.removeRange(y), s.insertTextAfterRange(v, `, ${b}`)];
58
+ }
43
59
  });
44
- } catch (r) {
45
- console.log("ESlint error", r);
60
+ } catch (o) {
61
+ console.log("ESlint error", o);
46
62
  return;
47
63
  }
48
64
  }
49
65
  } : {};
50
66
  }
51
- }, I = {
67
+ }, C = {
68
+ meta: {
69
+ type: "problem",
70
+ fixable: "code",
71
+ docs: {
72
+ description: "Salty CSS related function calls or other values must be exported",
73
+ category: "Errors",
74
+ recommended: !0
75
+ },
76
+ messages: {
77
+ mustBeExported: "Salty CSS related function calls or other values must be exported"
78
+ }
79
+ },
80
+ create(r) {
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;
88
+ const d = ["styled", "keyframes"];
89
+ if (t.callee.type === "Identifier" && d.includes(t.callee.name))
90
+ return !0;
91
+ }
92
+ return !1;
93
+ }
94
+ function o(e) {
95
+ const a = e.parent;
96
+ return a.type === "ExportNamedDeclaration" || a.type === "ExportDefaultDeclaration";
97
+ }
98
+ return {
99
+ VariableDeclaration: (e) => {
100
+ l(e) && (o(e) || r.report({
101
+ node: e,
102
+ messageId: "mustBeExported",
103
+ fix: (a) => a.insertTextBefore(e, "export ")
104
+ }));
105
+ }
106
+ };
107
+ }
108
+ }, L = {
52
109
  rules: {
53
- "no-variants-in-base": f
110
+ "no-variants-in-base": V,
111
+ "must-be-exported": C
54
112
  }
55
113
  };
56
114
  export {
57
- I as default
115
+ L as default
58
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.12",
3
+ "version": "0.0.1-alpha.121",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",
@@ -10,7 +10,12 @@
10
10
  "publishConfig": {
11
11
  "access": "public"
12
12
  },
13
- "homepage": "https://github.com/margarita-form/salty-css",
13
+ "description": "ESLint plugin for Salty CSS",
14
+ "homepage": "https://salty-css.dev/",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/margarita-form/salty-css.git"
18
+ },
14
19
  "bugs": {
15
20
  "url": "https://github.com/margarita-form/salty-css/issues"
16
21
  },
@@ -28,8 +33,8 @@
28
33
  "require": "./index.cjs"
29
34
  }
30
35
  },
31
- "peerDependencies": {
32
- "@salty-css/core": ">=1.x || >=0.x",
33
- "eslint": ">=9.x || >=8.x >=7.x"
36
+ "dependencies": {
37
+ "@salty-css/core": "^0.0.1-alpha.121",
38
+ "eslint": ">=9.x || >=8.x || >=7.x"
34
39
  }
35
40
  }
@@ -0,0 +1,2 @@
1
+ import { Rule } from 'eslint';
2
+ export declare const mustBeExported: Rule.RuleModule;