grayshine
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # <font class="h2">ESlint規範工具</font> ###### tags: `vscode` <style> .h2 { background: linear-gradient(135deg,#fff,#537479) ; color: #537479; display:block; padding: 6px 5px; border-radius: 4px; } .h3 { background: linear-gradient(180deg,#fff 50%,#c9d5d4) ; color: #537479; display:block; padding: 6px 5px; border-bottom: 3px solid #537479; } .h4 { color: #537479; font-weight:bold; font-size:1.1em; } </style> ![](https://i.imgur.com/Jhdbj8s.png) :arrow_right:https://eslint.org/docs/user-guide/getting-started ESLint(Coding Style) 會有什麼影響 - 程式碼會極度整齊,潔癖者推薦使用 - 團隊開發會有一致性 - 透過提示,可學習更好的語法習慣 - 搭配 Webpack 或框架 cli,如果不符合規範會無法編譯 <br><br><br><br> ### <font class="h3">全域安裝</font> ### <font class="h4">➤用npm全域安裝ESLint套件</font> ![](https://i.imgur.com/hlANbFQ.png) `npm install -g eslint` <br><br><br><br> ### <font class="h4">➤產生package.json檔案</font> ![](https://i.imgur.com/kdekaWL.png) ![](https://i.imgur.com/3lPJNH7.png) <br><br><br><br> ### <font class="h4">➤安裝設定eslint</font> `eslint --init` ![](https://i.imgur.com/h1YkCAd.png) <br> ![](https://i.imgur.com/tebd3Z5.png) <br> ![](https://i.imgur.com/WRlU3sf.png) <br> ![](https://i.imgur.com/V7M8yDJ.png) <br> ![](https://i.imgur.com/lRSq9Xq.png) <br> 這邊選用規範類型,下面就可以不用設定 ![](https://i.imgur.com/wLkmOsJ.png) Airbnb是裡面最嚴格的,Standard是較為寬鬆的 Standard規範: - 兩空白鍵 - 單引號 - 不加分號 ![](https://i.imgur.com/7b4Ke9m.png) <br><br><br><br><br><br> ### <font class="h4">➤如果不選規範類型,自訂義</font> ![](https://i.imgur.com/egis2pp.png) <br> ![](https://i.imgur.com/X18cr8F.png) <br> ![](https://i.imgur.com/aifPCCo.png) <br> ![](https://i.imgur.com/bdQQ8Yu.png) <br> ![](https://i.imgur.com/WMPuRQU.png) <br> ```json { "env": { "browser": true, "es2021": true, "node": true }, "extends": [ "standard" ], "parserOptions": { "ecmaVersion": "latest", "sourceType": "module" }, "rules": { "indent": [ "error", 2 //空格要幾格 ], "linebreak-style": [ "error", "windows" //使用windows的換行,默認是使用unix ], "quotes": [ "error", "single" //使用單引號 ], "semi": [ "error", "never" //是否加分號(不要打always) ], "no-unused-var": [ "off" //將未使用的變數錯誤提醒關閉 ] } } ``` :::info CRLF是carriage return的意思,也就是\r, windows系統環境下的換行方式 LF是line feed的意思,也就是\n, Linux系統環境下的換行方式 這就是為什麼有些檔案從unix系統拿去windows上面看 會變成全部都在同一行 因為只有LF 他不知道是換行 ::: <br><br><br><br> ### <font class="h4">➤eslint的其他的設置</font> ![](https://i.imgur.com/KImpfe8.png) ```javascript module.exports = { // 目前專案是在什麼環境執行, 如果沒有設定 browser:true, 那就不會有 window 物件 env: { browser: true, es6: true, node: true, }, // 直接採用 airbnb-base eslint 設定 extends: [ 'airbnb-base', ], // globals 變數,一般指的都是 windows.xxx 變數 globals: { $: 'readonly', }, parser: 'babel-eslint', settings: { // eslint 可以讀取 webpack alias 設定 'import/resolver': { webpack: { config: 'webpack.config.js', }, }, }, rules: { 'global-require': 0, 'import/no-extraneous-dependencies': 0, 'import/prefer-default-export': 0, 'no-plusplus': ['error', { allowForLoopAfterthoughts: true }], }, }; ``` <br><br><br><br><br><br><br><br> ### <font class="h3">vscode設定檔</font> ![](https://i.imgur.com/ALkL9NA.png) 選用工作區來設定(for專案) <br> ![](https://i.imgur.com/rAZCrf0.png) ```json { "editor.codeActionsOnSave": { "source.fixAll.eslint": true //存檔自動修正eslint的錯誤 }, "eslint.validate": [ //檢查那些檔案類型 "javascript", "vue" ], "vetur.validation.template": false //關閉vetur的檢查,避免影響eslint } ``` <br><br><br><br> <br><br><br><br><br><br> ### <font class="h3">專案安裝</font> ### <font class="h4">➤npm init</font> ![](https://i.imgur.com/BhjbEZc.png) ![](https://i.imgur.com/ergJKsf.png) <br><br><br><br> ### <font class="h4">➤`npm install eslint --save-dev`安裝eslint</font> ![](https://i.imgur.com/MXeWvKM.png) ![](https://i.imgur.com/YuekzrA.png) <br><br><br><br> ### <font class="h4">➤`npm init @eslint/config`設定eslint</font> ![](https://i.imgur.com/YcNIaJQ.png) ![](https://i.imgur.com/ADKzR5j.png) <br><br><br><br> ### <font class="h4">➤選擇格式化工具</font> ![](https://i.imgur.com/n8H0IBN.png) ![](https://i.imgur.com/BxMO508.png) <br><br><br><br><br><br> ### <font class="h3">常用的rules:</font> ```json rules: { indent: [2, 4], // 縮排規則,index[0] 的數字代表含意為 關閉(0), 警告(1), 錯誤(2) quotes: [2, 'single'], // 單引號, 雙引號 semi: [2, 'never'], // 句尾是否加上 ";" 'no-use-before-define': [2, 'nofunc'], //變數是否一定要宣告賦值 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off', // 是否留下 console.log 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off', // 是否留下 debugger 'comma-spacing': [2, { // 關於 , 的規則,前後是否有空格 before: false, after: true }], 'key-spacing': [1, { // 關於 key 的 ":" 前後是否有空格 beforeColon: false, afterColon: true }], 'import/first': [0], // 雖說 import 都會先 Hoisting,在這些行數中間可否插入其他的變數或是函式 'object-property-newline': [2, { // Object 的撰寫規則,詳請請查閱官方文件 allowAllPropertiesOnSameLine: false }], 'object-curly-newline': [1, { // Object 的撰寫規則,詳請請查閱官方文件 ObjectExpression: 'always', ImportDeclaration: 'always', ExportDeclaration: 'never' }], 'vue/html-indent': [1, 4, { // Vue 中的 html 的撰寫規則,詳請請查閱官方文件 attribute: 1, baseIndent: 1, closeBracket: 0, alignAttributesVertically: true, ignores: [] }], 'vue/html-closing-bracket-newline': [2, { // Vue 中的 html 的撰寫規則,詳請請查閱官方文件 singleline: 'never', multiline: 'always' }], 'vue/html-closing-bracket-spacing': [2, { // Vue 中的 html 的撰寫規則,詳請請查閱官方文件 selfClosingTag: 'always' }] } ``` <br><br><br><br> ### <font class="h3">排除eslint檢查</font> ### <font class="h4">➤此句不檢查</font> ```javascript var ignoreESLintLine = 0; // eslint-disable-line ``` <br><br> ### <font class="h4">➤此段不檢查</font> ```javascript /* eslint-disable */ var a = 0; var b = 1; /* eslint-enable */ ``` <br><br> ### <font class="h4">➤那些檔案不檢查</font> ![](https://i.imgur.com/sDxbu29.png) <br><br><br><br><br><br> --- https://wcc723.github.io/javascript/2018/01/01/javascript-eslint/ https://wcc723.github.io/tool/2017/11/09/coding-style/

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully