返回

巧用Eslint和Vscode,优雅地为你的代码添加copyright注释

前端

Eslint是一个流行的JavaScript代码风格检查工具,它可以帮助你检查代码是否符合特定的编码规范。Vscode是一个流行的代码编辑器,它提供了丰富的扩展功能,可以帮助你提高代码编写效率。

结合Eslint和Vscode,我们可以轻松地实现自动添加copyright注释的功能。具体步骤如下:

  1. 安装Eslint和Vscode扩展。

在Vscode中,打开扩展商店,搜索“Eslint”和“Vscode Eslint”,然后点击“安装”按钮。

  1. 创建.eslintrc文件。

在你的项目根目录下,创建一个名为.eslintrc的文件。该文件用于配置Eslint的规则。

  1. 在.eslintrc文件中添加以下配置:
{
  "rules": {
    "no-unused-vars": ["error"],
    "no-console": ["error"],
    "no-debugger": ["error"],
    "no-alert": ["error"],
    "no-eval": ["error"],
    "no-new-func": ["error"],
    "no-new": ["error"],
    "no-this-assign": ["error"],
    "no-undef": ["error"],
    "no-unreachable": ["error"],
    "no-unused-expressions": ["error"],
    "no-var": ["error"],
    "no-sequences": ["error"],
    "no-ternary": ["error"],
    "no-empty-function": ["error"],
    "no-extra-semi": ["error"],
    "no-implied-eval": ["error"],
    "no-iterator": ["error"],
    "no-label-var": ["error"],
    "no-lone-blocks": ["error"],
    "no-multi-spaces": ["error"],
    "no-multi-str": ["error"],
    "no-octal": ["error"],
    "no-plusplus": ["error"],
    "no-proto": ["error"],
    "no-shadow": ["error"],
    "no-trailing-spaces": ["error"],
    "no-underscore-dangle": ["error"],
    "no-use-before-define": ["error"],
    "no-void": ["error"],
    "no-with": ["error"],
    "consistent-return": ["error"],
    "curly": ["error"],
    "default-case": ["error"],
    "dot-notation": ["error"],
    "eqeqeq": ["error"],
    "guard-for-in": ["error"],
    "handle-callback-err": ["error"],
    "no-caller": ["error"],
    "no-cond-assign": ["error"],
    "no-console": ["error"],
    "no-constant-condition": ["error"],
    "no-debugger": ["error"],
    "no-empty": ["error"],
    "no-empty-character-class": ["error"],
    "no-ex-assign": ["error"],
    "no-extra-boolean-cast": ["error"],
    "no-extra-parens": ["error"],
    "no-floating-decimal": ["error"],
    "no-global-assign": ["error"],
    "no-implicit-coercion": ["error"],
    "no-invalid-regexp": ["error"],
    "no-invalid-this": ["error"],
    "no-lone-blocks": ["error"],
    "no-misleading-character-class": ["error"],
    "no-mixed-operators": ["error"],
    "no-multi-spaces": ["error"],
    "no-multi-str": ["error"],
    "no-new": ["error"],
    "no-new-func": ["error"],
    "no-new-object": ["error"],
    "no-new-wrappers": ["error"],
    "no-octal": ["error"],
    "no-octal-escape": ["error"],
    "no-param-reassign": ["error"],
    "no-proto": ["error"],
    "no-regex-spaces": ["error"],
    "no-return-assign": ["error"],
    "no-script-url": ["error"],
    "no-sequences": ["error"],
    "no-shadow": ["error"],
    "no-shadow-restricted-names": ["error"],
    "no-sparse-arrays": ["error"],
    "no-template-curly-in-string": ["error"],
    "no-ternary": ["error"],
    "no-this-assign": ["error"],
    "no-trailing-spaces": ["error"],
    "no-undef": ["error"],
    "no-undef-init": ["error"],
    "no-undefined": ["error"],
    "no-unused-expressions": ["error"],
    "no-unused-labels": ["error"],
    "no-unused-vars": ["error"],
    "no-use-before-define": ["error"],
    "no-useless-call": ["error"],
    "no-useless-catch": ["error"],
    "no-useless-concat": ["error"],
    "no-useless-escape": ["error"],
    "no-useless-return": ["error"],
    "no-void": ["error"],
    "no-warning-comments": ["error"],
    "no-with": ["error"],
    "array-bracket-spacing": ["error"],
    "block-spacing": ["error"],
    "brace-style": ["error"],
    "camelcase": ["error"],
    "comma-dangle": ["error"],
    "comma-spacing": ["error"],
    "comma-style": ["error"],
    "computed-property-spacing": ["error"],
    "consistent-this": ["error"],
    "eol-last": ["error"],
    "func-call-spacing": ["error"],
    "func-name-matching": ["error"],
    "func-style": ["error"],
    "function-paren-newline": ["error"],
    "indent": ["error"],
    "jsx-quotes": ["error"],
    "key-spacing": ["error"],
    "keyword-spacing": ["error"],
    "linebreak-style": ["error"],
    "lines-around-comment": ["error"],
    "max-depth": ["error"],
    "max-len": ["error"],
    "max-nested-callbacks": ["error"],
    "max-params": ["error"],
    "max-statements": ["error"],
    "max-statements-per-line": ["error"],
    "multiline-ternary": ["error"],
    "new-cap": ["error"],
    "new-parens": ["error"],
    "no-array-constructor": ["error"],
    "no-bitwise": ["error"],
    "no-continue": ["error"],
    "no-inline-comments": ["error"],
    "no-lonely-if": ["error"],
    "no-mixed-spaces-and-tabs": ["error"],
    "no-multiple-empty-lines": ["error"],
    "no-nested-ternary": ["error"],
    "no-new-object": ["error"],
    "no-plusplus": ["error"],
    "no-restricted-syntax": ["error"],
    "no-tabs": ["error"],
    "no-ternary": ["error"],
    "no-trailing-spaces": ["error"],
    "no-underscore-dangle": ["error"],
    "no-unneeded-ternary": ["error"],
    "no-whitespace-before-property": ["error"],
    "object-curly-newline": ["error"],
    "object-curly-spacing": ["error"],
    "object-property-newline": ["error"],
    "one-var": ["error"],
    "one-var-declaration-per-line": ["error"],
    "operator-assignment": ["error"],
    "operator-linebreak": ["error"],
    "padded-blocks": ["error"],
    "quote-props": ["error"],
    "quotes": ["error"],
    "semi": ["error"],
    "semi-spacing": ["error"],
    "sort-keys": ["error"],
    "sort-vars": ["error"],
    "space-before-blocks": ["error"],
    "space-before-function-paren": ["error"],