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/script-indent doesn't respect nested spacing #987

Closed
akoidan opened this issue Nov 16, 2019 · 7 comments · Fixed by #1520
Closed

vue/script-indent doesn't respect nested spacing #987

akoidan opened this issue Nov 16, 2019 · 7 comments · Fixed by #1520

Comments

@akoidan
Copy link
Contributor

akoidan commented Nov 16, 2019

Tell us about your environment

  • ESLint version: 6.6.0
  • eslint-plugin-vue version: 6.0.1
  • Node version: v12.13.0

Please show your full configuration:

{
  "extends": [
    "plugin:vue/recommended",
    "eslint:all",
    "@vue/typescript",
    "plugin:@typescript-eslint/recommended"
  ],
  "parser": "vue-eslint-parser",
  "parserOptions": {
    "parser": "@typescript-eslint/parser",
    "sourceType": "module"
  },
  "rules": {
    "indent": [
      "error",
      2
    ],
    "init-declarations": "off",
    "one-var": "off",
    "no-plusplus": "off",
    "vue/script-indent": ["error", 2, { "baseIndent": 0 }],
    "quote-props": ["error", "as-needed"],
    "no-ternary": "off",
    "multiline-ternary": "off",
    "new-cap": ["error", {"capIsNewExceptions":  ["Module", "Component", "Prop", "Ref", "Emit"]}],
    "space-before-function-paren": ["error", "never"],
    "array-element-newline": ["error", "consistent"],
    "comma-dangle": ["error", "always-multiline"],
    "function-call-argument-newline": ["error", "consistent"],
    "max-len": ["error", { "code": 120 }],
    "import/no-unresolved": "off",
    "padded-blocks": ["error", "never"],
    "vue/html-self-closing": [
      "error",
      {
        "html": {
          "void": "always",
          "normal": "always",
          "component": "always"
        }
      }
    ]
  },
  "settings": {
    "overrides": [
      {
        "files": ["*.vue"],
        "rules": {
          "indent": "off"
        }
      }
    ]
  }
}

What did you do?

<template>
  <div>
  </div>
</template>

<script lang="ts">
import {Component, Prop, Vue} from "vue-property-decorator";

@Component
export default class UserComp extends Vue {
                     private id = "UserComp";  // it doesn't matter how many spaces there are private readonly user!: User;
}
</script>

What did you expect to happen?
Since we ban indent rule there's no way of check nested spacing. I would expect vue/script-idnent to warn about incorrect spacing in the same way how would indent rule warn me if it was .ts file

What actually happened?

No warnings are present

Reproduce:

   class A { // this 2 indent before class would produce error
   }

class B {
                     a = 3; // but this won't!
}
@akoidan akoidan changed the title vue/script-indent ignores nested spaces vue/script-indent doesn't respect nested spacing Nov 16, 2019
@ota-meshi
Copy link
Member

Thank you for this issue.

The vue/script-indent rule does not understand TypeScript AST.

I think it works well if you use the @typescript-eslint/indent rule of @typescript-eslint/eslint-plugin.

@akoidan
Copy link
Contributor Author

akoidan commented Nov 18, 2019

@ota-meshi

This is so complicated... is there a guide or readme? How are people suppose to find that out? Because eslint/indent works out of the box outside .vue (in .ts) files

@ota-meshi
Copy link
Member

The vue/script-indent documentation is here, but there is no documentation about TypeScript.
Welcome your pull request.

@akoidan
Copy link
Contributor Author

akoidan commented Nov 18, 2019

@ota-meshi vue 3.0 is gonna be released soon and it's based on typescript. While it still has support for JS this would probably inspire peple using typescript for vue. For this issue this means:

  • either we mark on global README page that this set of rules doesn't support typescript, and could have unpredictable issues
  • either vue/script-indent is the only rule that doesn't support typescript and we probably want to find out why that is. Beause eslint/indent doesn't know about TS AST as well, but works completely fine.

@ota-meshi
Copy link
Member

I know peoples want TypeScript support.
But I'm not familiar with TypeScript AST, and other members are busy now. So I can't start work about TypeScript.
I need your help.

@jwayne2
Copy link

jwayne2 commented Feb 26, 2021

I added TypeScript AST nodes to KNOWN_NODES constant in the file https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/utils/indent-common.js and it seems to work ok.

List of TS AST nodes I added to the end of KNOW_NODES array:

'TSAbstractClassProperty',
'TSAbstractKeyword',
'TSAbstractMethodDefinition',
'TSAnyKeyword',
'TSArrayType',
'TSAsExpression',
'TSAsyncKeyword',
'TSBigIntKeyword',
'TSBooleanKeyword',
'TSCallSignatureDeclaration',
'TSClassImplements',
'TSConditionalType',
'TSConstructorType',
'TSConstructSignatureDeclaration',
'TSDeclareFunction',
'TSDeclareKeyword',
'TSEmptyBodyFunctionExpression',
'TSEnumDeclaration',
'TSEnumMember',
'TSExportAssignment',
'TSExportKeyword',
'TSExternalModuleReference',
'TSFunctionType',
'TSImportEqualsDeclaration',
'TSImportType',
'TSIndexedAccessType',
'TSIndexSignature',
'TSInferType',
'TSInterfaceBody',
'TSInterfaceDeclaration',
'TSInterfaceHeritage',
'TSIntersectionType',
'TSLiteralType',
'TSMappedType',
'TSMethodSignature',
'TSModuleBlock',
'TSModuleDeclaration',
'TSNamedTupleMember',
'TSNamespaceExportDeclaration',
'TSNeverKeyword',
'TSNonNullExpression',
'TSNullKeyword',
'TSNumberKeyword',
'TSObjectKeyword',
'TSOptionalType',
'TSParameterProperty',
'TSParenthesizedType',
'TSPrivateKeyword',
'TSPropertySignature',
'TSProtectedKeyword',
'TSPublicKeyword',
'TSQualifiedName',
'TSReadonlyKeyword',
'TSRestType',
'TSStaticKeyword',
'TSStringKeyword',
'TSSymbolKeyword',
'TSThisType',
'TSTupleType',
'TSTypeAliasDeclaration',
'TSTypeAnnotation',
'TSTypeAssertion',
'TSTypeLiteral',
'TSTypeOperator',
'TSTypeParameter',
'TSTypeParameterDeclaration',
'TSTypeParameterInstantiation',
'TSTypePredicate',
'TSTypeQuery',
'TSTypeReference',
'TSUndefinedKeyword',
'TSUnionType',
'TSUnknownKeyword',
'TSVoidKeyword'

@Djaler
Copy link

Djaler commented Mar 11, 2021

@jwayne2 can you publish this?

lisadeloach63 added a commit to lisadeloach63/plugin-develop-vue that referenced this issue Oct 7, 2022
Viktor949 added a commit to Viktor949/Eslint-Plugin-Vue that referenced this issue Oct 1, 2023
sebastianmensense added a commit to sebastianmensense/Eslint-Plugin-Vue- that referenced this issue Nov 15, 2023
Antontokarchuk0302 added a commit to Antontokarchuk0302/Eslint-plugin that referenced this issue Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants