VSCODE配置eslint校验和保存自动修复

福尔摩斯对我笑 2019-06-07 3331 次 618条

VSCODE 配置eslint规则和自动修复

  • vscode安装以下插件

    EsLint、vetur、Prettier - Code formatter

  • vscode设置了添加配置项,,默认会去查找你项目中的eslint配置文件
       {
      "workbench.iconTheme": "material-icon-theme",
      "explorer.confirmDragAndDrop": false,
      "explorer.confirmDelete": false,
      //配置eslint
      "eslint.autoFixOnSave": true,  //  启用保存时自动修复,默认只支持.js文件
      "eslint.validate": [
         "javascript",  //  用eslint的规则检测js文件
         {
           "language": "vue",   // 检测vue文件
           "autoFix": true   //  为vue文件开启保存自动修复的功能
         },
         {
           "language": "html",
           "autoFix": true
         },
       ],
    
    }
    
    
  • 项目中创建.eslitrc.js配置 文件,可能比较多
        module.exports = {
      root: true,
      parserOptions: {
        parser: 'babel-eslint',
        sourceType: 'module'
      },
      env: {
        browser: true,
        node: true,
        es6: true,
      },
      extends: ['plugin:vue/recommended', 'eslint:recommended'],
    
      // add your custom rules here
      //it is base on https://github.com/vuejs/eslint-config-vue
      rules: {
        "vue/max-attributes-per-line": [2, {
          "singleline": 10,
          "multiline": {
            "max": 1,
            "allowFirstLine": false
          }
        }],
        "vue/singleline-html-element-content-newline": "off",
        "vue/multiline-html-element-content-newline":"off",
        "vue/name-property-casing": ["error", "PascalCase"],
        "vue/no-v-html": "off",
        'accessor-pairs': 2,
        'arrow-spacing': [2, {
          'before': true,
          'after': true
        }],
        'block-spacing': [2, 'always'],
        'brace-style': [2, '1tbs', {
          'allowSingleLine': true
        }],
        'camelcase': [0, {
          'properties': 'always'
        }],
        'comma-dangle': [2, 'never'],
        'comma-spacing': [2, {
          'before': false,
          'after': true
        }],
        'comma-style': [2, 'last'],
        'constructor-super': 2,
        'curly': [2, 'multi-line'],
        'dot-location': [2, 'property'],
        'eol-last': 2,
        'eqeqeq': ["error", "always", {"null": "ignore"}],
        'generator-star-spacing': [2, {
          'before': true,
          'after': true
        }],
        'handle-callback-err': [2, '^(err|error)$'],
        'indent': [2, 2, {
          'SwitchCase': 1
        }],
        'jsx-quotes': [2, 'prefer-single'],
        'key-spacing': [2, {
          'beforeColon': false,
          'afterColon': true
        }],
        'keyword-spacing': [2, {
          'before': true,
          'after': true
        }],
        'new-cap': [2, {
          'newIsCap': true,
          'capIsNew': false
        }],
        'new-parens': 2,
        'no-array-constructor': 2,
        'no-caller': 2,
        'no-console': 'off',
        'no-class-assign': 2,
        'no-cond-assign': 2,
        'no-const-assign': 2,
        'no-control-regex': 0,
        'no-delete-var': 2,
        'no-dupe-args': 2,
        'no-dupe-class-members': 2,
        'no-dupe-keys': 2,
        'no-duplicate-case': 2,
        'no-empty-character-class': 2,
        'no-empty-pattern': 2,
        'no-eval': 2,
        'no-ex-assign': 2,
        'no-extend-native': 2,
        'no-extra-bind': 2,
        'no-extra-boolean-cast': 2,
        'no-extra-parens': [2, 'functions'],
        'no-fallthrough': 2,
        'no-floating-decimal': 2,
        'no-func-assign': 2,
        'no-implied-eval': 2,
        'no-inner-declarations': [2, 'functions'],
        'no-invalid-regexp': 2,
        'no-irregular-whitespace': 2,
        'no-iterator': 2,
        'no-label-var': 2,
        'no-labels': [2, {
          'allowLoop': false,
          'allowSwitch': false
        }],
        'no-lone-blocks': 2,
        'no-mixed-spaces-and-tabs': 2,
        'no-multi-spaces': 2,
        'no-multi-str': 2,
        'no-multiple-empty-lines': [2, {
          'max': 1
        }],
        'no-native-reassign': 2,
        'no-negated-in-lhs': 2,
        'no-new-object': 2,
        'no-new-require': 2,
        'no-new-symbol': 2,
        'no-new-wrappers': 2,
        'no-obj-calls': 2,
        'no-octal': 2,
        'no-octal-escape': 2,
        'no-path-concat': 2,
        'no-proto': 2,
        'no-redeclare': 2,
        'no-regex-spaces': 2,
        'no-return-assign': [2, 'except-parens'],
        'no-self-assign': 2,
        'no-self-compare': 2,
        'no-sequences': 2,
        'no-shadow-restricted-names': 2,
        'no-spaced-func': 2,
        'no-sparse-arrays': 2,
        'no-this-before-super': 2,
        'no-throw-literal': 2,
        'no-trailing-spaces': 2,
        'no-undef': 2,
        'no-undef-init': 2,
        'no-unexpected-multiline': 2,
        'no-unmodified-loop-condition': 2,
        'no-unneeded-ternary': [2, {
          'defaultAssignment': false
        }],
        'no-unreachable': 2,
        'no-unsafe-finally': 2,
        'no-unused-vars': [2, {
          'vars': 'all',
          'args': 'none'
        }],
        'no-useless-call': 2,
        'no-useless-computed-key': 2,
        'no-useless-constructor': 2,
        'no-useless-escape': 0,
        'no-whitespace-before-property': 2,
        'no-with': 2,
        'one-var': [2, {
          'initialized': 'never'
        }],
        'operator-linebreak': [2, 'after', {
          'overrides': {
            '?': 'before',
            ':': 'before'
          }
        }],
        'padded-blocks': [2, 'never'],
        'quotes': [2, 'single', {
          'avoidEscape': true,
          'allowTemplateLiterals': true
        }],
        'semi': [2, 'never'],
        'semi-spacing': [2, {
          'before': false,
          'after': true
        }],
        'space-before-blocks': [2, 'always'],
        'space-before-function-paren': [2, 'never'],
        'space-in-parens': [2, 'never'],
        'space-infix-ops': 2,
        'space-unary-ops': [2, {
          'words': true,
          'nonwords': false
        }],
        'spaced-comment': [2, 'always', {
          'markers': ['global', 'globals', 'eslint', 'eslint-disable', '*package', '!', ',']
        }],
        'template-curly-spacing': [2, 'never'],
        'use-isnan': 2,
        'valid-typeof': 2,
        'wrap-iife': [2, 'any'],
        'yield-star-spacing': [2, 'both'],
        'yoda': [2, 'never'],
        'prefer-const': 2,
        'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
        'object-curly-spacing': [2, 'always', {
          objectsInObjects: false
        }],
        'array-bracket-spacing': [2, 'never']
      }
    }
    
    
  • Done 还看,没了,快去试试吧

