新手上路

ESLint 是一种用于识别和报告在 ECMAScript/JavaScript 代码中发现的模式的工具,其目标是使代码更加一致并避免错误。

ESLint 是完全可插拔的。每条规则都是一个插件,您可以在运行时添加更多。您还可以添加社区插件、配置和解析器来扩展 ESLint 的功能。

先决条件

要使用 ESLint,您必须安装并构建 Node.js^12.22.0^14.17.0>=16.0.0)并支持 SSL。(如果您使用的是官方 Node.js 发行版,则始终内置 SSL。)

快速开始

您可以使用以下命令安装和配置 ESLint:

npm init @eslint/config

如果您想使用托管在 npm 上的特定可共享配置,您可以使用 --config 选项并指定包名称:

# use `eslint-config-semistandard` shared config

# npm 7+
npm init @eslint/config -- --config semistandard

# or (`eslint-config` prefix is optional)
npm init @eslint/config -- --config eslint-config-semistandard

# ⚠️ npm 6.x no extra double-dash:
npm init @eslint/config --config semistandard

frnws110D6/N2KR08fvIjfcemwr9QIjxODo6a5U0Y+cxZp8zM75xLchEtBhVhHpOMuxjQnPe1KQl8Vfs/xE94w==

npm init @eslint/config -- --config semistandard,standard
# or
npm init @eslint/config -- --config semistandard --config standard

vAalFFDKMkNpIMn8Zb6xSIJMrTNTiL7NOdT+LT/S6zzL4yvBsKaLLJhchFNEnD8IBGGAQCo5Vvkpiq85UjdO2ET4TPNHN11GDTjBj8AlI6xE1LQ5CCSBwvr3DTMWFBR2XoLD2nOm6p+e7cxVaEmlSD25j12ulUi89QWBEswcCXvt6cA9jChwcT5veKIrMjvxidUVpuYjxQFZivM6yIU//xsQW3tuZ591Lts0wxJK8i7LWn7apoJs3bFlAVL6IBYETuOH444NbXGh1oWGpcwq59p6oUfZqV6IN37BFckMQp4=

Q3AZQmRhyw0mi0Saq5sdxPLIZLF/72tkhiUjrRhLppR+8PyZkDmQwngLBqVWqbi28oVGT+RWoYlLVgc5Eq9gXKlwOF0mknwqtlh2gs5TGSM=

npx eslint yourfile.js

# or

yarn run eslint yourfile.js

配置

vAalFFDKMkNpIMn8Zb6xSN+o6f2lrnZfongiUlUQHdHhaoqVvT0bt2nP6zJsuJ8GOep1VUb1uSoTbLsnSld4rqcpYfE8gE+iYQwsLqHmBQyJIqr6RQPILd7TZlAo25q8+bqx/84sg4t0jUCwbLYvQ6sSs+OeTc0AxY31HwUn0Qz5NlwTd/GkQxpuUyrYQxvi

dMoyDxIXWQsP72c6THgTLbcgVese3KMTs79FXu1HFHBCCg794TjGXTco9gORI1xWEPUCdvexebRzrPTq7p3Ac342T3EWGt7XYYWTjEsNbQdDWjpp7LqSCmIOvWnp/1FGXnEHdGzJSiNpyi3FGXF88HMsAzaO67CrBjJZHc9SAzqqgayd7Bdxdg98UgBIU++6iTG509yaVHaS5JTVi/cJBKPH3Rn/2AkqiBGZ9GF8qoG6sbgmdhz8AhxDoCUlkmtd

{
    "rules": {
        "semi": ["error", "always"],
        "quotes": ["error", "double"]
    }
}

kYWSRheOnFPJ+smxi2eLRDsXL2+Fg2ArHUwqg2haDYFEceM+HkJASkO+fWg2Y7SgxFuccrJD9eaRTOzgkCHZ5hsmU7/XZcnXGdflUEaNfFsQ9kPNdbxsvi5varBLIoOYvzprjamUG11UHQRqAFf/QmZ6RQdt2u//FHBoZ/ne3t0mIy45mwO3RRshxU/k+/SIYMuJKNJ/2yFcBeAEaWRVD+NG0m7KyYJ6oC4SQttloPG2iZuIkUU2/ycBmCrHf+QtugQib3+zG1wZtxWXI3px1A==

    1c6oHZlLfjKdIs+02SQYlC65qp4/pUarQIrQwFJHQCfmk8JYWGYWHvW+0Hr0AP+YZRP+qpJ1lhb+Rr/TuYBKDECDU3kGqUEKkvfqiVeA7SsuFAfd7uZDb7Mqr8SYG3mTeYL0EqVvpU/tU6XLOxMo7DlrpgIfCLas+nrYhLLAyR+7Euwpzql7Mle2OpHp2D0CNzrSSzAm0OXNmlFobaUVvzQ+hEW2zpeNCSst0ltWsfX9K5kmQne2vSigrTjDVwUBB27vFwtkNhNmFK0p1yVtXwLpB9N4jtnM+3XvAhEVGfGwaYCU4ZP3YT/4Aaxgx65tMOa56VWFeh8aPE9HsWsav892SL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1rwzcnj1ss6e0nFZ/Z/jdUEC25C2fP7iXyjPTqJDmwyiIk5b5rltwghs4Jk5NQ0HhPAlI4GhuRikxjVWZlKBeMzHPO2r4dFYRZWMBAp06cFmES0VPV7Snq7E87nSXPUz+dYbpwKYccZXsRgaX7PcLwO+tDTKv1ye1Aw9AWyR4MUP++vG1k2ERIGhJlvb0kVJW2tTQMRbUJh6kTGwLtUSlJxNPfG90T0VzX4lfZ1UKCrMXCrP

