add createConfig function

This commit is contained in:
vchikalkin 2023-11-02 16:02:31 +03:00
parent ea232dafca
commit e4a5dc8865
8 changed files with 62 additions and 35 deletions

View File

@ -12,39 +12,30 @@
yarn add -D eslint @vchikalkin/eslint-config-awesome
```
### ⚙️ Config `.eslintrc`
### ⚙️ Config `.eslintrc.js`
For Next.js
```json
{
"extends": [
"@vchikalkin/eslint-config-awesome/next-typescript/config",
"@vchikalkin/eslint-config-awesome/next-typescript/rules"
]
}
```js
const { createConfig } = require('@vchikalkin/eslint-config-awesome');
module.exports = createConfig('next-typescript'); // or module.exports = createConfig('next');
```
For React
```json
{
"extends": [
"@vchikalkin/eslint-config-awesome/react-typescript/config",
"@vchikalkin/eslint-config-awesome/react-typescript/rules"
]
}
```js
const { createConfig } = require('@vchikalkin/eslint-config-awesome');
module.exports = createConfig('react-typescript'); // or module.exports = createConfig('react');
```
For TypeScript
```json
{
"extends": [
"@vchikalkin/eslint-config-awesome/typescript/config",
"@vchikalkin/eslint-config-awesome/typescript/rules"
]
}
```js
const { createConfig } = require('@vchikalkin/eslint-config-awesome');
module.exports = createConfig('typescript');
```
### Add script for package.json

3
index.js Normal file
View File

@ -0,0 +1,3 @@
const createConfig = require('./utils/create-config');
module.exports = { createConfig };

View File

@ -1,12 +1,14 @@
/** @type {import('eslint').Linter.Config} */
module.exports = {
globals: {
React: true,
JSX: true,
},
env: {
browser: true,
es2022: true,
node: true,
},
parserOptions: {
ecmaVersion: 'latest',
},
parser: '@typescript-eslint/parser',
extends: [
'canonical',

View File

@ -1,12 +1,14 @@
/** @type {import('eslint').Linter.Config} */
module.exports = {
globals: {
React: true,
JSX: true,
},
env: {
browser: true,
es2022: true,
node: true,
},
parserOptions: {
ecmaVersion: 'latest',
},
extends: [
'canonical',
'plugin:sonarjs/recommended',

View File

@ -1,6 +1,6 @@
{
"name": "@vchikalkin/eslint-config-awesome",
"version": "1.1.3",
"version": "1.1.4",
"license": "MIT",
"main": "index.js",
"dependencies": {

View File

@ -1,12 +1,13 @@
/** @type {import('eslint').Linter.Config} */
module.exports = {
globals: {
JSX: true,
},
env: {
browser: true,
es2022: true,
node: true,
},
parserOptions: {
ecmaVersion: 'latest',
},
parser: '@typescript-eslint/parser',
extends: ['canonical', 'plugin:sonarjs/recommended', 'prettier'],
overrides: [

View File

@ -1,12 +1,10 @@
/** @type {import('eslint').Linter.Config} */
module.exports = {
env: {
browser: true,
es2022: true,
node: true,
},
parserOptions: {
ecmaVersion: 'latest',
},
parser: '@typescript-eslint/parser',
extends: ['canonical', 'plugin:sonarjs/recommended', 'prettier'],
overrides: [

30
utils/create-config.js Normal file
View File

@ -0,0 +1,30 @@
const { resolve } = require('node:path');
const project = resolve(process.cwd(), 'tsconfig.json');
/**
* @param {'next'|'next-typescript'|'react'|'react-typescript'|'typescript'} name
* @param {import('eslint').Linter.Config} overrideConfig
*/
function createConfig(name, overrideConfig) {
return {
extends: [
`@vchikalkin/eslint-config-awesome/${name}/config`,
`@vchikalkin/eslint-config-awesome/${name}/rules`,
],
parserOptions: {
project,
},
settings: {
'import/resolver': {
typescript: {
project,
},
},
},
ignorePatterns: ['node_modules/', 'dist/'],
...overrideConfig,
};
}
module.exports = createConfig;