当前位置:   article > 正文

uniapp配置eslint、typescript-eslint_typescript-eslint/eslint-plugin

typescript-eslint/eslint-plugin

uniapp配置eslint、typescript-eslint

安装eslint
yarn add eslint eslint-plugin-vue vue-eslint-parser -D
eslint-plugin-vue使用文档
安装typscript相关插件
必须保证tyscript和typescript-eslint/parser已经安装才能进行下一步@typescript-eslint/eslint-plugin的安装
yarn add typescript @typescript-eslint/parser -D
下一步安装
yarn add @typescript-eslint/eslint-plugin -D
@typescript-eslint/eslint-plugin使用文档

.eslintrc.js文件配置

module.exports = {
    root: true,
    env: {
        node: true
    },
    plugins: ['@typescript-eslint'],
    extends: [
        'eslint:recommended',
        'plugin:vue/essential',
        'plugin:vue/recommended',
        'plugin:@typescript-eslint/recommended',
    ],
    parser: 'vue-eslint-parser',
    parserOptions: {
        ecmaVersion: 2020,
    },
    //rules中的值0、1、2分别表示不开启检查、警告、错误
    rules: {
        'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
        'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
        'indent': [2, 4],
        'vue/html-indent': [2, 4],
        'quotes': [2, 'single'] , // 单引号
        '@typescript-eslint/no-var-requires': 0,
        '@typescript-eslint/no-explicit-any': 0,
    }
}

package.json
增加命令行
"lint": "eslint --ext .js,.ts,.vue ./ --fix"

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

