简体   繁体   中英

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:

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

//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. 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. 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.

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

You don't need to concatenate any files to use eslint-config-airbnb-base. Install it and create .eslintrc and you should be good to go.

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. The last step is to have an .eslintrc that refers to this new file with extends.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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