@yoshinani/style-guide 0.0.1

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,192 @@
1
+ # Yoshinani スタイルガイド
2
+
3
+ ## はじめに
4
+
5
+ このリポジトリは、Yoshinani のスタイルガイドのホームであり、人気のあるリンティングやスタイリングツール用の設定を含んでいます。
6
+
7
+ 以下の設定が利用可能で、組み合わせて使うことを想定しています。
8
+
9
+ - [Prettier](#prettier)
10
+ - [ESLint](#eslint)
11
+ - [TypeScript](#typescript)
12
+
13
+ ## コントリビュートについて
14
+
15
+ プルリクエストを作成する前に、[コントリビュートガイド](https://github.com/yoshinani-dev/style-guide/blob/main/CONTRIBUTING.md)をお読みください。
16
+
17
+ ## インストール
18
+
19
+ すべての設定は1つのパッケージ `@yoshinani/style-guide` に含まれています。インストール方法は以下の通りです。
20
+
21
+ ```sh
22
+ # npm を使う場合
23
+ npm i --save-dev @yoshinani/style-guide
24
+
25
+ # pnpm を使う場合
26
+ pnpm i --save-dev @yoshinani/style-guide
27
+
28
+ # Yarn を使う場合
29
+ yarn add --dev @yoshinani/style-guide
30
+ ```
31
+
32
+ 一部の ESLint 設定にはピア依存関係が必要です。必要な場合は [ESLint](#eslint) セクションで記載しています。
33
+
34
+ ## Prettier
35
+
36
+ > 注意: Prettier はこのパッケージのピア依存関係であり、プロジェクトのルートにインストールする必要があります。
37
+ >
38
+ > 参考: https://prettier.io/docs/en/install.html
39
+
40
+ 共有 Prettier 設定を使うには、`package.json` に以下を追加してください。
41
+
42
+ ```json
43
+ {
44
+ "prettier": "@yoshinani/style-guide/prettier"
45
+ }
46
+ ```
47
+
48
+ ## ESLint
49
+
50
+ > 注意: ESLint はこのパッケージのピア依存関係であり、プロジェクトのルートにインストールする必要があります。
51
+ >
52
+ > 参考: https://eslint.org/docs/user-guide/getting-started#installation-and-usage
53
+
54
+ この ESLint 設定は合成可能(composable)です。
55
+
56
+ 以下のベース設定が利用可能です。これらの設定は `extends` の最初に記載してください(どちらか一方または両方を使用可能)。
57
+
58
+ - `@yoshinani/style-guide/eslint/browser`
59
+ - `@yoshinani/style-guide/eslint/node`
60
+
61
+ 設定をスコープして、特定のファイルのみに適用することもできます。詳細は [Scoped configuration with `overrides`](#scoped-configuration-with-overrides) を参照してください。
62
+
63
+ 追加で利用できる設定は以下の通りです。
64
+
65
+ - `@yoshinani/style-guide/eslint/jest`
66
+ - `@yoshinani/style-guide/eslint/jest-react`(`@testing-library/react` のルールを含む)
67
+ - `@yoshinani/style-guide/eslint/next`(`@next/eslint-plugin-next` を `next` と同じバージョンでインストールする必要あり)
68
+ - `@yoshinani/style-guide/eslint/playwright-test`
69
+ - `@yoshinani/style-guide/eslint/react`
70
+ - `@yoshinani/style-guide/eslint/typescript`(`typescript` のインストールと[追加設定](#configuring-eslint-for-typescript)が必要)
71
+ - `@yoshinani/style-guide/eslint/vitest`
72
+
73
+ > ESLint の設定解決の問題([eslint/eslint#9188](https://github.com/eslint/eslint/issues/9188))のため、`require.resolve` を使って絶対パスを指定してください。
74
+
75
+ 例として、Next.js プロジェクトで共有 ESLint 設定を使う場合、`.eslintrc.js` に以下のように記載します。
76
+
77
+ ```js
78
+ module.exports = {
79
+ extends: [
80
+ require.resolve('@yoshinani/style-guide/eslint/browser'),
81
+ require.resolve('@yoshinani/style-guide/eslint/react'),
82
+ require.resolve('@yoshinani/style-guide/eslint/next'),
83
+ ],
84
+ };
85
+ ```
86
+
87
+ ### TypeScript 用 ESLint 設定
88
+
89
+ TypeScript 設定で有効になっている一部のルールは追加の型情報が必要です。`tsconfig.json` へのパスを指定してください。
90
+
91
+ 詳細は https://typescript-eslint.io/docs/linting/type-linting を参照してください。
92
+
93
+ ```js
94
+ const { resolve } = require('node:path');
95
+
96
+ const project = resolve(__dirname, 'tsconfig.json');
97
+
98
+ module.exports = {
99
+ root: true,
100
+ extends: [
101
+ require.resolve('@yoshinani/style-guide/eslint/node'),
102
+ require.resolve('@yoshinani/style-guide/eslint/typescript'),
103
+ ],
104
+ parserOptions: {
105
+ project,
106
+ },
107
+ settings: {
108
+ 'import/resolver': {
109
+ typescript: {
110
+ project,
111
+ },
112
+ },
113
+ },
114
+ };
115
+ ```
116
+
117
+ ### `jsx-a11y` のカスタムコンポーネント設定
118
+
119
+ React アプリでは、`Button` などの共通コンポーネントでネイティブ要素をラップすることが一般的です。`jsx-a11y` の `components` 設定でこの情報を渡せます。
120
+
121
+ 以下は一例です。
122
+
123
+ ```js
124
+ module.exports = {
125
+ root: true,
126
+ extends: [require.resolve('@yoshinani/style-guide/eslint/react')],
127
+ settings: {
128
+ 'jsx-a11y': {
129
+ components: {
130
+ Article: 'article',
131
+ Button: 'button',
132
+ Image: 'img',
133
+ Input: 'input',
134
+ Link: 'a',
135
+ Video: 'video',
136
+ },
137
+ },
138
+ },
139
+ };
140
+ ```
141
+
142
+ ### `overrides` を使ったスコープ設定
143
+
144
+ ESLint 設定は特定のパスにスコープできます。これにより、ルールが不要な場所に適用されるのを防げます。
145
+
146
+ 例として、Jest のルールをテストファイルのみに適用する場合は以下のようにします。
147
+
148
+ ```js
149
+ module.exports = {
150
+ extends: [require.resolve('@yoshinani/style-guide/eslint/node')],
151
+ overrides: [
152
+ {
153
+ files: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'],
154
+ extends: [require.resolve('@yoshinani/style-guide/eslint/jest')],
155
+ },
156
+ ],
157
+ };
158
+ ```
159
+
160
+ #### ファイル拡張子について
161
+
162
+ デフォルトでは、すべての TypeScript ルールは `.ts` および `.tsx` ファイルにスコープされています。
163
+
164
+ ただし、`overrides` を使う場合はファイル拡張子を明示的に含める必要があります。そうしないと ESLint は `.js` ファイルのみを対象にします。
165
+
166
+ ```js
167
+ module.exports = {
168
+ overrides: [
169
+ { files: [`directory/**/*.[jt]s?(x)`], rules: { 'my-rule': 'off' } },
170
+ ],
171
+ };
172
+ ```
173
+
174
+ ## TypeScript
175
+
176
+ このスタイルガイドは複数の TypeScript 設定を提供しています。これらの設定は LTS の Node.js バージョンに対応しており、それぞれに適した `lib`、`module`、`target`、`moduleResolution` 設定が含まれています。利用可能な設定は以下の通りです。
177
+
178
+ | Node.js バージョン | TypeScript 設定 |
179
+ | ------------------ | ----------------------------------------- |
180
+ | v16 | `@yoshinani/style-guide/typescript/node16` |
181
+ | v18 | `@yoshinani/style-guide/typescript/node18` |
182
+ | v20 | `@yoshinani/style-guide/typescript/node20` |
183
+
184
+ 共有 TypeScript 設定を使うには、`tsconfig.json` に以下のように記載します。
185
+
186
+ ```json
187
+ {
188
+ "extends": "@yoshinani/style-guide/typescript/node16"
189
+ }
190
+ ```
191
+
192
+ ベースとなる TypeScript 設定は [`@yoshinani/style-guide/typescript`](./typescript/tsconfig.base.json) としても利用可能で、一般的なルールのみを指定しています。`lib`、`module`、`target`、`moduleResolution` 設定をカスタマイズする場合はこのファイルを継承してください。
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@yoshinani/style-guide",
3
+ "version": "0.0.1",
4
+ "description": "Yoshinani's Style Guide",
5
+ "exports": {
6
+ "./typescript": "./typescript/base.json",
7
+ "./typescript/nextjs": "./typescript/nextjs.json",
8
+ "./typescript/react-library": "./typescript/react-library.json"
9
+ },
10
+ "files": [
11
+ "typescript"
12
+ ],
13
+ "devDependencies": {
14
+ "@commitlint/cli": "^19.8.0",
15
+ "@commitlint/config-conventional": "^19.8.0",
16
+ "husky": "^9.1.7"
17
+ },
18
+ "packageManager": "pnpm@9.15.4+sha512.b2dc20e2fc72b3e18848459b37359a32064663e5627a51e4c74b2c29dd8e8e0491483c3abb40789cfd578bf362fb6ba8261b05f0387d76792ed6e23ea3b1b6a0",
19
+ "scripts": {
20
+ "prepare": "husky"
21
+ },
22
+ "publishConfig": {
23
+ "access": "public"
24
+ }
25
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "compilerOptions": {
4
+ "declaration": true,
5
+ "declarationMap": true,
6
+ "esModuleInterop": true,
7
+ "forceConsistentCasingInFileNames": true,
8
+ "incremental": false,
9
+ "isolatedModules": true,
10
+ "lib": ["es2022", "DOM", "DOM.Iterable"],
11
+ "module": "NodeNext",
12
+ "moduleDetection": "force",
13
+ "moduleResolution": "NodeNext",
14
+ "noFallthroughCasesInSwitch": true,
15
+ "noImplicitReturns": true,
16
+ "noUncheckedIndexedAccess": true,
17
+ "resolveJsonModule": true,
18
+ "skipLibCheck": true,
19
+ "strict": true,
20
+ "target": "ES2022"
21
+ }
22
+ }
23
+
@@ -0,0 +1,16 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "./base.json",
4
+ "compilerOptions": {
5
+ "plugins": [{ "name": "next" }],
6
+ "module": "ESNext",
7
+ "moduleResolution": "Bundler",
8
+ "allowJs": true,
9
+ "jsx": "preserve",
10
+ "noEmit": true,
11
+ "types": [
12
+ "vitest/importMeta"
13
+ ]
14
+ }
15
+ }
16
+
@@ -0,0 +1,8 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "./base.json",
4
+ "compilerOptions": {
5
+ "jsx": "react-jsx"
6
+ }
7
+ }
8
+