Skip to content

script-indent does not work properly with the ternary operator #625

Closed
@korya

Description

@korya

Tell us about your environment

  • ESLint Version: 5.8.0
  • eslint-plugin-vue Version: 5.0.0-beta3
  • Node Version: 11

Please show your full configuration:

module.exports = {
  extends: [
    'plugin:vue/recommended',
  ],

  parserOptions: {
    parser: 'babel-eslint',
  },

  overrides: [
    // Disable the default `indent` rule for `.vue` files to avoid conflicts
    // with `vue/script-indent`.
    { files: ['*.vue'], rules: { indent: 'off' } },
  ],
};

What did you do? Please include the actual source code causing the issue.

<template>
  <img :src="imgUrl">
</template>

<script>
export default {
  data() {
    const hours = new Date().getHours();

    return {
      imgUrl: hours > 21 && hours < 6 ? 'night.png' :
        'day.png',
    };
  },
}
</script>

What did you expect to happen?

I expect the code to be successfully linted.

What actually happened? Please include the actual, raw output from ESLint.

  40:1  error  Expected indentation of 6 spaces but found 8 spaces  vue/script-indent

Additional notes

I was able to reproduce the issue in the playground: follow this link

Additionally, if I change the JS code from:

imgUrl: hours > 21 && hours < 6 ? 'night.png' :
  'day.png',

to

imgUrl: hours > 21 && hours < 6 ?
  'night.png' : 'day.png',

The the lint validation succeeds. Here is a playground link for a fixed case

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions