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

Sign up to get free protection for your applications and to get access to all the features.
package/README.md ADDED
@@ -0,0 +1,111 @@
1
+ # Salty Css
2
+
3
+ ## Basic usage example with Button
4
+
5
+ ### Initial requirements
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`
11
+
12
+ ### Code examples
13
+
14
+ **Salty config**
15
+
16
+ ```tsx
17
+ import { defineConfig } from '@salty-css/core/config';
18
+
19
+ export const config = defineConfig({
20
+ variables: {
21
+ colors: {
22
+ brand: '#111',
23
+ highlight: 'yellow',
24
+ },
25
+ },
26
+ global: {
27
+ html: {
28
+ backgroundColor: '#f8f8f8',
29
+ },
30
+ },
31
+ });
32
+ ```
33
+
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
+ **Wrapper** (`components/wrapper/wrapper.css.ts`)
52
+
53
+ ```tsx
54
+ import { styled } from '@salty-css/react/styled';
55
+
56
+ export const Wrapper = styled('div', {
57
+ base: {
58
+ display: 'block',
59
+ padding: '2vw',
60
+ },
61
+ });
62
+ ```
63
+
64
+ **Button** (`components/button/button.css.ts`)
65
+
66
+ ```tsx
67
+ import { styled } from '@salty-css/react/styled';
68
+
69
+ export const Button = styled('button', {
70
+ base: {
71
+ display: 'block',
72
+ padding: `0.6em 1.2em`,
73
+ border: '1px solid currentColor',
74
+ background: 'transparent',
75
+ color: 'currentColor/40',
76
+ cursor: 'pointer',
77
+ transition: '200ms',
78
+ textDecoration: 'none',
79
+ '&:hover': {
80
+ background: 'black',
81
+ borderColor: 'black',
82
+ color: 'white',
83
+ },
84
+ '&:disabled': {
85
+ opacity: 0.25,
86
+ pointerEvents: 'none',
87
+ },
88
+ },
89
+ variants: {
90
+ variant: {
91
+ outlined: {
92
+ // same as default styles
93
+ },
94
+ solid: {
95
+ '&:not(:hover)': {
96
+ background: 'black',
97
+ borderColor: 'black',
98
+ color: 'white',
99
+ },
100
+ '&:hover': {
101
+ background: 'transparent',
102
+ borderColor: 'currentColor',
103
+ color: 'currentColor',
104
+ },
105
+ },
106
+ },
107
+ },
108
+ });
109
+ ```
110
+
111
+ More examples coming soon
package/index.cjs ADDED
@@ -0,0 +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;
package/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ declare const _default: {
2
+ rules: {
3
+ 'no-variants-in-base': import("eslint").Rule.RuleModule;
4
+ };
5
+ };
6
+ export default _default;
package/index.js ADDED
@@ -0,0 +1,58 @@
1
+ import "esbuild";
2
+ import * as s from "winston";
3
+ import "child_process";
4
+ import "path";
5
+ import "fs";
6
+ 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({})]
11
+ });
12
+ const d = ["salty", "css", "styles", "styled"], m = (t = []) => new RegExp(`\\.(${[...d, ...t].join("|")})\\.`), p = (t, a = []) => m(a).test(t), f = {
13
+ meta: {
14
+ type: "problem",
15
+ docs: {
16
+ description: "Ensure `variants` are not nested inside `base` in styled calls",
17
+ category: "Errors",
18
+ recommended: !0
19
+ },
20
+ messages: {
21
+ nestedVariants: "`variants` should not be nested inside `base`."
22
+ }
23
+ },
24
+ create(t) {
25
+ return p(t.filename) ? {
26
+ CallExpression: (c) => {
27
+ 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"
38
+ );
39
+ if (!l) return;
40
+ t.report({
41
+ node: l,
42
+ messageId: "nestedVariants"
43
+ });
44
+ } catch (r) {
45
+ console.log("ESlint error", r);
46
+ return;
47
+ }
48
+ }
49
+ } : {};
50
+ }
51
+ }, I = {
52
+ rules: {
53
+ "no-variants-in-base": f
54
+ }
55
+ };
56
+ export {
57
+ I as default
58
+ };
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@salty-css/eslint-plugin-core",
3
+ "version": "0.0.1-alpha.12",
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
+ "homepage": "https://github.com/margarita-form/salty-css",
14
+ "bugs": {
15
+ "url": "https://github.com/margarita-form/salty-css/issues"
16
+ },
17
+ "files": [
18
+ "**/*",
19
+ "!**/*.tsbuildinfo"
20
+ ],
21
+ "nx": {
22
+ "sourceRoot": "libs/eslint-plugin-core/src",
23
+ "name": "eslint-plugin-core"
24
+ },
25
+ "exports": {
26
+ ".": {
27
+ "import": "./index.js",
28
+ "require": "./index.cjs"
29
+ }
30
+ },
31
+ "peerDependencies": {
32
+ "@salty-css/core": ">=1.x || >=0.x",
33
+ "eslint": ">=9.x || >=8.x >=7.x"
34
+ }
35
+ }
@@ -0,0 +1,2 @@
1
+ import { Rule } from 'eslint';
2
+ export declare const noVariantsInBase: Rule.RuleModule;