Skip to content

Commit

Permalink
feat(eslint-config): add ESLint configuration package with various pl…
Browse files Browse the repository at this point in the history
…ugins and custom rules (#10)

- Set up esbuild and tsup for building TypeScript and emitting .d.ts
files
- Added core configuration files for ESLint with custom rules for
Prettier, Sort Keys, Unicorn, and TypeScript support
- Introduced optional React and TypeScript support based on package
detection
- Added utility functions for combining configs and renaming rules
  • Loading branch information
dmitr1sdae authored Sep 28, 2024
2 parents db61633 + 2eb13a6 commit 140ad88
Show file tree
Hide file tree
Showing 98 changed files with 5,224 additions and 952 deletions.
448 changes: 224 additions & 224 deletions .yarn/releases/yarn-4.4.0.cjs → .yarn/releases/yarn-4.5.0.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ packageExtensions:
"@types/node": ^20.14.10
typescript: ^5.5.3

yarnPath: .yarn/releases/yarn-4.4.0.cjs
yarnPath: .yarn/releases/yarn-4.5.0.cjs
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
],
"scripts": {
"build": "lerna run build",
"lint": "lerna run lint --parallel",
"lint:fix": "lerna run lint:fix --parallel",
"pretty": "lerna run pretty --parallel",
"pretty:fix": "lerna run pretty:fix --parallel",
"publish": "lerna run publish --parallel"
Expand All @@ -20,10 +22,10 @@
"@commitlint/config-conventional": "^19.2.2",
"husky": "^9.0.11",
"lerna": "^8.1.6",
"prettier": "^3.3.2",
"prettier": "^3.3.3",
"typescript": "5.5.3"
},
"packageManager": "yarn@4.4.0",
"packageManager": "yarn@4.5.0",
"engines": {
"node": ">= v20.9.0"
}
Expand Down
3 changes: 3 additions & 0 deletions packages/avatar/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import norns from "@norns-ui/eslint-config-norns";

export default norns();
13 changes: 9 additions & 4 deletions packages/avatar/lib/Avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import {Norn} from "@norns-ui/norn";
import {createContextScope, Scope} from "@norns-ui/shared";
import {forwardRef, useState} from "react";
import {
ComponentPropsWithoutRef,
ElementRef,
forwardRef,
useState,
} from "react";

const AVATAR_NAME = "Avatar";

