Vue-CLI с 4 пробелами - PullRequest
       54

Vue-CLI с 4 пробелами

0 голосов
/ 08 октября 2018

Я совершенно новичок в Vue.

Я хочу использовать CLI и хочу иметь отступ в 4 пробела (с машинописью и vuex).Но после 24 часов борьбы я уже не приблизился к тому, чтобы что-то заработало.Если это невозможно, дайте мне знать тоже.

Я думал, что tslint - это путь, но не смог найти решение.Итак, я попытался eslint и добавил это в package.json

  "devDependencies": {
    "@vue/cli-plugin-eslint": "^3.0.4",
    "@vue/cli-plugin-pwa": "^3.0.4",
    "@vue/cli-plugin-typescript": "^3.0.4",
    "@vue/cli-service": "^3.0.4",
    "@vue/eslint-config-prettier": "^3.0.4",
    "@vue/eslint-config-typescript": "^3.0.4",
    "eslint": "^5.6.1",
    "eslint-plugin-vue": "^5.0.0-beta.3",      // <------------------
    "typescript": "^3.0.0",
    "vue-template-compiler": "^2.5.17"
  }

Тогда есть eslintrc У меня есть

 module.exports = {
    root: true,
    env: {
        node: true
    },
    extends: ["plugin:vue/essential", "@vue/prettier", "@vue/typescript"],
    rules: {
        "no-console": process.env.NODE_ENV === "production" ? "error" : "off",
        "no-debugger": process.env.NODE_ENV === "production" ? "error" : "off",
        "vue/script-indent": ["error", 4, { baseIndent: 1 }],
        indent: ["error", 4]
    },
    parserOptions: {
        parser: "typescript-eslint-parser"
    }
};

тогда, когда я запускаю

$ npx eslint --fix *.js
=============

WARNING: You are currently running a version of TypeScript which is not officially supported by typescript-eslint-parser.

You may find that it works just fine, or you may not.

SUPPORTED TYPESCRIPT VERSIONS: ~3.0.1

YOUR TYPESCRIPT VERSION: 3.1.1

Please only submit bug reports when using the officially supported version.

=============

/Users/x/code/sync/vue/restos2/postcss.config.js
  2:1  error  Expected indentation of 4 spaces but found 2  indent
  3:1  error  Expected indentation of 8 spaces but found 4  indent
  4:1  error  Expected indentation of 4 spaces but found 2  indent

✖ 3 problems (3 errors, 0 warnings)
  3 errors and 0 warnings potentially fixable with the `--fix` option.
but the problem is that no files ever get changed.

1 Ответ

0 голосов
/ 09 октября 2018

Как описано в документе tslint, правило отступа не исправляет неправильное количество символов отступа, оно только исправляет тип символа, это означает, что оно может преобразовывать символы табуляции в пробелы и наоборот, но оно не фиксирует 4 пробела в 2 пробелах.

ПРИМЕЧАНИЕ: автоматическое исправление преобразует только недопустимые отступы в нужный тип, оно не исправляет недопустимые размеры пробелов.

https://palantir.github.io/tslint/rules/indent/

Так что да, тебе придется пойти с Эслинт.Я не вижу полный файл eslintrc, но думаю, что основной проблемой может быть эта строка: indent: ["error", 4].Попробуйте удалить это.

Этот конфиг eslint работает для меня:

{
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/essential",
      "eslint:recommended",
      "@vue/typescript"
    ],
    "rules": {
      "vue/script-indent": ["error",2,{"baseIndent": 1}]
    },
    "parserOptions": {
      "parser": "typescript-eslint-parser"
    }
}

И запустить с npm run lint

...