From 824d4ff33e3c2e8a0083ca531ed5a6b077706a4c Mon Sep 17 00:00:00 2001 From: Carlux Date: Mon, 20 Sep 2021 20:59:09 +0300 Subject: [PATCH] chore: update schema --- lib/rules/jsx-max-props-per-line.js | 61 +++++++++++++---------- tests/lib/rules/jsx-max-props-per-line.js | 44 ++++++++++++---- 2 files changed, 70 insertions(+), 35 deletions(-) diff --git a/lib/rules/jsx-max-props-per-line.js b/lib/rules/jsx-max-props-per-line.js index cdbcce4fae..64691b27c2 100644 --- a/lib/rules/jsx-max-props-per-line.js +++ b/lib/rules/jsx-max-props-per-line.js @@ -26,31 +26,42 @@ module.exports = { }, schema: [{ - type: 'object', - properties: { - maximum: { - oneOf: [{ - type: 'integer', - minimum: 1 - }, { - type: 'object', - properties: { - single: { - type: 'integer', - minimum: 1 - }, - multi: { - type: 'integer', - minimum: 1 + anyOf: [{ + type: 'object', + properties: { + maximum: { + oneOf: [{ + type: 'integer', + minimum: 1 + }, { + type: 'object', + properties: { + single: { + type: 'integer', + minimum: 1 + }, + multi: { + type: 'integer', + minimum: 1 + } } - } - }] + }] + } }, - when: { - type: 'string', - enum: ['always', 'multiline'] + additionalProperties: false + }, { + type: 'object', + properties: { + maximum: { + type: 'number', + minimum: 1 + }, + when: { + type: 'string', + enum: ['always', 'multiline'] + } } - } + }] }] }, @@ -63,8 +74,8 @@ module.exports = { const isExtendedConfig = typeof maximum !== 'number'; if (isExtendedConfig) { - maximumSingle = maximum.single || 1; - maximumMulti = maximum.multi || 1; + maximumSingle = maximum.single || Infinity; + maximumMulti = maximum.multi || Infinity; } const when = isExtendedConfig @@ -129,7 +140,7 @@ module.exports = { linePartitionedProps.forEach((propsInLine) => { if (isExtendedConfig) { - maxPropsCountPerLine = propsInLine[0].loc.start.line === node.loc.start.line + maxPropsCountPerLine = isSingleLineTag && propsInLine[0].loc.start.line === node.loc.start.line ? maximumSingle : maximumMulti; } diff --git a/tests/lib/rules/jsx-max-props-per-line.js b/tests/lib/rules/jsx-max-props-per-line.js index 7002988721..503b0e132a 100644 --- a/tests/lib/rules/jsx-max-props-per-line.js +++ b/tests/lib/rules/jsx-max-props-per-line.js @@ -90,6 +90,38 @@ ruleTester.run('jsx-max-props-per-line', rule, { '/>' ].join('\n'), options: [{maximum: {multi: 2, single: 1}}] + }, { + code: '', + options: [{maximum: {multi: 2}}] + }, { + code: [ + '' + ].join('\n'), + options: [{maximum: {single: 1}}] + }, { + code: [ + '' + ].join('\n'), + options: [{maximum: {single: 2, multi: 2}}] + }, { + code: [ + '' + ].join('\n'), + options: [{maximum: 2}] + }, { + code: [ + '' + ].join('\n'), + options: [{maximum: 1, when: 'multiline'}] } ], @@ -352,8 +384,7 @@ ruleTester.run('jsx-max-props-per-line', rule, { '/>' ].join('\n'), output: [ - '' @@ -361,9 +392,6 @@ ruleTester.run('jsx-max-props-per-line', rule, { options: [{maximum: {single: 1, multi: 2}}], errors: [ { - messageId: 'newLine', - data: {prop: 'bar'} - }, { messageId: 'newLine', data: {prop: 'bor'} }] @@ -406,8 +434,7 @@ ruleTester.run('jsx-max-props-per-line', rule, { '/>' ].join('\n'), output: [ - '