Skip to content

Commit

Permalink
chore: update schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlux committed Sep 20, 2021
1 parent 945c610 commit 824d4ff
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 35 deletions.
61 changes: 36 additions & 25 deletions lib/rules/jsx-max-props-per-line.js
Expand Up @@ -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']
}
}
}
}]
}]
},

Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
44 changes: 34 additions & 10 deletions tests/lib/rules/jsx-max-props-per-line.js
Expand Up @@ -90,6 +90,38 @@ ruleTester.run('jsx-max-props-per-line', rule, {
'/>'
].join('\n'),
options: [{maximum: {multi: 2, single: 1}}]
}, {
code: '<App foo baz bar />',
options: [{maximum: {multi: 2}}]
}, {
code: [
'<App',
' foo bar',
' baz bor',
'/>'
].join('\n'),
options: [{maximum: {single: 1}}]
}, {
code: [
'<App foo bar',
' baz bor',
'/>'
].join('\n'),
options: [{maximum: {single: 2, multi: 2}}]
}, {
code: [
'<App foo bar',
' baz bor',
'/>'
].join('\n'),
options: [{maximum: 2}]
}, {
code: [
'<App foo',
' bar',
'/>'
].join('\n'),
options: [{maximum: 1, when: 'multiline'}]
}
],

Expand Down Expand Up @@ -352,18 +384,14 @@ ruleTester.run('jsx-max-props-per-line', rule, {
'/>'
].join('\n'),
output: [
'<App foo',
'bar',
'<App foo bar',
' bar baz',
'bor',
'/>'
].join('\n'),
options: [{maximum: {single: 1, multi: 2}}],
errors: [
{
messageId: 'newLine',
data: {prop: 'bar'}
}, {
messageId: 'newLine',
data: {prop: 'bor'}
}]
Expand Down Expand Up @@ -406,18 +434,14 @@ ruleTester.run('jsx-max-props-per-line', rule, {
'/>'
].join('\n'),
output: [
'<App boz',
'fuz',
'<App boz fuz',
' foo={{',
' }} bar',
'baz bor',
'/>'
].join('\n'),
options: [{maximum: {multi: 2, single: 1}}],
errors: [{
messageId: 'newLine',
data: {prop: 'fuz'}
}, {
messageId: 'newLine',
data: {prop: 'baz'}
}]
Expand Down

0 comments on commit 824d4ff

Please sign in to comment.