Skip to content

Commit

Permalink
🎉 add eslint-config-react (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
woohm402 authored May 31, 2024
1 parent bf94bd9 commit 9f56502
Show file tree
Hide file tree
Showing 12 changed files with 215 additions and 2 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/publish-react.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Publish (React)

on:
push:
tags:
- react-v*

jobs:
publish:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20

# GitHub Packages 배포
- name: Publish to GitHub Packages
run: |
echo "//npm.pkg.github.com/:_authToken=${{secrets.GITHUB_TOKEN}}" > ~/.npmrc
yarn publish:react --registry=https://npm.pkg.github.com/
# npm 공용 레지스트리에 배포
- name: Publish to npm
run: |
echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_TOKEN}}" > ~/.npmrc
yarn publish:react --registry=https://registry.npmjs.org/
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"scripts": {
"test": "turbo run test",
"prettier": "prettier . --check",
"publish:base": "yarn workspace @woohm402/eslint-config-base publish"
"publish:base": "yarn workspace @woohm402/eslint-config-base publish",
"publish:react": "yarn workspace @woohm402/eslint-config-react publish"
},
"devDependencies": {
"prettier": "3.2.5",
Expand Down
5 changes: 5 additions & 0 deletions packages/react/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[![NPM Version](https://img.shields.io/npm/v/%40woohm402%2Feslint-config-base)](https://www.npmjs.com/package/@woohm402/eslint-config-base)

# @woohm402/eslint-config-base

base configuration for JavaScript/TypeScript projects
19 changes: 19 additions & 0 deletions packages/react/__tests__/base.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { ESLint } from 'eslint';
import { describe, it, expect } from 'vitest';
import path from 'path';

const eslint = new ESLint({ overrideConfigFile: path.resolve(__dirname, '../index.js') });

describe('@woohm402/eslint-config-base', function () {
it('right', async function () {
const [result] = await eslint.lintFiles([`${__dirname}/right.tsx`]);

expect(result.errorCount).toBe(0);
});

it('wrong', async function () {
const [result] = await eslint.lintFiles([`${__dirname}/wrong.tsx`]);

expect(result.errorCount).toBe(1);
});
});
19 changes: 19 additions & 0 deletions packages/react/__tests__/right.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useEffect, useState } from 'react';

const fetchData = async (name: string) => new Promise<string>((resolve) => setTimeout(() => resolve(name), 1000));

export const Component = ({ name }: { name: string }) => {
const [data, setData] = useState<string>();

useEffect(() => {
let ignore = false;

fetchData(name).then((data) => !ignore && setData(data));

return () => {
ignore = true;
};
}, [name]);

return <div>{data}</div>;
};
19 changes: 19 additions & 0 deletions packages/react/__tests__/wrong.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useEffect, useState } from 'react';

const fetchData = async (name: string) => new Promise<string>((resolve) => setTimeout(() => resolve(name), 1000));

export const Component = ({ name }: { name: string }) => {
const [data, setData] = useState<string>();

useEffect(() => {
let ignore = false;

fetchData(name).then((data) => !ignore && setData(data));

return () => {
ignore = true;
};
}, []);

return <div>{data}</div>;
};
5 changes: 5 additions & 0 deletions packages/react/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ESLint } from 'eslint';

declare const eslintConfigBase: ESLint.Config;

export = eslintConfigBase;
16 changes: 16 additions & 0 deletions packages/react/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import woohm402 from '@woohm402/eslint-config-base';
import eslintPluginReactHooks from 'eslint-plugin-react-hooks';
import { fixupPluginRules } from '@eslint/compat';

export default [
...woohm402,
{
plugins: {
'react-hooks': fixupPluginRules(eslintPluginReactHooks),
},
rules: {
...eslintPluginReactHooks.configs.recommended.rules,
'react-hooks/exhaustive-deps': 'error',
},
},
];
54 changes: 54 additions & 0 deletions packages/react/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "@woohm402/eslint-config-react",
"version": "0.0.1",
"description": "Base config for TypeScript React",
"private": false,
"scripts": {
"test": "vitest run"
},
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.js",
"index.d.ts"
],
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "git+https://github.com/woohm402/eslint-config-woohm402.git",
"directory": "packages/react"
},
"keywords": [
"eslint",
"eslintconfig"
],
"author": "Hyunmin Woo <[email protected]> (https://github.com/woohm402)",
"license": "MIT",
"bugs": {
"url": "https://github.com/woohm402/eslint-config-woohm402/issues"
},
"homepage": "https://github.com/woohm402/eslint-config-woohm402#readme",
"dependencies": {
"@eslint/compat": "1.0.3",
"@woohm402/eslint-config-base": "0.1.0",
"eslint-plugin-react-hooks": "4.6.2"
},
"peerDependencies": {
"@types/react": ">= 18",
"eslint": ">= 9",
"prettier": ">= 3",
"react": ">= 18",
"typescript": ">= 5"
},
"devDependencies": {
"@types/eslint": "8.56.10",
"@types/node": "20.12.13",
"@types/react": "18.3.3",
"eslint": "9.3.0",
"typescript": "5.4.5",
"vitest": "1.6.0"
}
}
10 changes: 10 additions & 0 deletions packages/react/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"types": ["node"],
"strict": true,
"esModuleInterop": true,
"jsx": "react-jsx"
},
"include": ["__tests__/**/*"],
"exclude": ["node_modules"]
}
7 changes: 7 additions & 0 deletions packages/react/vitest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
files: ['**/*.test.js'],
},
});
30 changes: 29 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
resolved "https://registry.yarnpkg.com/@esbuild/win32-x64/-/win32-x64-0.20.2.tgz#9c907b21e30a52db959ba4f80bb01a0cc403d5cc"
integrity sha512-N49X4lJX27+l9jbLKSqZ6bKNjzQvHaT8IIFUy+YIqmXQdjYCToGWwOItDrfby14c78aDd5NHQl29xingXfCdLQ==

