diff --git a/configs/recommended-line-length.ts b/configs/recommended-line-length.ts new file mode 100644 index 000000000..b9f786b7a --- /dev/null +++ b/configs/recommended-line-length.ts @@ -0,0 +1,8 @@ +import mod from '../index' + +export default { + plugins: { + perfectionist: mod, + }, + rules: mod.configs['recommended-line-length'].rules, +} diff --git a/configs/recommended-natural.ts b/configs/recommended-natural.ts new file mode 100644 index 000000000..7ab3da81a --- /dev/null +++ b/configs/recommended-natural.ts @@ -0,0 +1,8 @@ +import mod from '../index' + +export default { + plugins: { + perfectionist: mod, + }, + rules: mod.configs['recommended-natural'].rules, +} diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index fc216ab25..c036b72f1 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -146,6 +146,11 @@ export default defineConfig({ link: '/guide/introduction', activeMatch: '^/guide/', }, + { + text: 'Configs', + link: '/configs/', + activeMatch: '^/configs/', + }, { text: 'Rules', link: '/rules/', @@ -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: [ diff --git a/docs/configs/index.md b/docs/configs/index.md new file mode 100644 index 000000000..868b48bb8 --- /dev/null +++ b/docs/configs/index.md @@ -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 | diff --git a/docs/configs/recommended-line-length.md b/docs/configs/recommended-line-length.md new file mode 100644 index 000000000..c3e87c114 --- /dev/null +++ b/docs/configs/recommended-line-length.md @@ -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 + + +```json +// .eslintrc +{ + "extends": [ + "plugin:perfectionist/recommended-line-length" + ] +} +``` + +### Flat config + + +```js +// eslint.config.js +import perfectionistPluginRecommendedLineLength from 'eslint-plugin-perfectionist/config/recommended-line-length' + +export default [ + perfectionistPluginRecommendedLineLength +] +``` diff --git a/docs/configs/recommended-natural.md b/docs/configs/recommended-natural.md new file mode 100644 index 000000000..9a027e76c --- /dev/null +++ b/docs/configs/recommended-natural.md @@ -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 + + +```json +// .eslintrc +{ + "extends": [ + "plugin:perfectionist/recommended-natural" + ] +} +``` + +### Flat config + + +```js +// eslint.config.js +import perfectionistPluginRecommendedNatural from 'eslint-plugin-perfectionist/config/recommended-natural' + +export default [ + perfectionistPluginRecommendedNatural +] +``` diff --git a/docs/index.md b/docs/index.md index 57db6fd70..d27cc65c4 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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/ diff --git a/package.json b/package.json index 6caea1a26..11eaf84c3 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,10 @@ "require": "./dist/index.js", "import": "./dist/index.mjs" }, + "./configs": { + "require": "./dist/configs", + "import": "./dist/configs" + }, "./package.json": "./package.json" }, "peerDependencies": { diff --git a/vite.config.ts b/vite.config.ts index a9d96ec63..a428c8366 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -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: {