@salty-css/eslint-plugin-core 0.0.1-alpha.100

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 ADDED
@@ -0,0 +1,186 @@
1
+ # Salty CSS - Kinda sweet but yet spicy CSS-in-JS library
2
+
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
+
5
+ ## Features
6
+
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
12
+
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
+ ### Packages
20
+
21
+ Note: 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](#nextjs) → `npm install @salty-css/next` + [Next.js install guide](#nextjs) + [Next.js example app](https://github.com/margarita-form/salty-css-website)
24
+ - [React](#react) → `npm install @salty-css/react` + [React install guide](#react) + [React example code](#code-examples)
25
+ - [Vite](#vite) → `npm install @salty-css/vite` + [(Vite install guide)](#vite)
26
+ - [Webpack](https://www.npmjs.com/package/@salty-css/webpack) → `npm install @salty-css/webpack` + Guide coming soon
27
+ - [ESLint](https://www.npmjs.com/package/@salty-css/eslint-plugin-core) → `npm install @salty-css/eslint-plugin-core` + Guide coming soon
28
+ - [Core](https://www.npmjs.com/package/@salty-css/react) → `npm install @salty-css/core` (This package contains code for internal use)
29
+
30
+ ### Add Salty CSS to your project with `salty-css` CLI
31
+
32
+ #### Initialize Salty CSS for a project
33
+
34
+ In your existing repository run `npx salty-css init [directory]` which installs required salty-css packages to the current directory, detects framework in use (current support for vite and next.js) and creates project files to the provided directory. Directory can be left blank if you want files to be created to the current directory. Init will also create `.saltyrc.json` which contains some metadata for future CLI commands.
35
+
36
+ #### Create components
37
+
38
+ Components can be created with `npx salty-css generate [filePath]` which then creates a new Salty CSS component file to the specified path. Additional options like `--dir, --tag, --name and --className` are also supported. Read more about them with `npx salty-css generate --help`
39
+
40
+ #### Build / Compile Salty CSS
41
+
42
+ If you want to manually build your project that can be done by running `npx salty-css build [directory]`. Directory is not required as CLI can use default directory defined in `.saltyrc.json`. Note that build generates css files but Vite / Webpack plugin is still required for full support.
43
+
44
+ #### Update Salty CSS packages
45
+
46
+ To ease the pain of package updates all Salty CSS packages can be updated with `npx salty-css update`
47
+
48
+ ### Manual work
49
+
50
+ #### Next.js
51
+
52
+ 1. For Next.js support install `npm i @salty-css/next @salty-css/core @salty-css/react`
53
+ 2. Create `salty.config.ts` to your app directory
54
+ 3. Add Salty CSS plugin to next.js config
55
+
56
+ - **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);`
57
+ - **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);`
58
+
59
+ 4. Make sure that `salty.config.ts` and `next.config.ts` are in the same folder!
60
+ 5. Build `saltygen` directory by running your app once or with cli `npx salty-css build [directory]`
61
+ 6. Import global styles from `saltygen/index.css` to some global css file with `@import 'insert_path_to_index_css';`.
62
+
63
+ [Check out Next.js demo project](https://github.com/margarita-form/salty-css-website) or [react example code](#code-examples)
64
+
65
+ #### React
66
+
67
+ 1. Install related dependencies: `npm i @salty-css/core @salty-css/react`
68
+ 2. Create `salty.config.ts` to your app directory
69
+ 3. Configure your build tool to support Salty CSS ([Vite](#vite) or Webpack)
70
+
71
+ [Check out react example code](#code-examples)
72
+
73
+ #### Vite
74
+
75
+ 1. For Vite support install `npm i @salty-css/vite @salty-css/core`
76
+ 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
77
+ 3. Make sure that `salty.config.ts` and `vite.config.ts` are in the same folder!
78
+ 4. Build `saltygen` directory by running your app once or with cli `npx salty-css build [directory]`
79
+ 5. Import global styles from `saltygen/index.css` to some global css file with `@import 'insert_path_to_index_css';`.
80
+
81
+ ### Create components
82
+
83
+ 1. Create salty components with styled only inside files that end with `.css.ts`, `.salty.ts` `.styled.ts` or `.styles.ts`
84
+
85
+ ## Code examples
86
+
87
+ ### Basic usage example with Button
88
+
89
+ **Salty config**
90
+
91
+ ```tsx
92
+ import { defineConfig } from '@salty-css/core/config';
93
+
94
+ export const config = defineConfig({
95
+ variables: {
96
+ colors: {
97
+ brand: '#111',
98
+ highlight: 'yellow',
99
+ },
100
+ },
101
+ global: {
102
+ html: {
103
+ backgroundColor: '#f8f8f8',
104
+ },
105
+ },
106
+ });
107
+ ```
108
+
109
+ **Your React component file**
110
+
111
+ ```tsx
112
+ import { Wrapper } from '../components/wrapper/wrapper.css';
113
+ import { Button } from '../components/button/button.css';
114
+
115
+ export const IndexPage = () => {
116
+ return (
117
+ <Wrapper>
118
+ <Button variant="solid" onClick={() => alert('It is a button.')}>
119
+ Outlined
120
+ </Button>
121
+ </Wrapper>
122
+ );
123
+ };
124
+ ```
125
+
126
+ **Wrapper** (`components/wrapper/wrapper.css.ts`)
127
+
128
+ ```tsx
129
+ import { styled } from '@salty-css/react/styled';
130
+
131
+ export const Wrapper = styled('div', {
132
+ base: {
133
+ display: 'block',
134
+ padding: '2vw',
135
+ },
136
+ });
137
+ ```
138
+
139
+ **Button** (`components/button/button.css.ts`)
140
+
141
+ ```tsx
142
+ import { styled } from '@salty-css/react/styled';
143
+
144
+ export const Button = styled('button', {
145
+ base: {
146
+ display: 'block',
147
+ padding: `0.6em 1.2em`,
148
+ border: '1px solid currentColor',
149
+ background: 'transparent',
150
+ color: 'currentColor/40',
151
+ cursor: 'pointer',
152
+ transition: '200ms',
153
+ textDecoration: 'none',
154
+ '&:hover': {
155
+ background: 'black',
156
+ borderColor: 'black',
157
+ color: 'white',
158
+ },
159
+ '&:disabled': {
160
+ opacity: 0.25,
161
+ pointerEvents: 'none',
162
+ },
163
+ },
164
+ variants: {
165
+ variant: {
166
+ outlined: {
167
+ // same as default styles
168
+ },
169
+ solid: {
170
+ '&:not(:hover)': {
171
+ background: 'black',
172
+ borderColor: 'black',
173
+ color: 'white',
174
+ },
175
+ '&:hover': {
176
+ background: 'transparent',
177
+ borderColor: 'currentColor',
178
+ color: 'currentColor',
179
+ },
180
+ },
181
+ },
182
+ },
183
+ });
184
+ ```
185
+
186
+ More examples coming soon
package/index.cjs ADDED
@@ -0,0 +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:d}=r,b=d.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=d.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 y=["styled","keyframes"];if(t.callee.type==="Identifier"&&y.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 ADDED
@@ -0,0 +1,7 @@
1
+ declare const eslintPluginCore: {
2
+ rules: {
3
+ 'no-variants-in-base': import("eslint").Rule.RuleModule;
4
+ 'must-be-exported': import("eslint").Rule.RuleModule;
5
+ };
6
+ };
7
+ export default eslintPluginCore;
package/index.js ADDED
@@ -0,0 +1,116 @@
1
+ import "esbuild";
2
+ import "child_process";
3
+ import "path";
4
+ import "fs";
5
+ import "fs/promises";
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
+ });
12
+ const S = ["salty", "css", "styles", "styled"], I = (r = []) => new RegExp(`\\.(${[...S, ...r].join("|")})\\.`), x = (r, i = []) => I(i).test(r), V = {
13
+ meta: {
14
+ type: "problem",
15
+ fixable: "code",
16
+ docs: {
17
+ description: "Ensure `variants` are not nested inside `base` in styled calls",
18
+ category: "Errors",
19
+ recommended: !0
20
+ },
21
+ messages: {
22
+ nestedVariants: "`variants` should not be nested inside `base`."
23
+ }
24
+ },
25
+ create(r) {
26
+ return x(r.filename) ? {
27
+ CallExpression: (l) => {
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(
38
+ (s) => s.type === "Property" && s.key.type === "Identifier" && s.key.name === "variants"
39
+ );
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
+ }
59
+ });
60
+ } catch (o) {
61
+ console.log("ESlint error", o);
62
+ return;
63
+ }
64
+ }
65
+ } : {};
66
+ }
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 = {
109
+ rules: {
110
+ "no-variants-in-base": V,
111
+ "must-be-exported": C
112
+ }
113
+ };
114
+ export {
115
+ L as default
116
+ };
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@salty-css/eslint-plugin-core",
3
+ "version": "0.0.1-alpha.100",
4
+ "main": "./dist/index.js",
5
+ "module": "./dist/index.mjs",
6
+ "typings": "./dist/index.d.ts",
7
+ "type": "module",
8
+ "license": "MIT",
9
+ "private": false,
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
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
+ },
19
+ "bugs": {
20
+ "url": "https://github.com/margarita-form/salty-css/issues"
21
+ },
22
+ "files": [
23
+ "**/*",
24
+ "!**/*.tsbuildinfo"
25
+ ],
26
+ "nx": {
27
+ "sourceRoot": "libs/eslint-plugin-core/src",
28
+ "name": "eslint-plugin-core"
29
+ },
30
+ "exports": {
31
+ ".": {
32
+ "import": "./index.js",
33
+ "require": "./index.cjs"
34
+ }
35
+ },
36
+ "dependencies": {
37
+ "@salty-css/core": "^0.0.1-alpha.100",
38
+ "eslint": ">=9.x || >=8.x || >=7.x"
39
+ }
40
+ }
@@ -0,0 +1,2 @@
1
+ import { Rule } from 'eslint';
2
+ export declare const mustBeExported: Rule.RuleModule;
@@ -0,0 +1,2 @@
1
+ import { Rule } from 'eslint';
2
+ export declare const noVariantsInBase: Rule.RuleModule;