-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #154 from hatena/fine-grained-configs
React / Next.js 向けの設定を個別に利用可能にする
- Loading branch information
Showing
6 changed files
with
154 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use strict'; | ||
|
||
const nextPlugin = require('@next/eslint-plugin-next'); | ||
const jsxA11yPlugin = require('eslint-plugin-jsx-a11y'); | ||
const tsEslint = require('typescript-eslint'); | ||
const rules = require('../rules/index.js'); | ||
const reactConfig = require('./react.js'); | ||
|
||
/** | ||
* @typedef ConfigOptions | ||
* @property {boolean | undefined} [strict] | ||
* true の場合, Core Web Vitals に関するルールを追加で有効にする. | ||
* デフォルト: false | ||
*/ | ||
|
||
/** | ||
* Next.js を使用するプロジェクト向けの設定. React 向けの設定も内包している. | ||
* @param {ConfigOptions} [options] オプション | ||
* @returns {import('@typescript-eslint/utils').TSESLint.FlatConfig.ConfigArray} 設定の配列 | ||
*/ | ||
function config(options) { | ||
const strict = options?.strict ?? false; | ||
|
||
// NOTE: files は extends によって一括で上書きされることもある | ||
const defaultFiles = ['**/*.{js,jsx,cjs,mjs}', '**/*.{ts,tsx,cts,mts}']; | ||
|
||
return tsEslint.config( | ||
{ | ||
name: '@hatena/eslint-config-hatena/next/react', | ||
files: defaultFiles, | ||
extends: reactConfig(), | ||
}, | ||
{ | ||
name: '@hatena/eslint-config-hatena/next/plugins', | ||
files: defaultFiles, | ||
plugins: { | ||
'@next/next': nextPlugin, | ||
'jsx-a11y': jsxA11yPlugin, | ||
}, | ||
}, | ||
{ | ||
name: '@hatena/eslint-config-hatena/next/rules', | ||
files: defaultFiles, | ||
extends: [ | ||
{ | ||
rules: { | ||
...nextPlugin.configs.recommended.rules, | ||
...(strict ? nextPlugin.configs['core-web-vitals'].rules : {}), | ||
}, | ||
}, | ||
], | ||
rules: rules.next, | ||
}, | ||
); | ||
} | ||
|
||
module.exports = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
'use strict'; | ||
|
||
const reactPlugin = require('eslint-plugin-react'); | ||
const reactHooksPlugin = require('eslint-plugin-react-hooks'); | ||
const tsEslint = require('typescript-eslint'); | ||
const rules = require('../rules/index.js'); | ||
|
||
/** | ||
* React を使用するプロジェクト向けの設定 | ||
* @returns {import('@typescript-eslint/utils').TSESLint.FlatConfig.ConfigArray} 設定の配列 | ||
*/ | ||
function config() { | ||
// NOTE: files は extends によって一括で上書きされることもある | ||
const defaultFiles = ['**/*.{js,jsx,cjs,mjs}', '**/*.{ts,tsx,cts,mts}']; | ||
|
||
return tsEslint.config( | ||
{ | ||
name: '@hatena/eslint-config-hatena/react/plugins', | ||
files: defaultFiles, | ||
plugins: { | ||
'react': reactPlugin, | ||
'react-hooks': reactHooksPlugin, | ||
}, | ||
settings: { | ||
react: { | ||
version: 'detect', | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: '@hatena/eslint-config-hatena/react/rules', | ||
files: defaultFiles, | ||
extends: [ | ||
{ rules: reactPlugin.configs.recommended.rules }, | ||
{ rules: reactPlugin.configs['jsx-runtime'].rules }, | ||
{ rules: reactHooksPlugin.configs.recommended.rules }, | ||
], | ||
rules: rules.react, | ||
}, | ||
); | ||
} | ||
|
||
module.exports = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.