Skip to content

Commit

Permalink
feat: use prettier-plugin-pkgsort for package.json formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
auvred committed Aug 10, 2023
1 parent deb8101 commit 1e0ee99
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 76 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,44 @@
> Some code snippets were taken from these awesome repos: [`@so1ve/eslint-config`](https://github.com/so1ve/eslint-config), [`@antfu/eslint-config`](https://github.com/antfu/eslint-config)
## Features

- Single quotes, no semi, trailing commas
- Formatting with [Prettier](https://github.com/prettier/prettier)
- Typescript and Vue support out-of-box
- Sortable imports
- Lint also for html, json, yaml, markdown

## Usage

### Install

```
pnpm add -D @auvred/eslint-config eslint prettier
```

### Config `.eslintrc`

```jsonc
{
// don't forget to mark the root config as root
"root": true,
"extends": "@auvred"
}
```

> You don't need .eslintignore normally as it has been provided by the preset.
## Extra configs

### `@auvred/eslint-config/pnpm-workspace`

This config is intended to be used in monorepositories based on [`pnpm`](https://github.com/pnpm/pnpm)

It finds `pnpm-workspace.yaml` in the root of the project, resolves the packages listed there and puts:
- found tsconfigs to the [typescript imports resolver](https://github.com/import-js/eslint-import-resolver-typescript) in the [`import/resolver`](https://github.com/import-js/eslint-plugin-import#importresolver)

- found tsconfigs to the [typescript imports resolver](https://github.com/import-js/eslint-import-resolver-typescript) in the [`import/resolver`](https://github.com/import-js/eslint-plugin-import#importresolver)
- project package names scope to the [`import/internal-regex`](https://github.com/import-js/eslint-plugin-import#importinternal-regex)

```jsonc
{
"extends": ["@auvred", "@auvred/eslint-config/pnpm-workspace"]
Expand All @@ -42,6 +50,7 @@ It finds `pnpm-workspace.yaml` in the root of the project, resolves the packages
## Configure your editor

### coc.nvim

Install [`coc-eslint`](https://github.com/neoclide/coc-eslint) extension

```jsonc
Expand All @@ -61,9 +70,11 @@ Install [`coc-eslint`](https://github.com/neoclide/coc-eslint) extension
]
}
```

> It's better to put these settings to workspace settings (`.vim/coc-settings.json`)
### VS Code

Install [`dbaeumer.vscode-eslint`](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) extension

```jsonc
Expand All @@ -89,13 +100,16 @@ Install [`dbaeumer.vscode-eslint`](https://marketplace.visualstudio.com/items?it
]
}
```

> It's better to put these settings to workspace settings (`.vscode/settings.json`)
### JetBrains IDEs

> If you're working on project with eslint >= 8.23.0, it'd be better to update your IDE to version >= 2022.2.2 because of [this issue](https://youtrack.jetbrains.com/issue/WEB-57089/ESLint8.23-TypeError-this.libOptions.parse-is-not-a-function)
1. Open ESLint settings ([docs](https://www.jetbrains.com/help/webstorm/eslint.html#ws_eslint_configure_scope))
2. Set linting scope to `{**/*,*}.{js,jsx,ts,tsx,vue,html,md,json,jsonc,yaml,yml}`

## License

MIT
76 changes: 3 additions & 73 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const prettierPlugins = ['jsdoc', 'pkgsort'].map(p => 'prettier-plugin-' + p)

const prettierConfig = {
semi: false,
singleQuote: true,
Expand All @@ -6,7 +8,7 @@ const prettierConfig = {
endOfLine: 'lf',
singleAttributePerLine: true,

plugins: ['prettier-plugin-jsdoc'],
plugins: prettierPlugins,
tsdoc: true,
}

Expand Down Expand Up @@ -298,78 +300,6 @@ const config = {
files: ['*.json', '*.json5', '*.jsonc', '.eslintrc'],
parser: 'jsonc-eslint-parser',
},
{
files: ['package.json'],
parser: 'jsonc-eslint-parser',
rules: {
'jsonc/sort-keys': [
'error',
{
pathPattern: '^$',
order: [
'name',
'displayName',
'private',
'preview',
'version',
'packageManager',
'publisher',
'author',
'contributors',
'type',
'description',
'keywords',
'homepage',
'repository',
'bugs',
'funding',
'categories',
'license',
'sideEffects',
'exports',
'bin',
'main',
'module',
'unpkg',
'jsdelivr',
'types',
'typesVersions',
'icon',
'files',
'engines',
'activationEvents',
'contributes',
'eslintConfig',
'publishConfig',
'scripts',
'husky',
'simple-git-hooks',
'lint-staged',
'dependencies',
'devDependencies',
'optionalDependencies',
'peerDependencies',
'peerDependenciesMeta',
'pnpm',
'overrides',
'resolutions',
],
},
{
pathPattern: '^(scripts|exports)$',
order: { type: 'asc' },
},
{
pathPattern: '^(?:dev|peer|optional|bundled)?[Dd]ependencies$',
order: { type: 'asc' },
},
{
pathPattern: '^exports.*$',
order: ['types', 'require', 'import'],
},
],
},
},
{
files: ['*.yaml', '*.yml'],
parser: 'yaml-eslint-parser',
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"license": "MIT",
"main": "index.js",
"files": [
"index.js",
"pnpm-workspace.js",
"utils"
],
Expand Down Expand Up @@ -57,7 +56,8 @@
"find-up": "^5.0.0",
"js-yaml": "^4.1.0",
"jsonc-eslint-parser": "^2.3.0",
"prettier-plugin-jsdoc": "^1.0.1"
"prettier-plugin-jsdoc": "^1.0.1",
"prettier-plugin-pkgsort": "^0.2.1"
},
"devDependencies": {
"bumpp": "^9.1.1",
Expand Down
98 changes: 98 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1e0ee99

Please sign in to comment.