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

[vue/html-indent] Unexpected indentation level when element follows mustache tag. #780

Closed
constantm opened this issue Jan 16, 2019 · 7 comments

Comments

@constantm
Copy link

Tell us about your environment

  • ESLint version: v5.12.0
  • eslint-plugin-vue version: 4.7.1
  • Node version: v10.11.0

Please show your full configuration:

module.exports = {
  root: true,
  parserOptions: {
    sourceType: 'script',
  },
  extends: [
    'prettier',
    'prettier/standard',
    'plugin:vue/recommended',
    'standard',
  ],
  rules: {
    // Only allow debugger in development
    'no-debugger': process.env.PRE_COMMIT ? 'error' : 'off',
    // Only allow `console.log` in development
    'no-console': process.env.PRE_COMMIT
      ? ['error', { allow: ['warn', 'error'] }]
      : 'off',
    'vue/html-closing-bracket-spacing': [
      'error',
      {
        startTag: 'never',
        endTag: 'never',
        selfClosingTag: 'never',
      },
    ],
    'vue/component-name-in-template-casing': [
      'error',
      'kebab-case',
      {
        ignores: [],
      },
    ],
    'vue/html-closing-bracket-newline': [
      'error',
      {
        singleline: 'never',
        multiline: 'never',
      },
    ],
    'vue/max-attributes-per-line': [
      'error',
      {
        singleline: 1,
        multiline: {
          max: 1,
          allowFirstLine: false,
        },
      },
    ],
    'vue/html-indent': [
      'error',
      2,
      {
        attribute: 1,
        baseIndent: 1,
        closeBracket: 0,
        alignAttributesVertically: true,
        ignores: [],
      },
    ],
    'comma-dangle': ['error', 'always-multiline'],
    'space-before-function-paren': ['error', 'never'],
  },
  overrides: [
    {
      files: ['src/**/*', 'tests/unit/**/*', 'tests/e2e/**/*'],
      excludedFiles: 'app.config.js',
      parserOptions: {
        parser: 'babel-eslint',
        sourceType: 'module',
      },
      env: {
        browser: true,
      },
    },
    {
      files: ['**/*.unit.js'],
      parserOptions: {
        parser: 'babel-eslint',
        sourceType: 'module',
      },
      env: { jest: true },
      globals: {
        mount: false,
        shallowMount: false,
        shallowMountView: false,
        createComponentMocks: false,
        createModuleStore: false,
      },
    },
  ],
}

What did you do?

node_modules/eslint/bin/eslint.js --ext .js,.vue --fix src/**/*.vue

On file:

<div class="col">
  You accepted the policy {{ policyUrl ? 'at' : '' }}
                    <a :href="policyUrl" target="_blank">
                     {{ policyUrl }}
                    </a>
      on {{ acceptDate }}.
</div>

What did you expect to happen?

<div class="col">
  You accepted the policy {{ policyUrl ? 'at' : '' }}
  <a
    :href="policyUrl"
    target="_blank">
    {{ policyUrl }}
  </a>
  on {{ acceptDate }}.
</div>

What actually happened?

<div class="col">
  You accepted the policy {{ policyUrl ? 'at' : '' }}
                    <a
                      :href="policyUrl"
                      target="_blank">
                      {{ policyUrl }}
                    </a>
                    on {{ acceptDate }}.
</div>
@ckritzinger
Copy link

I'm running into the same thing. Any suggestions?

@ota-meshi
Copy link
Member

Hello.
This problem does not seem to happen on the demo.
In the latest version, this problem may have been fixed.

@lilisgeorge
Copy link

Hello,

It doesnt seem to be related to mustaches, but generally with text not wrapped by a tag
Yesterday i updated my dependencies to the latest and since then i get weird behavior with indentations on vue templates.

Below is a sample of my code before updating to latest

<label class="label-checkbox">
  Text not wrapped by an element
  <input
    type="checkbox"
    class="checkbox"
    v-validate="'required'"
    data-vv-as="Accept"
    v-model="formData.accepted"
    name="accepted"
    :class="{ 'has-error': errors.has(`${scope}.accepted`) }"
    :disabled="submitting"
  >
  <div class="checkbox-indicator" />
</label>

I then run development server and received indentation warnings on above sample.

The warning was suggesting to indent the input tag 39 spaces instead of 10 it was originally at.

I let it auto fix the problem and the result was:

<label class="label-checkbox">
  Text not wrapped by an element
                                       <input
                                         type="checkbox"
                                         class="checkbox"
                                         v-validate="'required'"
                                         data-vv-as="Accept"
                                         v-model="formData.accepted"
                                         name="accepted"
                                         :class="{ 'has-error': errors.has(`${scope}.accepted`) }"
                                         :disabled="submitting"
                                       >
  <div class="checkbox-indicator" />
</label>

In order to temporary fix it i had to wrap the text with an element

<label class="label-checkbox">
  <span>Text not wrapped by an element</span>
  <input
    type="checkbox"
    class="checkbox"
    v-validate="'required'"
    data-vv-as="Accept"
    v-model="formData.accepted"
    name="accepted"
    :class="{ 'has-error': errors.has(`${scope}.accepted`) }"
    :disabled="submitting"
  >
  <div class="checkbox-indicator" />
</label>

After that the warning disappeared

@ota-meshi
Copy link
Member

@lilisgeorge
What version are you using?
I think that it was fixed in v 5.1.0.

@lilisgeorge
Copy link

@ota-meshi
I am using v5.1.0 on a project scaffolded with vue-cli 3

The project is setup on 2 desktop computers. One at home and the other at work.

I have updated both computer dependencies. On home pc i did npm update and npm ci to clear node_modules folder while on work pc i just did npm ci.

On my work pc i receive no errors but in my home pc I still get linting errors.

@lilisgeorge
Copy link

@ota-meshi

Hello,
Error fixed for me. Seems like it was some kind of caching.

@constantm
Copy link
Author

Woohoo this was indeed fixed in 5.1.0, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants