From f00e8b1773ee796418f74381a01aab1efcfab695 Mon Sep 17 00:00:00 2001
From: eno1220
Date: Sun, 4 Jun 2023 23:21:39 +0900
Subject: [PATCH] =?UTF-8?q?:+1:=20linter=E3=82=92=E5=B0=8E=E5=85=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.eslintrc.js | 42 +++++
.eslintrc.json | 3 -
.husky/common.sh | 8 +
.husky/pre-commit | 5 +
.lintstagedrc.js | 16 ++
package.json | 12 +-
prettier.config.js | 7 +
src/pages/_document.tsx | 2 +-
src/pages/index.tsx | 47 ++---
yarn.lock | 381 +++++++++++++++++++++++++++++++++++++++-
10 files changed, 488 insertions(+), 35 deletions(-)
create mode 100644 .eslintrc.js
delete mode 100644 .eslintrc.json
create mode 100644 .husky/common.sh
create mode 100644 .husky/pre-commit
create mode 100644 .lintstagedrc.js
create mode 100644 prettier.config.js
diff --git a/.eslintrc.js b/.eslintrc.js
new file mode 100644
index 0000000..d33268b
--- /dev/null
+++ b/.eslintrc.js
@@ -0,0 +1,42 @@
+module.exports = {
+ extends: [
+ 'next/core-web-vitals',
+ 'eslint:recommended',
+ 'plugin:@typescript-eslint/recommended',
+ ],
+ parser: '@typescript-eslint/parser',
+ plugins: ['@typescript-eslint', 'import', 'unused-imports'],
+ rules: {
+ '@typescript-eslint/no-unused-vars': 'error',
+ 'unused-imports/no-unused-imports': 'error',
+ 'import/order': [
+ 'error',
+ {
+ pathGroups: [
+ {
+ pattern: 'react**',
+ group: 'external',
+ position: 'before',
+ },
+ {
+ pattern: '{next**,next/**}',
+ group: 'external',
+ position: 'before',
+ },
+ {
+ pattern: '@chakra-ui/**',
+ group: 'external',
+ position: 'before',
+ },
+ ],
+ pathGroupsExcludedImportTypes: ['react', 'next', '@chakra-ui'],
+ 'newlines-between': 'always',
+ alphabetize: {
+ order: 'asc',
+ caseInsensitive: true,
+ orderImportKind: 'asc',
+ },
+ },
+ ],
+ },
+}
diff --git a/.eslintrc.json b/.eslintrc.json
deleted file mode 100644
index bffb357..0000000
--- a/.eslintrc.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "extends": "next/core-web-vitals"
-}
diff --git a/.husky/common.sh b/.husky/common.sh
new file mode 100644
index 0000000..0f4ced8
--- /dev/null
+++ b/.husky/common.sh
@@ -0,0 +1,8 @@
+command_exists () {
+ command -v "$1" >/dev/null 2>&1
+}
+
+# Workaround for Windows 10, Git Bash and Yarn
+if command_exists winpty && test -t 1; then
+ exec < /dev/tty
+fi
\ No newline at end of file
diff --git a/.husky/pre-commit b/.husky/pre-commit
new file mode 100644
index 0000000..58a97a4
--- /dev/null
+++ b/.husky/pre-commit
@@ -0,0 +1,5 @@
+#!/bin/sh
+. "$(dirname "$0")/_/husky.sh"
+. "$(dirname "$0")/common.sh"
+
+yarn lint-staged
\ No newline at end of file
diff --git a/.lintstagedrc.js b/.lintstagedrc.js
new file mode 100644
index 0000000..c1375b6
--- /dev/null
+++ b/.lintstagedrc.js
@@ -0,0 +1,16 @@
+const path = require('path')
+
+const buildEslintCommand = (filenames) =>
+ `next lint --fix --file ${filenames
+ .map((f) => path.relative(process.cwd(), f))
+ .join(' --file ')}`
+
+const buildPrettierCommand = (filenames) =>
+ `prettier --write ${filenames
+ .map((f) => path.relative(process.cwd(), f))
+ .join(' ')}`
+
+module.exports = {
+ '*.{js,jsx,ts,tsx}': [buildEslintCommand],
+ '*.{js,jsx,ts,tsx,yml,json,css,md}': [buildPrettierCommand],
+}
diff --git a/package.json b/package.json
index cfd2c0b..e0b7021 100644
--- a/package.json
+++ b/package.json
@@ -6,7 +6,9 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
- "lint": "next lint"
+ "lint": "next lint && prettier --check .",
+ "lint:fix": "next lint --fix && prettier --write .",
+ "postinstall": "husky install"
},
"dependencies": {
"@chakra-ui/react": "^2.7.0",
@@ -15,6 +17,7 @@
"@types/node": "20.2.5",
"@types/react": "18.2.8",
"@types/react-dom": "18.2.4",
+ "@typescript-eslint/eslint-plugin": "^5.59.8",
"axios": "^1.4.0",
"eslint": "8.42.0",
"eslint-config-next": "13.4.4",
@@ -23,5 +26,12 @@
"react": "18.2.0",
"react-dom": "18.2.0",
"typescript": "5.1.3"
+ },
+ "devDependencies": {
+ "eslint-plugin-import": "^2.27.5",
+ "eslint-plugin-unused-imports": "^2.0.0",
+ "husky": "^8.0.3",
+ "lint-staged": "^13.2.2",
+ "prettier": "^2.8.8"
}
}
diff --git a/prettier.config.js b/prettier.config.js
new file mode 100644
index 0000000..569b515
--- /dev/null
+++ b/prettier.config.js
@@ -0,0 +1,7 @@
+module.exports = {
+ useTabs: false,
+ semi: false,
+ singleQuote: true,
+ jsxSingleQuote: true,
+ bracketSpacing: true,
+}
diff --git a/src/pages/_document.tsx b/src/pages/_document.tsx
index 54e8bf3..ee65e53 100644
--- a/src/pages/_document.tsx
+++ b/src/pages/_document.tsx
@@ -2,7 +2,7 @@ import { Html, Head, Main, NextScript } from 'next/document'
export default function Document() {
return (
-
+