Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/rules/no-boolean-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,13 @@ module.exports = {
break

case 'default-false':
if (defaultNode.value.value !== false) {
if (
defaultNode &&
defaultNode.value.value !== false
) {
context.report({
node: defaultNode,
message: 'Boolean prop should be defaulted to false.'
message: 'Boolean prop should only be defaulted to false.'
})
}
break
Expand Down
151 changes: 149 additions & 2 deletions tests/lib/rules/no-boolean-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,53 @@ ruleTester.run('no-boolean-default', rule, {
}
`
},
{
filename: 'test.vue',
code: `
export default {
props: {
enabled: Boolean
}
}
`,
options: ['no-default']
},
{
filename: 'test.vue',
code: `
export default {
props: {
enabled: Boolean
}
}
`,
options: ['default-false']
},
{
filename: 'test.vue',
code: `
const props = {};
export default {
props: {
...props,
enabled: Boolean
}
}
`
},
{
filename: 'test.vue',
code: `
const props = {};
export default {
props: {
...props,
enabled: Boolean
}
}
`,
options: ['no-default']
},
{
filename: 'test.vue',
code: `
Expand All @@ -45,6 +92,21 @@ ruleTester.run('no-boolean-default', rule, {
enabled: Boolean
}
}
`,
options: ['default-false']
},
{
filename: 'test.vue',
code: `
const data = {};
export default {
props: {
enabled: {
type: Boolean,
...data
}
}
}
`
},
{
Expand All @@ -62,6 +124,21 @@ ruleTester.run('no-boolean-default', rule, {
`,
options: ['no-default']
},
{
filename: 'test.vue',
code: `
const data = {};
export default {
props: {
enabled: {
type: Boolean,
...data
}
}
}
`,
options: ['default-false']
},
{
filename: 'test.vue',
code: `
Expand Down Expand Up @@ -89,6 +166,30 @@ ruleTester.run('no-boolean-default', rule, {
}
`
},
{
filename: 'test.vue',
code: `
const data = {};
export default {
props: {
enabled: data
}
}
`,
options: ['no-default']
},
{
filename: 'test.vue',
code: `
const data = {};
export default {
props: {
enabled: data
}
}
`,
options: ['default-false']
},
{
filename: 'test.vue',
code: `
Expand All @@ -101,6 +202,34 @@ ruleTester.run('no-boolean-default', rule, {
}
}
`
},
{
filename: 'test.vue',
code: `
const data = {};
export default {
props: {
enabled: {
...data
}
}
}
`,
options: ['no-default']
},
{
filename: 'test.vue',
code: `
const data = {};
export default {
props: {
enabled: {
...data
}
}
}
`,
options: ['default-false']
}
],

Expand All @@ -119,7 +248,7 @@ ruleTester.run('no-boolean-default', rule, {
`,
options: ['default-false'],
errors: [{
message: 'Boolean prop should be defaulted to false.',
message: 'Boolean prop should only be defaulted to false.',
line: 6
}]
},
Expand All @@ -137,7 +266,7 @@ ruleTester.run('no-boolean-default', rule, {
`,
options: ['default-false'],
errors: [{
message: 'Boolean prop should be defaulted to false.',
message: 'Boolean prop should only be defaulted to false.',
line: 6
}]
},
Expand All @@ -158,6 +287,24 @@ ruleTester.run('no-boolean-default', rule, {
message: 'Boolean prop should not set a default (Vue defaults it to false).',
line: 6
}]
},
{
filename: 'test.vue',
code: `
export default {
props: {
enabled: {
type: Boolean,
default: true,
}
}
}
`,
options: ['no-default'],
errors: [{
message: 'Boolean prop should not set a default (Vue defaults it to false).',
line: 6
}]
}
]
})