@yoshinani/style-guide 0.0.1 → 0.0.3
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 +16 -95
- package/eslint/base.js +133 -0
- package/eslint/library.js +40 -0
- package/eslint/next.js +35 -0
- package/eslint/react-internal.js +44 -0
- package/package.json +17 -3
package/README.md
CHANGED
|
@@ -51,92 +51,27 @@ yarn add --dev @yoshinani/style-guide
|
|
|
51
51
|
>
|
|
52
52
|
> 参考: https://eslint.org/docs/user-guide/getting-started#installation-and-usage
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
利用できる設定は以下の通りです。
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
- `@yoshinani/style-guide/eslint/
|
|
59
|
-
- `@yoshinani/style-guide/eslint/
|
|
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`
|
|
56
|
+
- `@yoshinani/style-guide/eslint/base`
|
|
57
|
+
- `@yoshinani/style-guide/eslint/next`
|
|
58
|
+
- `@yoshinani/style-guide/eslint/library`
|
|
59
|
+
- `@yoshinani/style-guide/eslint/react-internal`
|
|
72
60
|
|
|
73
61
|
> ESLint の設定解決の問題([eslint/eslint#9188](https://github.com/eslint/eslint/issues/9188))のため、`require.resolve` を使って絶対パスを指定してください。
|
|
74
62
|
|
|
75
63
|
例として、Next.js プロジェクトで共有 ESLint 設定を使う場合、`.eslintrc.js` に以下のように記載します。
|
|
76
64
|
|
|
77
65
|
```js
|
|
78
|
-
|
|
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
|
-
|
|
66
|
+
/** @type {import("eslint").Linter.Config} */
|
|
98
67
|
module.exports = {
|
|
99
68
|
root: true,
|
|
100
|
-
extends: [
|
|
101
|
-
|
|
102
|
-
require.resolve('@yoshinani/style-guide/eslint/typescript'),
|
|
103
|
-
],
|
|
69
|
+
extends: [require.resolve("@yoshinani/style-guide/eslint/next")],
|
|
70
|
+
parser: "@typescript-eslint/parser",
|
|
104
71
|
parserOptions: {
|
|
105
|
-
project,
|
|
72
|
+
project: true,
|
|
106
73
|
},
|
|
107
|
-
|
|
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
|
-
};
|
|
74
|
+
}
|
|
140
75
|
```
|
|
141
76
|
|
|
142
77
|
### `overrides` を使ったスコープ設定
|
|
@@ -157,35 +92,21 @@ module.exports = {
|
|
|
157
92
|
};
|
|
158
93
|
```
|
|
159
94
|
|
|
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
95
|
## TypeScript
|
|
175
96
|
|
|
176
97
|
このスタイルガイドは複数の TypeScript 設定を提供しています。これらの設定は LTS の Node.js バージョンに対応しており、それぞれに適した `lib`、`module`、`target`、`moduleResolution` 設定が含まれています。利用可能な設定は以下の通りです。
|
|
177
98
|
|
|
178
|
-
|
|
|
179
|
-
|
|
|
180
|
-
|
|
|
181
|
-
|
|
|
182
|
-
|
|
|
99
|
+
| 種類 | 設定パッケージ名 |
|
|
100
|
+
| -------------- | --------------------------------------------------- |
|
|
101
|
+
| base | `@yoshinani/style-guide/typescript/base` |
|
|
102
|
+
| nextjs | `@yoshinani/style-guide/typescript/nextjs` |
|
|
103
|
+
| react-library | `@yoshinani/style-guide/typescript/react-library` |
|
|
183
104
|
|
|
184
105
|
共有 TypeScript 設定を使うには、`tsconfig.json` に以下のように記載します。
|
|
185
106
|
|
|
186
107
|
```json
|
|
187
108
|
{
|
|
188
|
-
"extends": "@yoshinani/style-guide/typescript
|
|
109
|
+
"extends": "@yoshinani/style-guide/typescript"
|
|
189
110
|
}
|
|
190
111
|
```
|
|
191
112
|
|
package/eslint/base.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
const { resolve } = require("node:path")
|
|
2
|
+
|
|
3
|
+
const project = resolve(process.cwd(), "tsconfig.json")
|
|
4
|
+
|
|
5
|
+
/** @type {import("eslint").Linter.Config} */
|
|
6
|
+
module.exports = {
|
|
7
|
+
settings: {
|
|
8
|
+
"import/resolver": {
|
|
9
|
+
typescript: {
|
|
10
|
+
project,
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
plugins: ["@typescript-eslint", "eslint-plugin-import"],
|
|
15
|
+
rules: {
|
|
16
|
+
eqeqeq: ["error", "always", { null: "ignore" }],
|
|
17
|
+
"@typescript-eslint/no-confusing-void-expression": [
|
|
18
|
+
"error",
|
|
19
|
+
{ ignoreArrowShorthand: true },
|
|
20
|
+
],
|
|
21
|
+
"@typescript-eslint/no-shadow": "off",
|
|
22
|
+
"@typescript-eslint/no-misused-promises": [
|
|
23
|
+
"error",
|
|
24
|
+
{ checksVoidReturn: { attributes: false } },
|
|
25
|
+
],
|
|
26
|
+
"@typescript-eslint/restrict-template-expressions": [
|
|
27
|
+
"error",
|
|
28
|
+
{
|
|
29
|
+
allowAny: false,
|
|
30
|
+
allowBoolean: false,
|
|
31
|
+
allowNullish: false,
|
|
32
|
+
allowRegExp: false,
|
|
33
|
+
allowNever: false,
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
// sort import statements
|
|
37
|
+
"import/order": [
|
|
38
|
+
"warn",
|
|
39
|
+
{
|
|
40
|
+
groups: [
|
|
41
|
+
"builtin",
|
|
42
|
+
"external",
|
|
43
|
+
"internal",
|
|
44
|
+
"parent",
|
|
45
|
+
"sibling",
|
|
46
|
+
"index",
|
|
47
|
+
],
|
|
48
|
+
"newlines-between": "always",
|
|
49
|
+
alphabetize: { order: "asc" },
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
// sort named imports within an import statement
|
|
53
|
+
"sort-imports": ["warn", { ignoreDeclarationSort: true }],
|
|
54
|
+
"no-restricted-syntax": [
|
|
55
|
+
"error",
|
|
56
|
+
{
|
|
57
|
+
selector: "TSEnumDeclaration",
|
|
58
|
+
message:
|
|
59
|
+
"TSのenumには様々な問題があります。enum as constを使用してください。",
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
selector: "ForInStatement",
|
|
63
|
+
message: "for文は使わず、forEach、map、filterなどを使用してください。",
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
selector: "ForOfStatement",
|
|
67
|
+
message: "for文は使わず、forEach、map、filterなどを使用してください。",
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
selector: "LabeledStatement",
|
|
71
|
+
message:
|
|
72
|
+
"Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.",
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
selector: "WithStatement",
|
|
76
|
+
message:
|
|
77
|
+
"`with` is disallowed in strict mode because it makes code impossible to predict and optimize.",
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
"no-process-env": "error",
|
|
81
|
+
"no-restricted-imports": [
|
|
82
|
+
"warn",
|
|
83
|
+
{
|
|
84
|
+
paths: [
|
|
85
|
+
{
|
|
86
|
+
name: "yup",
|
|
87
|
+
message: "valibotを使用してください。",
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: "@material-tailwind/react",
|
|
91
|
+
message: "shadcn/uiを使用してください。",
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
name: "dayjs",
|
|
95
|
+
message: "date-fnsを使用してください。",
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
patterns: [
|
|
99
|
+
{
|
|
100
|
+
group: ["lodash/*"],
|
|
101
|
+
message: "remedaを使用してください。",
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
},
|
|
107
|
+
overrides: [
|
|
108
|
+
{
|
|
109
|
+
files: [
|
|
110
|
+
"*.config.{mjs,ts}",
|
|
111
|
+
"app/**/{page,layout,not-found,*error,opengraph-image,apple-icon}.tsx",
|
|
112
|
+
"app/**/{sitemap,robots}.ts",
|
|
113
|
+
],
|
|
114
|
+
rules: {
|
|
115
|
+
"import/no-default-export": "off",
|
|
116
|
+
"import/prefer-default-export": ["error", { target: "any" }],
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
files: ["env.ts"],
|
|
121
|
+
rules: {
|
|
122
|
+
"@typescript-eslint/dot-notation": "off",
|
|
123
|
+
"no-process-env": "off",
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
files: ["*.ts", "*.tsx"],
|
|
128
|
+
rules: {
|
|
129
|
+
"func-names": "off",
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const { resolve } = require("node:path")
|
|
2
|
+
|
|
3
|
+
const project = resolve(process.cwd(), "tsconfig.json")
|
|
4
|
+
|
|
5
|
+
/** @type {import("eslint").Linter.Config} */
|
|
6
|
+
module.exports = {
|
|
7
|
+
extends: [
|
|
8
|
+
"eslint:recommended",
|
|
9
|
+
"prettier",
|
|
10
|
+
require.resolve("@vercel/style-guide/eslint/node"),
|
|
11
|
+
require.resolve("@vercel/style-guide/eslint/typescript"),
|
|
12
|
+
require.resolve("./base"),
|
|
13
|
+
],
|
|
14
|
+
plugins: ["only-warn"],
|
|
15
|
+
globals: {
|
|
16
|
+
React: true,
|
|
17
|
+
JSX: true,
|
|
18
|
+
},
|
|
19
|
+
env: {
|
|
20
|
+
node: true,
|
|
21
|
+
},
|
|
22
|
+
settings: {
|
|
23
|
+
"import/resolver": {
|
|
24
|
+
typescript: {
|
|
25
|
+
project,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
ignorePatterns: [
|
|
30
|
+
// Ignore dotfiles
|
|
31
|
+
".*.js",
|
|
32
|
+
"node_modules/",
|
|
33
|
+
"dist/",
|
|
34
|
+
],
|
|
35
|
+
overrides: [
|
|
36
|
+
{
|
|
37
|
+
files: ["*.js?(x)", "*.ts?(x)"],
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
}
|
package/eslint/next.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const { resolve } = require("node:path")
|
|
2
|
+
|
|
3
|
+
const project = resolve(process.cwd(), "tsconfig.json")
|
|
4
|
+
|
|
5
|
+
/** @type {import("eslint").Linter.Config} */
|
|
6
|
+
module.exports = {
|
|
7
|
+
extends: [
|
|
8
|
+
"eslint:recommended",
|
|
9
|
+
"prettier",
|
|
10
|
+
require.resolve("@vercel/style-guide/eslint/next"),
|
|
11
|
+
require.resolve("./base"),
|
|
12
|
+
],
|
|
13
|
+
globals: {
|
|
14
|
+
React: true,
|
|
15
|
+
JSX: true,
|
|
16
|
+
},
|
|
17
|
+
env: {
|
|
18
|
+
node: true,
|
|
19
|
+
browser: true,
|
|
20
|
+
},
|
|
21
|
+
plugins: ["only-warn"],
|
|
22
|
+
settings: {
|
|
23
|
+
"import/resolver": {
|
|
24
|
+
typescript: {
|
|
25
|
+
project,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
ignorePatterns: [
|
|
30
|
+
// Ignore dotfiles
|
|
31
|
+
".*.js",
|
|
32
|
+
"node_modules/",
|
|
33
|
+
],
|
|
34
|
+
overrides: [{ files: ["*.js?(x)", "*.ts?(x)"] }],
|
|
35
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const { resolve } = require("node:path")
|
|
2
|
+
|
|
3
|
+
const project = resolve(process.cwd(), "tsconfig.json")
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* This is a custom ESLint configuration for use with
|
|
7
|
+
* internal (bundled by their consumer) libraries
|
|
8
|
+
* that utilize React.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** @type {import("eslint").Linter.Config} */
|
|
12
|
+
module.exports = {
|
|
13
|
+
extends: [
|
|
14
|
+
"eslint:recommended",
|
|
15
|
+
"prettier",
|
|
16
|
+
"turbo",
|
|
17
|
+
require.resolve("@vercel/style-guide/eslint/react"),
|
|
18
|
+
require.resolve("./base"),
|
|
19
|
+
],
|
|
20
|
+
plugins: ["only-warn"],
|
|
21
|
+
globals: {
|
|
22
|
+
React: true,
|
|
23
|
+
},
|
|
24
|
+
env: {
|
|
25
|
+
browser: true,
|
|
26
|
+
},
|
|
27
|
+
settings: {
|
|
28
|
+
"import/resolver": {
|
|
29
|
+
typescript: {
|
|
30
|
+
project,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
ignorePatterns: [
|
|
35
|
+
// Ignore dotfiles
|
|
36
|
+
".*.js",
|
|
37
|
+
"node_modules/",
|
|
38
|
+
"dist/",
|
|
39
|
+
],
|
|
40
|
+
overrides: [
|
|
41
|
+
// Force ESLint to detect .tsx files
|
|
42
|
+
{ files: ["*.js?(x)", "*.ts?(x)"] },
|
|
43
|
+
],
|
|
44
|
+
}
|
package/package.json
CHANGED
|
@@ -1,20 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yoshinani/style-guide",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Yoshinani's Style Guide",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./typescript": "./typescript/base.json",
|
|
7
7
|
"./typescript/nextjs": "./typescript/nextjs.json",
|
|
8
|
-
"./typescript/react-library": "./typescript/react-library.json"
|
|
8
|
+
"./typescript/react-library": "./typescript/react-library.json",
|
|
9
|
+
"./eslint/*": "./eslint/*.js"
|
|
9
10
|
},
|
|
10
11
|
"files": [
|
|
11
|
-
"typescript"
|
|
12
|
+
"typescript",
|
|
13
|
+
"eslint"
|
|
12
14
|
],
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@typescript-eslint/eslint-plugin": "^8.18.2",
|
|
17
|
+
"@typescript-eslint/parser": "^8.18.2",
|
|
18
|
+
"@vercel/style-guide": "^6.0.0",
|
|
19
|
+
"eslint-config-prettier": "^9.1.0",
|
|
20
|
+
"eslint-plugin-import": "^2.31.0",
|
|
21
|
+
"eslint-plugin-only-warn": "^1.1.0",
|
|
22
|
+
"eslint-plugin-tailwindcss": "^3.17.5"
|
|
23
|
+
},
|
|
13
24
|
"devDependencies": {
|
|
14
25
|
"@commitlint/cli": "^19.8.0",
|
|
15
26
|
"@commitlint/config-conventional": "^19.8.0",
|
|
16
27
|
"husky": "^9.1.7"
|
|
17
28
|
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"eslint": "^8"
|
|
31
|
+
},
|
|
18
32
|
"packageManager": "pnpm@9.15.4+sha512.b2dc20e2fc72b3e18848459b37359a32064663e5627a51e4c74b2c29dd8e8e0491483c3abb40789cfd578bf362fb6ba8261b05f0387d76792ed6e23ea3b1b6a0",
|
|
19
33
|
"scripts": {
|
|
20
34
|
"prepare": "husky"
|