Expand All @@ -18,8 +23,8 @@ type AvatarContextValue = {
const [AvatarProvider, useAvatarContext] =
createAvatarContext<AvatarContextValue>(AVATAR_NAME);

type AvatarElement = React.ElementRef<typeof Norn.span>;
type NornSpanProps = React.ComponentPropsWithoutRef<typeof Norn.span>;
type AvatarElement = ElementRef<typeof Norn.span>;
type NornSpanProps = ComponentPropsWithoutRef<typeof Norn.span>;
interface AvatarProps extends NornSpanProps {}

const Avatar = forwardRef<AvatarElement, AvatarProps>(
Expand All @@ -41,4 +46,4 @@ const Avatar = forwardRef<AvatarElement, AvatarProps>(
Avatar.displayName = AVATAR_NAME;

export {Avatar, createAvatarScope, useAvatarContext};
export type {AvatarProps, AvatarElement, NornSpanProps, ScopedProps};
export type {AvatarElement, AvatarProps, NornSpanProps, ScopedProps};
1 change: 1 addition & 0 deletions packages/avatar/lib/AvatarFallback.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Norn} from "@norns-ui/norn";
import {ElementRef, forwardRef, useEffect, useState} from "react";

import {NornSpanProps, ScopedProps, useAvatarContext} from "./Avatar";

const FALLBACK_NAME = "AvatarFallback";
Expand Down
11 changes: 6 additions & 5 deletions packages/avatar/lib/AvatarImage.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import {Norn} from "@norns-ui/norn";
import {forwardRef} from "react";
import {ScopedProps, useAvatarContext} from "./Avatar";
import {
ImageLoadingStatus,
useCallbackRef,
useImageLoadingStatus,
useLayoutEffect,
} from "@norns-ui/hooks";
import {Norn} from "@norns-ui/norn";
import {ComponentPropsWithoutRef, ElementRef, forwardRef} from "react";

import {ScopedProps, useAvatarContext} from "./Avatar";

const IMAGE_NAME = "AvatarImage";

type AvatarImageElement = React.ElementRef<typeof Norn.img>;
type NornImageProps = React.ComponentPropsWithoutRef<typeof Norn.img>;
type AvatarImageElement = ElementRef<typeof Norn.img>;
type NornImageProps = ComponentPropsWithoutRef<typeof Norn.img>;
interface AvatarImageProps extends NornImageProps {
onLoadingStatusChange?: (status: ImageLoadingStatus) => void;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/avatar/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export {Avatar} from "./Avatar";
export type {AvatarProps} from "./Avatar";
export {AvatarFallback} from "./AvatarFallback";
export {Avatar} from "./Avatar";
export type {AvatarFallbackProps} from "./AvatarFallback";
export {AvatarImage} from "./AvatarImage";
export {AvatarFallback} from "./AvatarFallback";
export type {AvatarImageProps} from "./AvatarImage";
export {AvatarImage} from "./AvatarImage";
9 changes: 7 additions & 2 deletions packages/avatar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
],
"scripts": {
"build": "node esbuild.config.js",
"pretty": "prettier --check $(find . -type d \\( -name 'node_modules' -o -name 'dist' \\) -prune -o -print)",
"pretty:fix": "prettier --write $(find . -type d \\( -name 'node_modules' -o -name 'dist' \\) -prune -o -print)",
"lint": "eslint lib",
"lint:fix": "eslint lib --fix",
"pretty": "prettier --check $(find . -type d \\( -name 'node_modules' -o -name 'dist' \\) -prune -o \\( -type f -name '*.js' -o -name '*.ts' -o -name '*.tsx' \\) -print)",
"pretty:fix": "prettier --write $(find . -type d \\( -name 'node_modules' -o -name 'dist' \\) -prune -o \\( -type f -name '*.js' -o -name '*.ts' -o -name '*.tsx' \\) -print)",
"publish": "yarn npm publish --tolerate-republish"
},
"dependencies": {
Expand All @@ -30,10 +32,13 @@
"react-dom": "^18.3.1"
},
"devDependencies": {
"@norns-ui/eslint-config-norns": "workspace:packages/eslint-config-norns",
"@types/node": "^20.14.9",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"esbuild": "^0.23.0",
"eslint": "^9.11.1",
"prettier": "^3.3.3",
"tsup": "^8.2.4",
"typescript": "^5.5.4"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/collection/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import norns from "@norns-ui/eslint-config-norns";

export default norns();
10 changes: 6 additions & 4 deletions packages/collection/lib/createCollection.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"use client";

import {useComposedRefs} from "@norns-ui/hooks";
import {createContextScope} from "@norns-ui/shared";
import {Slot} from "@norns-ui/slot";
import {
ComponentPropsWithoutRef,
FC,
Expand All @@ -10,9 +13,6 @@ import {
useEffect,
useRef,
} from "react";
import {Slot} from "@norns-ui/slot";
import {createContextScope} from "@norns-ui/shared";
import {useComposedRefs} from "@norns-ui/hooks";

type SlotProps = ComponentPropsWithoutRef<typeof Slot>;
type CollectionElement = HTMLElement;
Expand Down Expand Up @@ -124,7 +124,9 @@ const createCollection = <ItemElement extends HTMLElement, ItemData = {}>(

const getItems = useCallback(() => {
const collectionNode = context.collectionRef.current;
if (!collectionNode) return [];
if (!collectionNode) {
return [];
}
const orderedNodes = Array.from(
collectionNode.querySelectorAll(`[${ITEM_DATA_ATTR}]`),
);
Expand Down
9 changes: 7 additions & 2 deletions packages/collection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
],
"scripts": {
"build": "node esbuild.config.js",
"pretty": "prettier --check $(find . -type d \\( -name 'node_modules' -o -name 'dist' \\) -prune -o -print)",
"pretty:fix": "prettier --write $(find . -type d \\( -name 'node_modules' -o -name 'dist' \\) -prune -o -print)",
"lint": "eslint lib",
"lint:fix": "eslint lib --fix",
"pretty": "prettier --check $(find . -type d \\( -name 'node_modules' -o -name 'dist' \\) -prune -o \\( -type f -name '*.js' -o -name '*.ts' -o -name '*.tsx' \\) -print)",
"pretty:fix": "prettier --write $(find . -type d \\( -name 'node_modules' -o -name 'dist' \\) -prune -o \\( -type f -name '*.js' -o -name '*.ts' -o -name '*.tsx' \\) -print)",
"publish": "yarn npm publish --tolerate-republish"
},
"dependencies": {
Expand All @@ -30,10 +32,13 @@
"react-dom": "^18.3.1"
},
"devDependencies": {
"@norns-ui/eslint-config-norns": "workspace:packages/eslint-config-norns",
"@types/node": "^20.14.9",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"esbuild": "^0.23.0",
"eslint": "^9.11.1",
"prettier": "^3.3.3",
"tsup": "^8.2.4",
"typescript": "^5.5.4"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/dismissable-layer/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import norns from "@norns-ui/eslint-config-norns";

export default norns();
Loading

0 comments on commit 140ad88

Please sign in to comment.