add createConfig function
This commit is contained in:
parent
ea232dafca
commit
e4a5dc8865
35
README.md
35
README.md
@ -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
3
index.js
Normal file
@ -0,0 +1,3 @@
|
||||
const createConfig = require('./utils/create-config');
|
||||
|
||||
module.exports = { createConfig };
|
||||
@ -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',
|
||||
|
||||
@ -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',
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vchikalkin/eslint-config-awesome",
|
||||
"version": "1.1.3",
|
||||
"version": "1.1.4",
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
|
||||
7
react-typescript/config.js
vendored
7
react-typescript/config.js
vendored
@ -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: [
|
||||
|
||||
@ -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
30
utils/create-config.js
Normal 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;
|
||||
Loading…
x
Reference in New Issue
Block a user