标签: 无

非特殊说明,本博所有文章均为博主原创。

头像也是LOGO
未来博客 博主大人
到了这个年纪,不应该再彷徨!

发表评论



 


已有 618 条评论 1


  1. SEO DC in Baltimore

    I seriously love your site.. Excellent colors & theme. Did you make this web site yourself? Please reply back as I’m attempting to create my own blog and would love to learn where you got this from or just what the theme is named. Thank you!

    回复 2020年2月26日
  2. Abbruch aus Lübeck

    Hi, I do believe this is a great blog. I stumbledupon it 😉 I’m going to revisit once again since i have saved as a favorite it. Money and freedom is the best way to change, may you be rich and continue to guide others.

    回复 2020年2月26日
  3. Seemless Gutters Raleigh NC

    Having read this I believed it was very enlightening. I appreciate you taking the time and effort to put this information together. I once again find myself spending a significant amount of time both reading and commenting. But so what, it was still worth it.

    回复 2020年2月26日
  4. a325tc bolt

    Howdy! This is kind of off topic but I need some advice from an established blog. Is it hard to set up your own blog? I’m not very techincal but I can figure things out pretty quick. I’m thinking about creating my own but I’m not sure where to begin. Do you have any points or suggestions? Many thanks

    回复 2020年2月25日
  5. King Weekly Sentinel

    Hi, I do think this is an excellent website. I stumbledupon it 😉 I will revisit yet again since I saved as a favorite it. Money and freedom is the greatest way to change, may you be rich and continue to guide other people.

    回复 2020年2月25日
  6. Superior Home Inspection Fayetteville NC

    Hello there! This post couldn’t be written any better! Looking at this article reminds me of my previous roommate! He always kept talking about this. I will send this information to him. Pretty sure he’s going to have a great read. I appreciate you for sharing!

    回复 2020年2月25日
  7. f1852n bolts

    At this time it seems like Movable Type is the preferred blogging platform out there right now. (from what I’ve read) Is that what you are using on your blog?

    回复 2020年2月25日
  8. modern technology in construction industry

    Hello! This is my 1st comment here so I just wanted to give a quick shout out and tell you I genuinely enjoy reading your articles. Can you recommend any other blogs/websites/forums that go over the same topics? Thank you!

    回复 2020年2月25日
  9. Junk Removal Companies in Raleigh NC

    This site truly has all the information and facts I wanted concerning this subject and didn’t know who to ask.

    回复 2020年2月25日
  10. Best egusi soup in La

    May I just say what a comfort to find somebody that really knows what they are talking about online. You actually understand how to bring a problem to light and make it important. More people should check this out and understand this side of the story. It’s surprising you’re not more popular given that you most certainly possess the gift.

    回复 2020年2月25日
  11. home cleaning

    Do you mind if I quote a couple of your articles as long as I provide credit and sources back to your website? My website is in the very same area of interest as yours and my users would really benefit from a lot of the information you present here. Please let me know if this okay with you. Appreciate it!

    回复 2020年2月25日
  12. superb maids llc

    Yesterday, while I was at work, my cousin stole my iPad and tested to see if it can survive a twenty five foot drop, just so she can be a youtube sensation. My apple ipad is now broken and she has 83 views. I know this is completely off topic but I had to share it with someone!

    回复 2020年2月25日
  13. source

    I seriously love your blog.. Very nice colors & theme. Did you develop this site yourself? Please reply back as I’m trying to create my own personal site and would like to know where you got this from or just what the theme is called. Kudos!

    回复 2020年2月25日
  14. motherhood and work life

    Today, I went to the beachfront with my kids. I found a sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She placed the shell to her ear and screamed. There was a hermit crab inside and it pinched her ear. She never wants to go back! LoL I know this is completely off topic but I had to tell someone!

    回复 2020年2月24日
  15. read more

    I was very pleased to find this web site. I want to to thank you for your time for this fantastic read!! I definitely enjoyed every little bit of it and i also have you saved as a favorite to check out new things in your site.

    回复 2020年2月24日
  16. click here

    Way cool! Some extremely valid points! I appreciate you penning this write-up and the rest of the site is extremely good.

    回复 2020年2月24日
  17. Chinese medicine

    Your style is really unique compared to other people I’ve read stuff from. Thanks for posting when you’ve got the opportunity, Guess I will just bookmark this site.

    回复 2020年2月23日
  18. super peach wear

    Hi, I do think this is a great website. I stumbledupon it 😉 I’m going to revisit once again since I book-marked it. Money and freedom is the greatest way to change, may you be rich and continue to guide others.

    回复 2020年2月23日
  19. John Deere Service Manuals

    I have learned newer and more effective things by means of your blog. One other thing I’d like to say is that newer personal computer operating systems are inclined to allow extra memory to get used, but they likewise demand more memory simply to function. If a person’s computer can’t handle extra memory and also the newest computer software requires that memory increase, it could be the time to buy a new Laptop. Thanks

    回复 2020年2月23日
  20. notebook

    Wonderful article! We will be linking to this particularly great content on our site. Keep up the great writing.

    回复 2020年2月23日
  21. gift basket and flowers

    Hi there! I simply want to give you a huge thumbs up for your excellent info you have got right here on this post. I’ll be returning to your website for more soon.

    回复 2020年2月22日
  22. crazy bulk

    Hi, I do believe your web site could be having web browser compatibility problems. Whenever I look at your website in Safari, it looks fine however, if opening in IE, it’s got some overlapping issues. I simply wanted to give you a quick heads up! Apart from that, excellent blog.

    回复 2020年2月22日
  23. forum male perf

    An impressive share! I have just forwarded this onto a coworker who had been doing a little research on this. And he in fact ordered me dinner simply because I found it for him… lol. So allow me to reword this…. Thank YOU for the meal!! But yeah, thanx for spending time to talk about this issue here on your internet site.

    回复 2020年2月22日
  24. Legal justice Advocates

    The very next time I read a blog, Hopefully it won’t fail me as much as this particular one. After all, Yes, it was my choice to read, but I actually thought you would probably have something helpful to talk about. All I hear is a bunch of crying about something that you can fix if you weren’t too busy seeking attention.

    回复 2020年2月21日
  25. btl toys

    Hi there! This blog post could not be written much better! Looking at this article reminds me of my previous roommate! He constantly kept preaching about this. I most certainly will send this post to him. Fairly certain he’ll have a good read. Many thanks for sharing!

    回复 2020年2月21日
  26. Ummy Video Downloader

    I was able to find good information from your articles.

    回复 2020年2月21日
  27. nail extensions

    Howdy! This blog post couldn’t be written much better! Looking at this post reminds me of my previous roommate! He continually kept talking about this. I most certainly will send this article to him. Fairly certain he’ll have a good read. Thanks for sharing!

    回复 2020年2月21日
  28. most expensive secondary nigeria

    Aw, this was an incredibly good post. Spending some time and actual effort to create a good article… but what can I say… I put things off a whole lot and don’t seem to get nearly anything done.

    回复 2020年2月19日
  29. mobil bahis giris

    After looking over a handful of the articles on your web site, I truly like your way of blogging. I bookmarked it to my bookmark website list and will be checking back soon. Please visit my website as well and tell me your opinion.

    回复 2020年2月19日
  30. holiday ins pre existing conditions

    Today, I went to the beach front with my children. I found a sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She placed the shell to her ear and screamed. There was a hermit crab inside and it pinched her ear. She never wants to go back! LoL I know this is totally off topic but I had to tell someone!

    回复 2020年2月19日
  31. unusual traveler

    Wonderful post but I was wondering if you could write a litte more on this subject? I’d be very grateful if you could elaborate a little bit further. Cheers!

    回复 2020年2月19日
  32. flight insurance

    Superb website you have here but I was wondering if you knew of any community forums that cover the same topics talked about in this article? I’d really like to be a part of online community where I can get feedback from other experienced individuals that share the same interest. If you have any suggestions, please let me know. Thanks!

    回复 2020年2月19日
  33. best digital marketing services

    I’m not sure why but this site is loading incredibly slow for me. Is anyone else having this problem or is it a issue on my end? I’ll check back later and see if the problem still exists.

    回复 2020年2月19日
  34. audio tour guide

    With havin so much content and articles do you ever run into any issues of plagorism or copyright infringement? My site has a lot of unique content I’ve either created myself or outsourced but it looks like a lot of it is popping it up all over the internet without my authorization. Do you know any ways to help protect against content from being stolen? I’d certainly appreciate it.

    回复 2020年2月19日
  35. domestic cruise travel insurance

    My programmer is trying to convince me to move to .net from PHP. I have always disliked the idea because of the expenses. But he’s tryiong none the less. I’ve been using Movable-type on various websites for about a year and am worried about switching to another platform. I have heard very good things about blogengine.net. Is there a way I can import all my wordpress posts into it? Any help would be really appreciated!

    回复 2020年2月19日
  36. Real Estate Las Vegas

    Very good write-up. I absolutely appreciate this website. Keep writing!

    回复 2020年2月19日
  37. Corporate gathering

    This is a topic that is near to my heart… Take care! Where can I find the contact details for questions?

    回复 2020年2月19日
  38. wanderlust travel blog

    I’m not sure why but this blog is loading extremely slow for me. Is anyone else having this issue or is it a problem on my end? I’ll check back later on and see if the problem still exists.

    回复 2020年2月19日
  39. asthma travel insurance cover

    Good day! I could have sworn I’ve been to this site before but after browsing through some of the post I realized it’s new to me. Nonetheless, I’m definitely glad I found it and I’ll be book-marking and checking back frequently!

    回复 2020年2月18日
  40. creative digital marketing

    First off I want to say excellent blog! I had a quick question that I’d like to ask if you do not mind. I was curious to find out how you center yourself and clear your mind before writing. I have had a hard time clearing my mind in getting my thoughts out there. I do enjoy writing but it just seems like the first 10 to 15 minutes are usually wasted just trying to figure out how to begin. Any recommendations or hints? Kudos!

    回复 2020年2月18日
  41. Pablo Bascle

    This writing article support review is basically standard. This review is extremely useful to students accumulated some essay writing details for good essay. Such a essay writing articles are extremely impressive in order to viewers. Thank you pertaining to sharing your notions. anchor |

    回复 2020年2月18日
  42. travel guide

    Greetings! I know this is kind of off topic but I was wondering if you knew where I could find a captcha plugin for my comment form? I’m using the same blog platform as yours and I’m having difficulty finding one? Thanks a lot!

    回复 2020年2月18日
  43. rings

    Hi, I do believe this is an excellent website. I stumbledupon it 😉 I may revisit once again since i have saved as a favorite it. Money and freedom is the best way to change, may you be rich and continue to help others.

    回复 2020年2月18日
  44. princess cruises travel insurance rates

    Please let me know if you’re looking for a article writer for your blog. You have some really good articles and I believe I would be a good asset. If you ever want to take some of the load off, I’d really like to write some material for your blog in exchange for a link back to mine. Please send me an email if interested. Cheers!

    回复 2020年2月18日
  45. executive coaching courses Australia

    Hi, I do believe this is a great site. I stumbledupon it 😉 I may revisit once again since i have saved as a favorite it. Money and freedom is the greatest way to change, may you be rich and continue to help other people.

    回复 2020年2月18日
  46. nhà dat quy nhon

    I absolutely love your website.. Very nice colors & theme. Did you create this site yourself? Please reply back as I’m looking to create my very own blog and would love to learn where you got this from or what the theme is named. Cheers!

    回复 2020年2月18日