Skip to content

Commit

Permalink
feat(eslint): split ESLint config into specialised parts (#19)
Browse files Browse the repository at this point in the history
Resolves #14

## 📑 Description

Split the ESLint config into specialized parts. For now, we use "base", "next" and "react" as separated configurations. Base is the default.


## ⚠️ BREAKING CHANGE

The default config is now only "base", instead of all of them.

## ✏️ Side Note

To ignore the `.changeset` folder from prettier, I added a custom ignore file.
  • Loading branch information
mheob authored Aug 26, 2022
1 parent 14c7cd1 commit 6e97fe2
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 49 deletions.
6 changes: 3 additions & 3 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works with multi-package
repos, or single-package repos to help you version and publish your code. You can find the full documentation for it
[in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
5 changes: 5 additions & 0 deletions .changeset/fresh-brooms-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@mheob/eslint-config": patch
---

Improve README to get a better copy/paste experience.
5 changes: 5 additions & 0 deletions .changeset/short-worms-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@mheob/eslint-config": major
---

Split ESLint configuration into specified files (base/reat/next for now).
11 changes: 11 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Changeset
.changeset

# dependencies
node_modules

# testing
coverage

# turbo
.turbo
4 changes: 4 additions & 0 deletions packages/eslint-config/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
extends: ['./base.js'],
env: { node: true },
};
84 changes: 57 additions & 27 deletions packages/eslint-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,64 @@

To make my configurations a bit easier I share my [ESLint](https://eslint.org/) config.

## Usage
## Install

### Install
### With NPM

```sh
# with npm
npm install -D @mheob/eslint-config
```

### With YARN

# with yarn
```sh
yarn add -D @mheob/eslint-config
```

# with pnpm
### With PNPM

```sh
pnpm add -D @mheob/eslint-config
```

### Include in your project
## Usage

#### Simple: Edit `package.json`
### Basic Rules only

```jsonc
{
// ...
"eslint": {
"extends": "@mheob/eslint-config"
}
}
```js
// .eslintrc.cjs
module.exports = {
root: true, // optional
extends: ['@mheob/eslint-config'],
};
```

#### Or with override settings
### React and Basic Rules (`@mheob/eslint-config/react`)

If you need to override some settings you can do it this way:
```js
// .eslintrc.cjs
module.exports = {
root: true, // optional
extends: ['@mheob/eslint-config/react'],
};
```

### NextJS and Basic Rules (`@mheob/eslint-config/next`)

```js
// .eslintrc.cjs
module.exports = {
root: true, // optional
extends: ['@mheob/eslint-config/next'],
};
```

If you need to override some rules you can do it this way:

```js
// .eslintrc.cjs
module.exports = {
root: true,
root: true, // optional
extends: ['@mheob/eslint-config'],
rules: {
'prettier/prettier': 'off',
Expand All @@ -46,14 +68,22 @@ module.exports = {
};
```

## Ruleset

This configuration uses these external ESLint packages:
Or override rules specified for some files:

- [`@typescript-eslint/eslint-plugin`](https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/eslint-plugin)
- [`@typescript-eslint/parser`](https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/parser)
- [`eslint-config-next`](https://github.com/vercel/next.js/tree/canary/packages/eslint-config-next)
- [`eslint-config-prettier`](https://github.com/prettier/eslint-config-prettier)
- [`eslint-plugin-prettier`](https://github.com/prettier/eslint-plugin-prettier)
- [`eslint-plugin-react`](https://github.com/jsx-eslint/eslint-plugin-react)
- [`eslint-plugin-unicorn`](https://github.com/sindresorhus/eslint-plugin-unicorn)
```js
// .eslintrc.cjs
module.exports = {
root: true, // optional
extends: ['@mheob/eslint-config'],
overrides: [
{
files: ['*.jsx', '*.tsx'],
settings: { react: { version: 'detect' } },
rules: {
'react/jsx-no-useless-fragment': 'warn',
'react/react-in-jsx-scope': 'off',
},
},
],
};
```
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
/** @type {import('eslint').ESLint.ConfigData} */
/**
* Base ESLint rules
* @type {import('eslint').ESLint.ConfigData}
*/
module.exports = {
plugins: ['@typescript-eslint'],
extends: ['eslint:recommended', 'plugin:unicorn/recommended', 'plugin:prettier/recommended'],
settings: {
react: {
version: 'detect',
},
},
rules: {
'prettier/prettier': 'warn',
'no-console': ['warn', { allow: ['warn', 'error'] }],
Expand Down Expand Up @@ -44,16 +42,5 @@ module.exports = {
],
},
},
{
files: ['*.jsx', '*.tsx'],
extends: ['plugin:eslint-plugin-react/recommended', 'next/core-web-vitals'],
settings: { react: { version: 'detect' } },
rules: {
'react/jsx-curly-brace-presence': ['warn', { props: 'never', children: 'never' }],
'react/jsx-no-useless-fragment': 'warn',
'react/react-in-jsx-scope': 'off',
'unicorn/filename-case': ['error', { case: 'pascalCase' }],
},
},
],
};
1 change: 1 addition & 0 deletions packages/eslint-config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./base');
7 changes: 7 additions & 0 deletions packages/eslint-config/next.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* NextJS specific ESLint rules
* @type {import('eslint').ESLint.ConfigData}
*/
module.exports = {
extends: ['./react', 'next/core-web-vitals'],
};
7 changes: 5 additions & 2 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
"author": "Alexander Böhm <[email protected]>",
"main": "index.cjs",
"files": [
"index.cjs",
"index.js",
"base.js",
"next.js",
"react.js",
"LICENSE",
"README.md"
],
"scripts": {
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
"lint": "TIMING=1 eslint src/**/*.ts* --fix"
"lint": "TIMING=1 eslint **/*.cjs --fix"
},
"dependencies": {
"@typescript-eslint/eslint-plugin": "^5.35.1",
Expand Down
24 changes: 24 additions & 0 deletions packages/eslint-config/react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* React specific ESLint rules
* @type {import('eslint').ESLint.ConfigData}
*/
module.exports = {
extends: ['./base', 'plugin:eslint-plugin-react/recommended'],
settings: {
react: {
version: 'detect',
},
},
overrides: [
{
files: ['*.jsx', '*.tsx'],
settings: { react: { version: 'detect' } },
rules: {
'react/jsx-curly-brace-presence': ['warn', { props: 'never', children: 'never' }],
'react/jsx-no-useless-fragment': 'warn',
'react/react-in-jsx-scope': 'off',
'unicorn/filename-case': ['error', { case: 'pascalCase' }],
},
},
],
};

0 comments on commit 6e97fe2

Please sign in to comment.