Skip to content

Commit

Permalink
feat(eslint-plugin): add install script.
Browse files Browse the repository at this point in the history
  • Loading branch information
lvjiaxuan committed Feb 20, 2023
1 parent 93178d6 commit 0540225
Show file tree
Hide file tree
Showing 10 changed files with 515 additions and 780 deletions.
22 changes: 6 additions & 16 deletions README.md
Expand Up @@ -7,7 +7,7 @@

## [My custom rules](./packages/eslint-plugin/README.md)

- [@lvjiaxuan/no-spaces-on-empty-line](./packages/eslint-plugin/src/rules/no-spaces-on-empty-line.ts) is deprecated.
- [~~@lvjiaxuan/no-spaces-on-empty-line~~](./packages/eslint-plugin/src/rules/no-spaces-on-empty-line.ts) is deprecated.
- [@lvjiaxuan/prefer-constraint-tuple-type](./packages/eslint-plugin/src/rules/prefer-constraint-tuple-type.ts) is warning by default.
- [@lvjiaxuan/no-multi-empty-lines-in-pattern](./packages/eslint-plugin/src/rules/no-multi-empty-lines-in-pattern.ts) is warning by default.
- [@lvjiaxuan/omit-arrow-curly](./packages/eslint-plugin/src/rules/omit-arrow-curly.ts) is warning by default.
Expand All @@ -16,24 +16,14 @@

Installation:
```bash
ni @lvjiaxuan/eslint-config -D
ni @lvjiaxuan/eslint-config -D # By @antfu/ni
npm i lvjiaxuan/eslint-config -D
pnpm add lvjiaxuan/eslint-config -D
```

*package.json* Setting:
```json
{
"eslintConfig": {
"extends": [
"@lvjiaxuan"
]
}
}
nx @lvjiaxuan/eslint-config # Shortcut
nx @lvjiaxuan/eslint-plugin # Include custom rules
```

> Shortcut(uses [@antfu/ni](https://github.com/antfu/ni)): `nx @lvjiaxuan/eslint-config`
Fix on save. VScode settings as below:
```json
{
Expand All @@ -46,5 +36,5 @@ Fix on save. VScode settings as below:
# Refer

- https://github.com/antfu/eslint-config
- https://eslint.org/
- https://typescript-eslint.io/
- https://eslint.org
- https://typescript-eslint.io
2 changes: 1 addition & 1 deletion packages/all/index.js
@@ -1 +1 @@
module.exports = { extends: [ '@lvjiaxuan/vue' ] }
module.exports = { extends: '@lvjiaxuan/vue' }
2 changes: 1 addition & 1 deletion packages/eslint-plugin/README.md
Expand Up @@ -4,7 +4,7 @@

Installation:
```shell
npm i @lvjiaxuan/eslint-plugin
npm i @lvjiaxuan/eslint-plugin -D
```

*package.json* Setting:
Expand Down
41 changes: 41 additions & 0 deletions packages/eslint-plugin/add.ts
@@ -0,0 +1,41 @@
import { execaSync } from 'execa'
import path from 'node:path'
import fs from 'node:fs'

try {

const cwd = process.cwd()

// Install
execaSync('ni', [ '@lvjiaxuan/eslint-plugin', 'eslint', '-D' ], { stdio: 'inherit', cwd })

// Setup
const pkgPath = path.resolve(cwd, 'package.json')
const pkgInfo = JSON.parse(fs.readFileSync(pkgPath, 'utf-8')) as {
scripts?: { [x: string]: string }
eslintConfig?: {
extends?: string | string[]
}
}
pkgInfo.eslintConfig = pkgInfo.eslintConfig ?? {}

if (typeof pkgInfo.eslintConfig.extends === 'string') {
pkgInfo.eslintConfig.extends = [ pkgInfo.eslintConfig.extends, 'plugin:@lvjiaxuan/recommended' ]
} else if (Array.isArray(pkgInfo.eslintConfig.extends)) {
pkgInfo.eslintConfig.extends = [ ...pkgInfo.eslintConfig.extends, 'plugin:@lvjiaxuan/recommended' ]
} else {
pkgInfo.eslintConfig = { extends: 'plugin:@lvjiaxuan/recommended' }
}

pkgInfo.scripts = pkgInfo.scripts ?? {}
!pkgInfo.scripts.lint && (
pkgInfo.scripts.lint = 'eslint .'
)

fs.writeFileSync(pkgPath, JSON.stringify(pkgInfo, null, 2) + '\n')

process.exit(0)
} catch (error) {
console.error(error)
process.exit(1)
}
3 changes: 3 additions & 0 deletions packages/eslint-plugin/bin/add.mjs
@@ -0,0 +1,3 @@
#!/usr/bin/env node
'use strict'
import '../dist/add.js'
6 changes: 0 additions & 6 deletions packages/eslint-plugin/build.config.ts

This file was deleted.

14 changes: 6 additions & 8 deletions packages/eslint-plugin/package.json
Expand Up @@ -8,16 +8,16 @@
"eslintplugin",
"eslint-plugin"
],
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"main": "./dist/src/index.cjs",
"module": "./dist/src/index.mjs",
"bin": "./bin/add.mjs",
"files": [
"dist"
"!./add.js"
],
"scripts": {
"dev": "vitest omit-arrow-curly.test.ts",
"dev": "vitest",
"test": "vitest run",
"stub": "unbuild --stub",
"build": "unbuild",
"build": "nx tsup src/index.ts add.ts --target=node16 --format=esm,cjs --splitting",
"prepublishOnly": "nr build"
},
"peerDependencies": {
Expand All @@ -31,8 +31,6 @@
"devDependencies": {
"@types/lodash.merge": "^4.6.7",
"eslint": "^8.34.0",
"typescript": "^4.9.5",
"unbuild": "^0.7.6",
"vitest": "^0.18.1"
}
}
4 changes: 2 additions & 2 deletions packages/eslint-plugin/src/configs/recommended.ts
@@ -1,6 +1,6 @@
export default {
extends: [ '@lvjiaxuan' ],
plugins: [ '@lvjiaxuan' ],
extends: '@lvjiaxuan',
plugins: '@lvjiaxuan',
rules: {
'@lvjiaxuan/prefer-constraint-tuple-type': 'warn',
'@lvjiaxuan/no-multi-empty-lines-in-pattern': 'warn',
Expand Down

0 comments on commit 0540225

Please sign in to comment.