关于uniapp:uniapp-配置eslint-prettier

背景: 应用的是vue/cli创立的支付宝小程序我的项目
话不多说上菜

  • 装置eslint ,因为我的项目中应用的是cli搭建的,所以间接应用 vue add @vue/eslint
    vue add @vue/eslint
    而后依据本人爱好抉择格调,这里我抉择的是prettier
  • 配置.eslintrc.js
    在我的项目根目录新建文件.eslintrc.js,依据本人需要配置规定
module.exports = {
    root: true,
    env: {
        node: true,
    },
    globals: {
        uni: "readonly",
        my:"readonly"
    },
    extends: ["plugin:vue/essential", "eslint:recommended", "@vue/prettier"],
    parserOptions: {
        parser: "babel-eslint",
    },
    rules: {
        "no-console": process.env.NODE_ENV === "production" ? "warn" : "off",
        "no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off",
        "no-sequences": 0,
        "import/named": 0,
        "no-useless-concat": 0,
        "no-unreachable": 0,
        "no-case-declarations": 0,
        "no-continue": 0,
        "no-redeclare": 0,
        "block-scoped-var": 0,
        "operator-assignment": 0,
        "no-multi-assign": 0,
        "comma-dangle": 0,
        "prefer-const": 0,
        "semi": 0,
        "eol-last": 0,
        "linebreak-style": 0,
        "no-unused-vars": 0,
        "no-useless-computed-key": 0,
        "default-case": 0,
        "prefer-destructuring": 0,
        "arrow-parens": 0,
        'no-var': 2, // 要求应用 let 或 const 而不是 var
        "comma-spacing": 0,
        "no-mixed-operators": 0,
        "radix": 0,
        "prefer-promise-reject-errors": 0,
        "arrow-body-style": 0,
        "prefer-rest-params": 0,
        "no-restricted-syntax": 0,
        "vars-on-top": 0,
        "import/no-named-as-default": 0,
        "import/extensions": 0,
        "import/no-named-as-default-member": 0,
        "guard-for-in": 0,
        "no-unused-expressions": 0,
        "import/prefer-default-export": 0,
        "no-shadow": 0,
        "no-nested-ternary": 0,
        "no-empty": 0,
        "eqeqeq": 0,
        "camelcase": 0,
        "prefer-template": 0,
        "dot-notation": 0,
        "prefer-arrow-callback": 0,
        "no-plusplus": 0,
        "no-else-return": 0,
        "one-var-declaration-per-line": 0,
        "consistent-return": 0,
        "no-param-reassign": 0,
        "max-len": 0,
        "no-lonely-if": 0,
        "array-callback-return": 0,
        "prefer-object-spread": 0,
        "import/order": 0,
        "import/newline-after-import": 0,
        "func-names": 0,
        "no-console": 0,
        "no-underscore-dangle": 0,
        "no-useless-escape": 0
    },
};
  • 配置eslint不必查看的文件 .eslintignore
    根目录 新建文件.eslintignore ,依据理论需要配置
/utils
/subpackage/utils
/node_modules
/postcss.config.js
/babel.config.js
  • 最初配置.prettierrc.js
    根目录新建.prettierrc.js文件,依据理论需要配置
//配置 prettier  。prettierrc.js
module.exports = {
  // 单行最大长度
  printWidth: 100,
  // 设置编辑器每一个程度缩进的空格数
  tabWidth: 2,
  // 在句尾增加分号
  semi: true,
  // 应用单引号
  singleQuote: true,
  jsxSingleQuote: true,
  // 在任何可能的多行中输出尾逗号。
  trailingComma: 'all',
  // 在对象字面量申明所应用的的花括号后({)和前(})输入空格
  bracketSpacing: true,
  // 在多行JSX元素最初一行的开端增加 > 而使 > 独自一行(不适用于自闭和元素)
  jsxBracketSameLinte: false,
  // 为单行箭头函数的参数增加圆括号。
  alwaysParens: 'always',
  // 行完结
  endOfLine:"auto",
  vueIndentScriptAndStyle: true, //是否缩进Vue 文件中的代码<script>和<style>标签
  htmlWhitespaceSensitivity:'ignore',//HTML 空白敏感度
};
  • 最初一步在package.json文件中批改一下lint的命令,批改为

     "lint": "eslint --fix --ext .js,.vue src",

    应用当有问题的时候就报错啦

    这些正告不必放心,执行一下npm run lint 会本人修复的

    修复后

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理