手动设置

CFonXjE55lLE6pKxcH9GL3AebKgw2xCMF8yqAobb24lRuhiA/64+BwABRjjuOJHg

JPHzmpYD16d491dCQy996L223BLdaGtpHZtCPhlCquVD1D5P9uS93xbKYMWLezOKZ8LDVvbOe0tfvQ5ss0Kna1wEtfOOXAZuB/ZkJfszU9Z3N7bc4kYk3nhTQ2jUAm+87viEFhpEw3IxrvIH2ptS5PJBlgy46ur7dupLWd0TjnMgFs1OEt14pZ+MHMHrtKS9K1721c7Oj+HHYwwludAFy8lAQkSAczqXB1eIWX3d3tfMTNfjdEaNF2+ZENzkiClb

  1. q5yBAcHwVbTqQGMvDcsAvkUNq1xKnB61ELqJS5AEchRtp4BiWZtD7QrDHQSC1nQD

    npm install --save-dev eslint
    
  2. SeIXcUNernvb67O91F34+8GbPZERu3PHJYGOVwmvxqELdeL0KL8VGmppBTaNZ2nB8VoKh8QCnU0WGUCZa7Ww2pIQ2Xt07hzpYTaTB8buOOC+AxGGfJCYMrTYkgjC50QuFP3YGDpeMyiQ9izMw2yKFsBoVEBdOygXD6NRYQkCzAEjemzfKIUexNdBU0l1dROP

    # Create JavaScript configuration file
    touch .eslintrc.js
    
  3. CRB4/fMqbhqRsGlbAk+d89mQFGVPd8RoS+ucYU3wRPS3V6dpl6cJCMsX4Kxo39CUh571JC7UpDC2s5qCuVUFPFTpOKqQ3kmnmwbNxYr34N92GmRhvY+m2Xj377wWB5PnlN6uy57TqF14NE8mjnqp//+Mrmx1Drun3aovC9z4fTBeyusTx+Kdy7mURpTexN/yOSWjCbsvs3WBfb53jbPlKHc9o2jpbXu72qDVxrBwRNFNFH4hbAGYviWUAR/VKVBUgmoW5sNXgLUvtijQi3p+Kw==

    // .eslintrc.js example
    module.exports = {
      "env": {
          "browser": true,
          "es2021": true
      },
      "extends": "eslint:recommended",
      "parserOptions": {
          "ecmaVersion": "latest",
          "sourceType": "module"
      },
    }
    
  4. PR2WeO3CR+xayK9MsCBnlLvgh58b1RL79zJOH0lOizw/YR4mIrmL1J3S9/T2SU9T

    npx eslint project-dir/ file1.js
    

    qdwA7TXLV2992MMMACmP8t0lApPJKGDRB+xgMvdrquxV04y/SWizND90Wn1LyfHNdjR5R5RLo0kC1OB0MO3fX/NIR4JdlDHEUjIq+A7GdfFI/TCvD2w35EtUuw5I23vkIMVeLHi1iLQ8/ntjoYNSY4vAp23e1z721o3aDhLEgkU=


下一步

    qoBNNGEjUU/NSARmUzm5F3iYT4ncXyg194si0h6r7xx96DJmQAiclsayxiEWMJOo8vDWc65DitBiK4ZWXBrINfI4+/i/Aeq8LXUONSjLAYxKzRh0vbv/romyrWIwUq4tc9slBKTSwAipWBenShd6uLjtA3J/ni/+1Wf47+Bt+iTeuJBLVs4HH86LIv636J5naszdazNO75AUkwwk3dnb84/VvEu377bMzpETF0Mig0XPH7cG+PANx65imlVDZ0rCSTa3PTGinv7oEDHrYVAa1xOtCFPs+yYkdchY2iHhDT2hdTHoetz0K1yuAfeE+qqbzRBSxZXt/bO0DuizJ0mP8iyzs6lVC6O8pnzwa4m5Tm3p8E+iQ5b9mq0OYzoIvizFN2lnNMroDMFY2EJc1MOOSb9u7tWg1OEQPmgRdMSj6X4KscNFuZ84MIz7JXWvO8s9b1lnMW4ldIW8JxJ3lgbEvKZjCrf/kBERRaLEsL0Hd4X3Q9Zv1Jc7nmMaiPNZvDHhaMXZu8LQHkXutKYf81+Jx8UNdF7jrSNiNjBt9YVU4hhNqUE7l26za51DxoR+vByyRR/8FSctByaZcfSrwpRe46cupHGqOLscDq/O+57pmKttwOeT7302an++mWIe+mLEm6eZ+XoPmgymQ8ksoDAMndqAixeXXIs6FwMjFetTCKp0AgyZylhxtMc3q4Amxols