Skip to content

Commit

Permalink
fix: config error.
Browse files Browse the repository at this point in the history
  • Loading branch information
lvjiaxuan committed Feb 21, 2023
1 parent 9c28346 commit e3f0f32
Show file tree
Hide file tree
Showing 16 changed files with 659 additions and 168 deletions.
12 changes: 3 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,17 @@
"scripts": {
"lint": "eslint .",
"test": "nr -r test",
"prepare": "nr -r stub",
"build": "nr -r build"
"prepare": "nr -r build"
},
"devDependencies": {
"@lvjiaxuan/eslint-plugin": "workspace:*",
"@types/semver": "^7.3.13",
"chalk": "^5.2.0",
"enquirer": "^2.3.6",
"eslint": "^8.34.0",
"execa": "^7.0.0",
"semver": "^7.3.8",
"tsup": "^6.6.3",
"typescript": "^4.9.5"
},
"eslintConfig": {
"root": true,
"extends": [
"plugin:@lvjiaxuan/recommended"
]
"extends": "plugin:@lvjiaxuan/recommended"
}
}
2 changes: 1 addition & 1 deletion packages/all/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ try {
const cwd = process.cwd()

// Install
execaSync('ni', [ '@lvjiaxuan/eslint-config', 'eslint', '-D' ], { stdio: 'inherit', cwd })
execaSync('ni', [ '@lvjiaxuan/eslint-config', 'eslint', '-D', '--workspace-root=true' ], { stdio: 'inherit', cwd })

// Setup
const pkgPath = path.resolve(cwd, 'package.json')
Expand Down
13 changes: 6 additions & 7 deletions packages/all/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@
"name": "@lvjiaxuan/eslint-config",
"version": "0.5.1",
"private": false,
"description": "Lvjiaxuan's ESLint config",
"author": "lvjiaxuan <471501748@qq.com> (https://github.com/lvjiaxuan)",
"license": "MIT",
"homepage": "https://github.com/lvjiaxuan/@lvjiaxuan/eslint-config-monorepo#README.md",
"keywords": [
"eslint-config"
],
"scripts": {
"build": "nix tsup add.ts --target=node16",
"prepublishOnly": "nr build"
},
"main": "index.js",
"bin": "./bin/add.mjs",
"files": [
"dist",
"!./add.js"
],
"main": "index.js",
"bin": "./bin/add.mjs",
"scripts": {
"build": "tsup add.ts --target=node16",
"prepublishOnly": "nr build"
},
"peerDependencies": {
"eslint": ">=8"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ try {
const cwd = process.cwd()

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

// Setup
const pkgPath = path.resolve(cwd, 'package.json')
Expand Down
9 changes: 5 additions & 4 deletions packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
"eslintplugin",
"eslint-plugin"
],
"main": "./dist/src/index.cjs",
"main": "./dist/src/index.js",
"module": "./dist/src/index.mjs",
"types": "./dist/src/index.d.ts",
"bin": "./bin/add.mjs",
"files": [
"dist",
Expand All @@ -18,12 +19,11 @@
"scripts": {
"dev": "vitest",
"test": "vitest run",
"build": "nix tsup src/index.ts add.ts --target=node16 --format=esm,cjs --splitting",
"build": "tsup",
"prepublishOnly": "nr build"
},
"peerDependencies": {
"eslint": ">=8",
"typescript": ">=4"
"eslint": ">=8"
},
"dependencies": {
"@lvjiaxuan/eslint-config": "workspace:*",
Expand All @@ -32,6 +32,7 @@
},
"devDependencies": {
"@types/lodash.merge": "^4.6.7",
"@types/node": "^18.14.0",
"eslint": "^8.34.0",
"vitest": "^0.18.1"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/configs/recommended.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default {
extends: '@lvjiaxuan',
plugins: '@lvjiaxuan',
plugins: [ '@lvjiaxuan' ],
rules: {
'@lvjiaxuan/prefer-constraint-tuple-type': 'warn',
'@lvjiaxuan/no-multi-empty-lines-in-pattern': 'warn',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,95 +7,90 @@ const ruleTester = new ESLintUtils.RuleTester({ parser: '@typescript-eslint/pars
// Maybe it could represent the other 3, which are ObjectPattern\ArrayExpression\ArrayPattern
describe('ObjectExpression', () => {

it('base', () => {
ruleTester.run(RULE_NAME, rule, {
valid: [
'const obj = { // valid' +
it('base', () => ruleTester.run(RULE_NAME, rule, {
valid: [
'const obj = { // valid' +
'\n a: 1, // valid' +
'\n b: { // valid' +
'\n bb: 22 // valid' +
'\n // valid' +
'\n } // valid' +
'\n} // valid',
],
invalid: [
{
code: `const obj = { // valid
],
invalid: [
{
code: `const obj = { // valid
a: 1, // valid
// valid
} // valid`,
output: `const obj = { // valid
output: `const obj = { // valid
a: 1, // valid
// valid
} // valid`,
errors: [
{
column: 1,
endColumn: 1,
line: 5,
endLine: 6,
messageId: 'noEmptyLine',
data: { linesCount: 2, maxLines: 0, patternType: '{ ... }' },
},
],
},
],
})
})

it('afterMaxLines is 2', () => {
ruleTester.run(RULE_NAME, rule, {
valid: [
{
code: `const obj = { // valid
errors: [
{
column: 1,
endColumn: 1,
line: 5,
endLine: 6,
messageId: 'noEmptyLine',
data: { linesCount: 2, maxLines: 0, patternType: '{ ... }' },
},
],
},
],
}))

it('afterMaxLines is 2', () => ruleTester.run(RULE_NAME, rule, {
valid: [
{
code: `const obj = { // valid
a: 1, // valid
// valid
} // valid`,
// @ts-ignore
options: [ { afterMaxLines: 2 } ],
},
],
invalid: [
{
code: `const obj = { // valid
// @ts-ignore
options: [ { afterMaxLines: 2 } ],
},
],
invalid: [
{
code: `const obj = { // valid
a: 1, // valid
// valid
} // valid`,
output: `const obj = { // valid
output: `const obj = { // valid
a: 1, // valid
// valid
} // valid`,
errors: [
{
messageId: 'noEmptyLine',
line: 4,
endLine: 4,
},
],
// @ts-ignore
options: [ { afterMaxLines: 2 } ],
},
],
})
})

it('with nested', () => {
ruleTester.run(RULE_NAME, rule, {
valid: [],
invalid: [
{
code: `const obj = { // valid
errors: [
{
messageId: 'noEmptyLine',
line: 4,
endLine: 4,
},
],
// @ts-ignore
options: [ { afterMaxLines: 2 } ],
},
],
}))

it('with nested', () => ruleTester.run(RULE_NAME, rule, {
valid: [],
invalid: [
{
code: `const obj = { // valid
a: 1, // valid
b: { // valid
bb: 22 // valid
Expand All @@ -107,26 +102,24 @@ b: { // valid
} // valid`,
output: `const obj = { // valid
output: `const obj = { // valid
a: 1, // valid
b: { // valid
bb: 22 // valid
// valid
} // valid
// valid
} // valid`,
errors: [ { messageId: 'noEmptyLine' }, { messageId: 'noEmptyLine' } ],
},
],
})
})
errors: [ { messageId: 'noEmptyLine' }, { messageId: 'noEmptyLine' } ],
},
],
}))

it('beforeMaxLines is 1', () => {
ruleTester.run(RULE_NAME, rule, {
valid: [],
invalid: [
{
code: `const obj = { // valid
it('beforeMaxLines is 1', () => ruleTester.run(RULE_NAME, rule, {
valid: [],
invalid: [
{
code: `const obj = { // valid
// valid
Expand All @@ -137,26 +130,25 @@ b: { // valid
} // valid`,
output: `const obj = { // valid
output: `const obj = { // valid
// valid
a: 1, // valid
// valid
} // valid`,
errors: [
{
messageId: 'noEmptyLine',
line: 3,
endLine: 3,
},
{ messageId: 'noEmptyLine' },
],
// @ts-ignore
options: [ { beforeMaxLines: 1 } ],
},
],
})
})
errors: [
{
messageId: 'noEmptyLine',
line: 3,
endLine: 3,
},
{ messageId: 'noEmptyLine' },
],
// @ts-ignore
options: [ { beforeMaxLines: 1 } ],
},
],
}))
})
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ const createRule = ESLintUtils.RuleCreator(

export const RULE_NAME = 'no-multi-empty-lines-in-pattern'

interface BaseOptions {
export interface BaseOptions {
afterMaxLines: number
beforeMaxLines: number
}

interface PatternOptions {
export interface PatternOptions {
ObjectExpression?: BaseOptions
ObjectPattern?: BaseOptions
ArrayExpression?: BaseOptions
ArrayPattern?: BaseOptions
}

export default createRule({
export default createRule<[BaseOptions] | [PatternOptions] | [ BaseOptions, PatternOptions ], 'noEmptyLine'>({
name: RULE_NAME,

meta: {
Expand Down Expand Up @@ -116,13 +116,13 @@ export default createRule({
} else {
// [ BaseOptions, PatternOptions ]

const { afterMaxLines = 0, beforeMaxLines = Infinity } = options[0] as BaseOptions
const { afterMaxLines = 0, beforeMaxLines = Infinity } = options[0]

const mergeBaseOptions = lodashMerge(defaultBaseOptions, { afterMaxLines, beforeMaxLines })

Object.keys(options[1])
.forEach(nodeType => patternOptions[nodeType as keyof PatternOptions] =
(options[1] as PatternOptions)[nodeType as keyof PatternOptions]
options[1][nodeType as keyof PatternOptions]
? lodashMerge(
JSON.parse(JSON.stringify(mergeBaseOptions)) as BaseOptions,
patternOptions[nodeType as keyof PatternOptions],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { it } from 'vitest'

const ruleTester = new ESLintUtils.RuleTester({ parser: '@typescript-eslint/parser' })

it('runs', () => {

it('runs', () =>
ruleTester.run(RULE_NAME, rule, {
valid: [
// base
Expand All @@ -22,5 +21,4 @@ it('runs', () => {
},
// template strings
],
})
})
}))

0 comments on commit e3f0f32

Please sign in to comment.