Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create vue/multiline-ternary extension rule #1996

Merged
merged 17 commits into from Oct 10, 2022
6 changes: 3 additions & 3 deletions docs/rules/multiline-ternary.md
Expand Up @@ -2,16 +2,16 @@
pageClass: rule-details
sidebarDepth: 0
title: vue/multiline-ternary
description: Enforce newlines between operands of ternary expressions in `<template>`
description: Enforce newlines between operands of ternary expressions in `<template>` and `<style>`
FloEdelmann marked this conversation as resolved.
Show resolved Hide resolved
---
# vue/multiline-ternary

> Enforce newlines between operands of ternary expressions in `<template>`
> Enforce newlines between operands of ternary expressions in `<template>` and `<style>`

- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
- :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule.

This rule is the same rule as core [multiline-ternary] rule but it applies to the expressions in `<template>`.
This rule is the same rule as core [multiline-ternary] rule but it applies to the expressions in `<template>` and `<style>`.

## :books: Further Reading

Expand Down
53 changes: 52 additions & 1 deletion tests/lib/rules/multiline-ternary.js
Expand Up @@ -31,6 +31,14 @@ tester.run('multiline-ternary', rule, {
</template>
`
},
{
filename: 'test.vue',
code: `
<script>
let test = someReallyLongCondition ? aVeryLongOutput : thisCantFitOnASingleLine
</script>
`
},
dev1437 marked this conversation as resolved.
Show resolved Hide resolved
{
filename: 'test.vue',
code: `
Expand Down Expand Up @@ -240,6 +248,49 @@ tester.run('multiline-ternary', rule, {
column: 56
}
]
}
},
{
filename: 'test.vue',
code: `
<template>
<div :class="{
'test': someReallyLongCondition ? aVeryLongOutput : thisCantFitOnASingleLine
}">
</div>
</template>
<script>
let test = someReallyLongCondition ? aVeryLongOutput : thisCantFitOnASingleLine
</script>
`,
output: semver.gte(ESLint.version, '7.1.0')
? `
<template>
<div :class="{
'test': someReallyLongCondition
? aVeryLongOutput
: thisCantFitOnASingleLine
}">
</div>
</template>
<script>
let test = someReallyLongCondition ? aVeryLongOutput : thisCantFitOnASingleLine
</script>
`
: null,
errors: [
{
message:
'Expected newline between test and consequent of ternary expression.',
line: 4,
column: 19
},
{
message:
'Expected newline between consequent and alternate of ternary expression.',
line: 4,
column: 45
}
]
},
]
})