"@eslint-community/eslint-plugin-eslint-comments@^4.3.0":
"@eslint-community/[email protected]":
version "4.3.0"
resolved "https://registry.yarnpkg.com/@eslint-community/eslint-plugin-eslint-comments/-/eslint-plugin-eslint-comments-4.3.0.tgz#e356a280764e14b1db9c94d0be7fab405431e2a6"
integrity sha512-6e93KtgsndNkvwCCa07LOQJSwzzLLxwrFll3+huyFoiiQXWG0KBcmo0Q1bVgYQQDLfWOOZl2VPBsXqZL6vHIBQ==
Expand All @@ -137,6 +137,11 @@
resolved "https://registry.yarnpkg.com/@eslint-community/regexpp/-/regexpp-4.10.0.tgz#548f6de556857c8bb73bbee70c35dc82a2e74d63"
integrity sha512-Cu96Sd2By9mCNTx2iyKOmq10v22jUVQv0lQnlGNy16oE9589yE+QADPbrMGCkA51cKZSg3Pu/aTJVTGfL/qjUA==

"@eslint/[email protected]":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@eslint/compat/-/compat-1.0.3.tgz#6be44cf553a14a2f68fafb304818f7d824a7248f"
integrity sha512-9RaroPQaU2+SDcWav1YfuipwqnHccoiXZdUsicRQsQ/vH2wkEmRVcj344GapG/FnCeZRtqj0n6PshI+s9xkkAQ==

"@eslint/eslintrc@^3.1.0":
version "3.1.0"
resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-3.1.0.tgz#dbd3482bfd91efa663cbe7aa1f506839868207b6"
Expand Down Expand Up @@ -329,6 +334,19 @@
dependencies:
undici-types "~5.26.4"

"@types/prop-types@*":
version "15.7.12"
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.12.tgz#12bb1e2be27293c1406acb6af1c3f3a1481d98c6"
integrity sha512-5zvhXYtRNRluoE/jAp4GVsSduVUzNWKkOZrCDBWYtE7biZywwdC2AcEzg+cSMLFRfVgeAFqpfNabiPjxFddV1Q==

"@types/[email protected]":
version "18.3.3"
resolved "https://registry.yarnpkg.com/@types/react/-/react-18.3.3.tgz#9679020895318b0915d7a3ab004d92d33375c45f"
integrity sha512-hti/R0pS0q1/xx+TsI73XIqk26eBsISZ2R0wUijXIngRK9R/e7Xw/cXVxQK7R5JjW+SV4zGcn5hXjudkN/pLIw==
dependencies:
"@types/prop-types" "*"
csstype "^3.0.2"

"@typescript-eslint/[email protected]":
version "7.11.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.11.0.tgz#f90f0914657ead08e1c75f66939c926edeab42dd"
Expand Down Expand Up @@ -607,6 +625,11 @@ cross-spawn@^7.0.2, cross-spawn@^7.0.3:
shebang-command "^2.0.0"
which "^2.0.1"

csstype@^3.0.2:
version "3.1.3"
resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.1.3.tgz#d80ff294d114fb0e6ac500fbf85b60137d7eff81"
integrity sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==

debug@^4.3.1, debug@^4.3.2, debug@^4.3.4:
version "4.3.4"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865"
Expand Down Expand Up @@ -685,6 +708,11 @@ [email protected]:
prettier-linter-helpers "^1.0.0"
synckit "^0.8.6"

[email protected]:
version "4.6.2"
resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-4.6.2.tgz#c829eb06c0e6f484b3fbb85a97e57784f328c596"
integrity sha512-QzliNJq4GinDBcD8gPB5v0wh6g8q3SUi6EFF0x8N/BL9PoVs0atuGc47ozMRyOWAKdwaZ5OnbOEa3WR+dSGKuQ==

[email protected]:
version "12.1.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-simple-import-sort/-/eslint-plugin-simple-import-sort-12.1.0.tgz#8186ad55474d2f5c986a2f1bf70625a981e30d05"
Expand Down

0 comments on commit 9f56502

Please sign in to comment.