简体   繁体   English

如何将 eslint airbnb 风格指南合并成一个文件以复制到 package.json 中?

[英]How can I concatinate the eslint airbnb style guide into one file to copy into package.json?

If you look at these directories and quoted file contents you can see the structure of the style guide .js files and how they all load into eslint:如果您查看这些目录和引用的文件内容,您可以看到样式指南 .js 文件的结构以及它们如何加载到 eslint 中:

https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb-base https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb-base

https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb-base/rules https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb-base/rules

//index.js

module.exports = {
  extends: [
    './rules/best-practices',
    './rules/errors',
    './rules/node',
    './rules/style',
    './rules/variables',
    './rules/es6',
    './rules/imports', // (my note) not needed as uses extra plugin
  ].map(require.resolve),
  parserOptions: {
    ecmaVersion: 2018,
    sourceType: 'module',
  },
  rules: {
    strict: 'error',
  },
};

// .eslintrc
{
  "extends": "./index.js",
  "rules": {
    // disable requiring trailing commas because it might be nice to revert to
    // being JSON at some point, and I don't want to make big changes now.
    "comma-dangle": 0,
    // we support node 4
    "prefer-destructuring": 0,
  },
}

I would like to concatinate all the files together so I can paste it into my package.json.我想将所有文件连接在一起,以便将其粘贴到我的 package.json 中。 How can I do this?我怎样才能做到这一点? I don't know node, I don't need all the other stuff in the NPM download, I would just like a permanent copy of the current style guide in one file in one place.我不知道节点,我不需要 NPM 下载中的所有其他内容,我只想将当前样式指南的永久副本放在一个文件中的一个地方。 Cheers!干杯!

If you follow the instructions on installing eslint-config-airbnb-base: https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb-base#eslint-config-airbnb-base-1 , step 2 asks you to create a file .eslintrc in your project's root directory. 如果您遵循有关安装eslint-config-airbnb-base的说明: https : //github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb-base#eslint-config-airbnb-base-1 ,步骤2要求您在项目的根目录中创建文件.eslintrc

// .eslintrc
{
  "extends": "airbnb-base"
}

You don't need to concatenate any files to use eslint-config-airbnb-base. 您无需连接任何文件即可使用eslint-config-airbnb-base。 Install it and create .eslintrc and you should be good to go. 安装它并创建.eslintrc ,您应该.eslintrc顺利。

I know this is old and I have not tried this but it should work.我知道这是旧的,我还没有尝试过,但它应该可以工作。 Just copy the rule files from the Airbnb repo into your repo and then create a new copy from their index.js file called something else like "my-eslint-rules.js" in your repo.只需将 Airbnb 存储库中的规则文件复制到您的存储库中,然后从他们的 index.js 文件中创建一个新副本,在您的存储库中称为“my-eslint-rules.js”。 The last step is to have an .eslintrc that refers to this new file with extends.最后一步是使用 .eslintrc 来引用这个带有扩展名的新文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM