Skip to content

vue/order-in-components computed内含有辅助函数无法自动修复 #2272

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

Closed
2 tasks
dongjinc opened this issue Aug 11, 2023 · 7 comments
Closed
2 tasks

Comments

@dongjinc
Copy link

Checklist

  • I have tried restarting my IDE and the issue persists.
  • I have read the FAQ and my problem is not listed.

Tell us about your environment

  • ESLint version:
  • eslint-plugin-vue version:
  • Node version:
  • Operating System:

Please show your full configuration:

const path = require("path");

module.exports = {
  root: true,
  env: {
    browser: true,
    node: true,
    es6: true,
  },
  globals: {
    __webpack_public_path__: true,
  },
  parserOptions: {
    ecmaVersion: 2022,
    sourceType: "module",
    ecmaFeatures: {
      jsx: true,
    },
  },
  plugins: ["prettier"],
  overrides: [
    {
      files: ["*.vue"],
      parser: "vue-eslint-parser",
      plugins: ["vue"],
      extends: ["plugin:vue/recommended", "plugin:prettier/recommended"],
      parserOptions: {
        ecmaVersion: 2022,
        sourceType: "module",
        ecmaFeatures: {
          jsx: true,
        },
      },
      rules: {
        "vue/require-default-prop": "off",
      },
    },
  ],
  extends: ["eslint:recommended", "plugin:import/recommended", "plugin:prettier/recommended"],
  rules: {
    "no-console": "off",
    "no-debugger": "off",
    "import/no-named-as-default": "off",
  },
  settings: {
    "import/core-modules": ["@nh/micro-base-service"],
    "import/resolver": {
      alias: {
        map: [
          ["@", path.resolve(__dirname, "./src")],
          ["@base-service", path.resolve(__dirname, "./micro/base-service")],
        ],
        extensions: [".js", ".vue"],
      },
    },
  },
};

What did you do?

<template>
  <div class="nav-multi">
    <el-tabs
      class="nav-multi-tag"
      :value="$route.fullPath"
      type="card"
      :closable="multiTab.length !== 1"
      @tab-remove="handleClose"
      @tab-click="handleOpen"
    >
      <el-tab-pane
        v-for="tab in multiTab"
        :key="tab.fullPath"
        :name="tab.fullPath"
        :label="(tab.query?.patientName || '') + (tab.meta.customTitle || tab.meta.title)"
      />
    </el-tabs>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import { findIndex } from "lodash-es";
export default {
  name: "NavMultiTab",
  watch: {
    $route(val) {
      this.addMultiTab(val);
    },
  },
  created() {
    this.addMultiTab(this.$route);
  },
// The "computed" property should be above the "watch" property on line 26.eslint[vue/order-in-components]
  computed: {
    ...mapGetters(["multiTab"]),
  },
  methods: {
    ...mapActions({ addMultiTab: "multiTab/add" }),
   
  },
};
</script>

What did you expect to happen?
1.computed内含有辅助函数时, 应该自动修复;

What actually happened?

1.computed内含有辅助函数无法自动修复, 请排查, 谢谢;

Repository to reproduce this issue

@FloEdelmann
Copy link
Member

Well, the rule seems to work like expected. Please see https://eslint.vuejs.org/rules/order-in-components.html.

@Sapphire2k
Copy link

It doesn't look like that.

image

@FloEdelmann
Copy link
Member

Yes it is. The order in your screenshot it computed, props, data, the rule suggests props, data, computed.

If it doesn't work as specified in the rule docs, please open a new issue following the issue template (including versions and a repository or Stackblitz or link to the eslint-plugin-vue Playground where the problem can be reproduced).

@Sapphire2k
Copy link

Yes it is. The order in your screenshot it computed, props, data, the rule suggests props, data, computed.

If it doesn't work as specified in the rule docs, please open a new issue following the issue template (including versions and a repository or Stackblitz or link to the eslint-plugin-vue Playground where the problem can be reproduced).

Thanks for replying.
Yes, i know this warning and it's correct, but the problem is it would not being fix by eslint (sort the life cycle), you can try to add ...mapStates(['test']) inside the computed, you will see it.

@FloEdelmann
Copy link
Member

So you agree that the rule is reporting the wrong sort order correctly, but you're only missing the autofix for it?

@Sapphire2k
Copy link

So you agree that the rule is reporting the wrong sort order correctly, but you're only missing the autofix for it?

Yes, that's the problem.

@FloEdelmann
Copy link
Member

It's because the rule can't be sure that the mapStates function has no side effects, so reordering might change something. But I think we could offer a suggestion instead of a fix in this case. I'll open a separate issue for that and link it here.

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

3 participants