Skip to content

Commit

Permalink
feat: support flat eslint config
Browse files Browse the repository at this point in the history
  • Loading branch information
azat-io committed May 22, 2023
1 parent e1fb1ad commit 969ae4e
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 2 deletions.
8 changes: 8 additions & 0 deletions configs/recommended-line-length.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import mod from '../index'

export default {
plugins: {
perfectionist: mod,
},
rules: mod.configs['recommended-line-length'].rules,
}
8 changes: 8 additions & 0 deletions configs/recommended-natural.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import mod from '../index'

export default {
plugins: {
perfectionist: mod,
},
rules: mod.configs['recommended-natural'].rules,
}
18 changes: 18 additions & 0 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ export default defineConfig({
link: '/guide/introduction',
activeMatch: '^/guide/',
},
{
text: 'Configs',
link: '/configs/',
activeMatch: '^/configs/',
},
{
text: 'Rules',
link: '/rules/',
Expand Down Expand Up @@ -177,6 +182,19 @@ export default defineConfig({
},
],
},
{
text: 'Configs',
items: [
{
text: 'recommended-natural',
link: '/configs/recommended-natural',
},
{
text: 'recommended-line-length',
link: '/configs/recommended-line-length',
},
],
},
{
text: 'Rules',
items: [
Expand Down
16 changes: 16 additions & 0 deletions docs/configs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
title: Configs
---

# Configs

The easiest way to use `eslint-plugin-perfectionist` is to use ready-made configs. Config files use all the rules of the current plugin, but you can override them.

This plugin provides two configs out of the box.

See the [ESLint docs](https://eslint.org/docs/latest/use/configure/configuration-files#extending-configuration-files) for more information about extending config files.

| Name | Description |
| :---------------------------------------------------------- | :--------------------------------------------------------------- |
| [recommended-natural](/configs/recommended-natural) | All plugin rules with natural sorting in ascending order |
| [recommended-line-length](/configs/recommended-line-length) | All plugin rules with sorting by line length in descending order |
37 changes: 37 additions & 0 deletions docs/configs/recommended-line-length.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
title: recommended-line-length
---

# recommended-line-length

## 馃摉 Details

Configuration for the `eslint-plugin-perfectionist` plugin, which provides all plugin rules with preset options: sorting by string length in descending order.

This configuration will make your code prettier and more pleasing to the eye.

## 鈿欙笍 Usage

### Legacy config

<!-- prettier-ignore -->
```json
// .eslintrc
{
"extends": [
"plugin:perfectionist/recommended-line-length"
]
}
```

### Flat config

<!-- prettier-ignore -->
```js
// eslint.config.js
import perfectionistPluginRecommendedLineLength from 'eslint-plugin-perfectionist/config/recommended-line-length'

export default [
perfectionistPluginRecommendedLineLength
]
```
39 changes: 39 additions & 0 deletions docs/configs/recommended-natural.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
title: recommended-natural
---

# recommended-natural

## 馃摉 Details

Configuration for the `eslint-plugin-perfectionist` plugin, which provides all plugin rules with predefined options: natural sorting in ascending order.

What is the difference between natural sorting and alphabetical sorting? Natural sort compares strings containing a mixture of letters and numbers, just as a human would do when sorting. For example: `item-1`, `item-2`, `item-10`.

This configuration will allow you to navigate through your code faster because all the data that can be safely sorted will be in order.

## 鈿欙笍 Usage

### Legacy config

<!-- prettier-ignore -->
```json
// .eslintrc
{
"extends": [
"plugin:perfectionist/recommended-natural"
]
}
```

### Flat config

<!-- prettier-ignore -->
```js
// eslint.config.js
import perfectionistPluginRecommendedNatural from 'eslint-plugin-perfectionist/config/recommended-natural'

export default [
perfectionistPluginRecommendedNatural
]
```
3 changes: 3 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ hero:
- theme: brand
text: Get Started
link: /guide/introduction
- theme: alt
text: Configs
link: /configs/
- theme: alt
text: Rules
link: /rules/
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./configs": {
"require": "./dist/configs",
"import": "./dist/configs"
},
"./package.json": "./package.json"
},
"peerDependencies": {
Expand Down
16 changes: 14 additions & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,20 @@ import path from 'path'
export default defineConfig({
build: {
lib: {
fileName: format => `index.${format === 'es' ? 'mjs' : 'js'}`,
entry: path.resolve(__dirname, 'index.ts'),
fileName: (format, entryName) => {
let path = ''

if (entryName === 'recommended-line-length' || entryName === 'recommended-natural') {
path = 'configs/'
}

return `${path}${entryName}.${format === 'es' ? 'mjs' : 'js'}`
},
entry: [
path.resolve(__dirname, 'index.ts'),
path.resolve(__dirname, 'configs/recommended-line-length.ts'),
path.resolve(__dirname, 'configs/recommended-natural.ts'),
],
formats: ['cjs', 'es'],
},
rollupOptions: {
Expand Down

0 comments on commit 969ae4e

Please sign in to comment.