Skip to content

Commit

Permalink
Add ESLint flat config support (#476)
Browse files Browse the repository at this point in the history
* feat: add ESLint flat config support to @topotal/eslint-config-typescript and @topotal/eslint-config-react

Co-Authored-By: [email protected] <[email protected]>

* refactor: improve flat config implementation to follow ESLint guidelines

Co-Authored-By: [email protected] <[email protected]>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: [email protected] <[email protected]>
  • Loading branch information
devin-ai-integration[bot] and sawa-zen authored Feb 26, 2025
1 parent 7932ba0 commit a08af58
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 8 deletions.
20 changes: 19 additions & 1 deletion packages/eslint-config-react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ yarn add -D eslint-plugin-react eslint-plugin-react-hooks

## Usage

Add `@topotal/eslunt-config-react` to `eslintrc` extends.
### Legacy ESLint Configuration (ESLint v8 and below)

Add `@topotal/eslint-config-react` to `eslintrc` extends.

```json
{
Expand All @@ -27,3 +29,19 @@ Add `@topotal/eslunt-config-react` to `eslintrc` extends.
]
}
```

### Flat ESLint Configuration (ESLint v9 and above)

In your `eslint.config.js`:

```js
const topotalReactConfig = require('@topotal/eslint-config-react/flat');

// Or using the conditional exports (recommended)
// const { flat: topotalReactConfig } = require('@topotal/eslint-config-react');

module.exports = [
topotalReactConfig,
// other configs...
];
```
33 changes: 33 additions & 0 deletions packages/eslint-config-react/flat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const reactPlugin = require('eslint-plugin-react');
const reactHooksPlugin = require('eslint-plugin-react-hooks');

module.exports = {
files: ['**/*.{jsx,tsx}'],
settings: {
react: {
pragma: 'React',
version: 'detect'
}
},
plugins: {
'react': reactPlugin,
'react-hooks': reactHooksPlugin,
},
rules: {
'react/jsx-quotes': 0,
'jsx-quotes': 'error',
'react/self-closing-comp': ['error', {
'component': true,
'html': true
}],
'react-hooks/exhaustive-deps': ['error', {
'additionalHooks': '(useAsync|useAsyncFn)'
}],
'react/jsx-key': ['error'],
'react/jsx-newline': ['error', { 'prevent': true }],
'react/prop-types': 'off',
'react/display-name': 'off',
'react/jsx-uses-react': 'off',
'react/react-in-jsx-scope': 'off',
}
};
18 changes: 15 additions & 3 deletions packages/eslint-config-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@topotal/eslint-config-react",
"version": "0.3.5",
"version": "0.4.0",
"description": "This is a common ESlint setting for React used within Topotal",
"homepage": "https://github.com/topotal/js-sdk#readme",
"bugs": {
Expand All @@ -14,13 +14,25 @@
"license": "MIT",
"author": "SAWADA Takayoshi <[email protected]>",
"main": "index.js",
"files": [
"index.js",
"flat.js"
],
"exports": {
".": {
"import": "./index.js",
"require": "./index.js"
},
"./flat": "./flat.js"
},
"devDependencies": {
"eslint-plugin-react": "^7.28.0",
"eslint-plugin-react-hooks": "^4.3.0"
},
"peerDependencies": {
"eslint-plugin-react": "7.x",
"eslint-plugin-react-hooks": "4.x"
"eslint": ">=6.0.0",
"eslint-plugin-react": ">=7.0.0",
"eslint-plugin-react-hooks": ">=4.0.0"
},
"publishConfig": {
"access": "public"
Expand Down
20 changes: 19 additions & 1 deletion packages/eslint-config-typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ yarn add -D @typescript-eslint/eslint-plugin @typescript-eslint/parser

## Usage

Add `@topotal/eslunt-config-typescript` to `eslintrc` extends.
### Legacy ESLint Configuration (ESLint v8 and below)

Add `@topotal/eslint-config-typescript` to `eslintrc` extends.

```json
{
Expand All @@ -27,3 +29,19 @@ Add `@topotal/eslunt-config-typescript` to `eslintrc` extends.
]
}
```

### Flat ESLint Configuration (ESLint v9 and above)

In your `eslint.config.js`:

```js
const topotalTypescriptConfig = require('@topotal/eslint-config-typescript/flat');

// Or using the conditional exports (recommended)
// const { flat: topotalTypescriptConfig } = require('@topotal/eslint-config-typescript');

module.exports = [
topotalTypescriptConfig,
// other configs...
];
```
34 changes: 34 additions & 0 deletions packages/eslint-config-typescript/flat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const typescriptEslint = require('@typescript-eslint/eslint-plugin');
const typescriptParser = require('@typescript-eslint/parser');

module.exports = {
files: ['**/*.{ts,tsx}'],
languageOptions: {
parser: typescriptParser,
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
plugins: {
'@typescript-eslint': typescriptEslint,
},
rules: {
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-empty-function': 'off',
// Indent setting
'indent': 'off',
'@typescript-eslint/indent': ['error', 2, {'SwitchCase': 1}],
// Disallow unused variables
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{
'argsIgnorePattern': '^_',
'ignoreRestSiblings': true
}
],
}
};
18 changes: 15 additions & 3 deletions packages/eslint-config-typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@topotal/eslint-config-typescript",
"version": "0.2.5",
"version": "0.3.0",
"description": "This is a common ESlint setting for TypeScript used within Topotal",
"homepage": "https://github.com/topotal/js-sdk#readme",
"bugs": {
Expand All @@ -13,13 +13,25 @@
"license": "MIT",
"author": "sawa-zen <[email protected]>",
"main": "main.js",
"files": [
"main.js",
"flat.js"
],
"exports": {
".": {
"import": "./main.js",
"require": "./main.js"
},
"./flat": "./flat.js"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.10.2",
"@typescript-eslint/parser": "^5.10.2"
},
"peerDependencies": {
"@typescript-eslint/eslint-plugin": "4.x",
"@typescript-eslint/parser": "4.x"
"@typescript-eslint/eslint-plugin": ">=4.0.0",
"@typescript-eslint/parser": ">=4.0.0",
"eslint": ">=6.0.0"
},
"publishConfig": {
"access": "public"
Expand Down

0 comments on commit a08af58

Please sign in to comment.