{
“name”: “smart-device-wxapp”,
“version”: “0.1.0”,
“private”: true,
“scripts”: {
“serve”: “npm run dev:h5”,
“build”: “npm run build:h5”,
“build:app-plus”: “cross-env NODE_ENV=production UNI_PLATFORM=app-plus vue-cli-service uni-build”,
“build:custom”: “cross-env NODE_ENV=production uniapp-cli custom”,
“build:h5”: “cross-env NODE_ENV=production UNI_PLATFORM=h5 vue-cli-service uni-build”,
“build:mp-360”: “cross-env NODE_ENV=production UNI_PLATFORM=mp-360 vue-cli-service uni-build”,
“build:mp-alipay”: “cross-env NODE_ENV=production UNI_PLATFORM=mp-alipay vue-cli-service uni-build”,
“build:mp-baidu”: “cross-env NODE_ENV=production UNI_PLATFORM=mp-baidu vue-cli-service uni-build”,
“build:mp-kuaishou”: “cross-env NODE_ENV=production UNI_PLATFORM=mp-kuaishou vue-cli-service uni-build”,
“build:mp-qq”: “cross-env NODE_ENV=production UNI_PLATFORM=mp-qq vue-cli-service uni-build”,
“build:mp-toutiao”: “cross-env NODE_ENV=production UNI_PLATFORM=mp-toutiao vue-cli-service uni-build”,
“build:mp-weixin”: “cross-env NODE_ENV=production UNI_PLATFORM=mp-weixin vue-cli-service uni-build”,
“build:quickapp-native”: “cross-env NODE_ENV=production UNI_PLATFORM=quickapp-native vue-cli-service uni-build”,
“build:quickapp-webview”: “cross-env NODE_ENV=production UNI_PLATFORM=quickapp-webview vue-cli-service uni-build”,
“build:quickapp-webview-huawei”: “cross-env NODE_ENV=production UNI_PLATFORM=quickapp-webview-huawei vue-cli-service uni-build”,
“build:quickapp-webview-union”: “cross-env NODE_ENV=production UNI_PLATFORM=quickapp-webview-union vue-cli-service uni-build”,
“dev:app-plus”: “cross-env NODE_ENV=development UNI_PLATFORM=app-plus vue-cli-service uni-build --watch”,
“dev:custom”: “cross-env NODE_ENV=development uniapp-cli custom”,
“dev:h5”: “cross-env NODE_ENV=development UNI_PLATFORM=h5 vue-cli-service uni-serve”,
“dev:mp-360”: “cross-env NODE_ENV=development UNI_PLATFORM=mp-360 vue-cli-service uni-build --watch”,
“dev:mp-alipay”: “cross-env NODE_ENV=development UNI_PLATFORM=mp-alipay vue-cli-service uni-build --watch”,
“dev:mp-baidu”: “cross-env NODE_ENV=development UNI_PLATFORM=mp-baidu vue-cli-service uni-build --watch”,
“dev:mp-kuaishou”: “cross-env NODE_ENV=development UNI_PLATFORM=mp-kuaishou vue-cli-service uni-build --watch”,
“dev:mp-qq”: “cross-env NODE_ENV=development UNI_PLATFORM=mp-qq vue-cli-service uni-build --watch”,
“dev:mp-toutiao”: “cross-env NODE_ENV=development UNI_PLATFORM=mp-toutiao vue-cli-service uni-build --watch”,
“dev:mp-weixin”: “cross-env NODE_ENV=development UNI_PLATFORM=mp-weixin vue-cli-service uni-build --watch”,
“dev:quickapp-native”: “cross-env NODE_ENV=development UNI_PLATFORM=quickapp-native vue-cli-service uni-build --watch”,
“dev:quickapp-webview”: “cross-env NODE_ENV=development UNI_PLATFORM=quickapp-webview vue-cli-service uni-build --watch”,
“dev:quickapp-webview-huawei”: “cross-env NODE_ENV=development UNI_PLATFORM=quickapp-webview-huawei vue-cli-service uni-build --watch”,
“dev:quickapp-webview-union”: “cross-env NODE_ENV=development UNI_PLATFORM=quickapp-webview-union vue-cli-service uni-build --watch”,
“info”: “node node_modules/@dcloudio/vue-cli-plugin-uni/commands/info.js”,
“serve:quickapp-native”: “node node_modules/@dcloudio/uni-quickapp-native/bin/serve.js”,
“test:android”: “cross-env UNI_PLATFORM=app-plus UNI_OS_NAME=android jest -i”,
“test:h5”: “cross-env UNI_PLATFORM=h5 jest -i”,
“test:ios”: “cross-env UNI_PLATFORM=app-plus UNI_OS_NAME=ios jest -i”,
“test:mp-baidu”: “cross-env UNI_PLATFORM=mp-baidu jest -i”,
“test:mp-weixin”: “cross-env UNI_PLATFORM=mp-weixin jest -i”,
“lint”: “eslint --ext .js,.ts,.vue ./ --fix”
},
“dependencies”: {
“@dcloudio/uni-app-plus”: “^2.0.0-28920200907001”,
“@dcloudio/uni-h5”: “^2.0.0-28920200907001”,
“@dcloudio/uni-helper-json”: “",
“@dcloudio/uni-mp-360”: “^2.0.0-28920200907001”,
“@dcloudio/uni-mp-alipay”: “^2.0.0-28920200907001”,
“@dcloudio/uni-mp-baidu”: “^2.0.0-28920200907001”,
“@dcloudio/uni-mp-qq”: “^2.0.0-28920200907001”,
“@dcloudio/uni-mp-toutiao”: “^2.0.0-28920200907001”,
“@dcloudio/uni-mp-vue”: “^2.0.0-28920200907001”,
“@dcloudio/uni-mp-weixin”: “^2.0.0-28920200907001”,
“@dcloudio/uni-quickapp-native”: “^2.0.0-28920200907001”,
“@dcloudio/uni-quickapp-webview”: “^2.0.0-28920200907001”,
“@dcloudio/uni-stat”: “^2.0.0-28920200907001”,
“@vue/shared”: “^3.0.0-rc.4”,
“core-js”: “^3.6.5”,
“flyio”: “^0.6.2”,
“regenerator-runtime”: “^0.12.1”,
“uview-ui”: “^1.6.9”,
“vue”: “^2.6.11”,
“vue-class-component”: “^7.2.5”,
“vue-property-decorator”: “^9.0.0”,
“vuex”: “^3.2.0”
},
“devDependencies”: {
“@babel/plugin-syntax-typescript”: “^7.2.0”,
“@dcloudio/types”: "
”,
“@dcloudio/uni-automator”: “^2.0.0-28920200907001”,
“@dcloudio/uni-cli-shared”: “^2.0.0-28920200907001”,
“@dcloudio/uni-migration”: “^2.0.0-28920200907001”,
“@dcloudio/uni-template-compiler”: “^2.0.0-28920200907001”,
“@dcloudio/vue-cli-plugin-hbuilderx”: “^2.0.0-28920200907001”,
“@dcloudio/vue-cli-plugin-uni”: “^2.0.0-28920200907001”,
“@dcloudio/vue-cli-plugin-uni-optimize”: “^2.0.0-28920200907001”,
“@dcloudio/webpack-uni-mp-loader”: “^2.0.0-28920200907001”,
“@dcloudio/webpack-uni-pages-loader”: “^2.0.0-28920200907001”,
“@typescript-eslint/eslint-plugin”: “^4.1.1”,
“@typescript-eslint/parser”: “^4.1.1”,
“@vue/cli-plugin-babel”: “~4.5.0”,
“@vue/cli-plugin-typescript”: “",
“@vue/cli-service”: “~4.5.0”,
“babel-plugin-import”: “^1.11.0”,
“cross-env”: “^7.0.2”,
“eslint”: “^7.9.0”,
“eslint-plugin-vue”: “^6.2.2”,
“jest”: “^25.4.0”,
“mini-types”: "
”,
“miniprogram-api-typings”: “*”,
“postcss-comment”: “^2.0.0”,
“typescript”: “^3.0.0”,
“vue-eslint-parser”: “^7.1.0”,
“vue-template-compiler”: “^2.6.11”
},
“browserslist”: [
“Android >= 4”,
“ios >= 8”
],
“uni-app”: {
“scripts”: {}
}
}


  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/76974
推荐阅读
相关标签
  

闽ICP备14008679号