From 089e7f48644f762ace288f5d05597f232ddd0bcc Mon Sep 17 00:00:00 2001 From: David Bradshaw Date: Fri, 12 Jun 2020 12:53:21 +0100 Subject: [PATCH] Add Node and Compat --- README.md | 4 ++-- index.js | 6 +----- package.json | 32 +------------------------------- plugins.js | 18 ++++++++++++++++++ rules/compat.js | 6 ++++++ rules/node.js | 6 ++++++ 6 files changed, 34 insertions(+), 38 deletions(-) create mode 100644 plugins.js create mode 100644 rules/compat.js create mode 100644 rules/node.js diff --git a/README.md b/README.md index 490957e..c449ab3 100644 --- a/README.md +++ b/README.md @@ -51,11 +51,11 @@ If the project includes Babel, then [eslint-plugin-babel]() will be loaded and t ### Compat -[TODO] If no transpiler is detected and `env.browser = true` in your `.eslintrc`, then [eslint-plugin-compat](https://github.com/amilajack/eslint-plugin-compat) is loaded. +If no transpiler is detected and `env.browser = true` in your `.eslintrc`, then [eslint-plugin-compat](https://github.com/amilajack/eslint-plugin-compat) is loaded. ### Node -[TODO] If `env.node = true` in your `.eslintrc` file, then [eslint-plugin-node](https://github.com/mysticatea/eslint-plugin-node) is loaded. +If `env.node = true` in your `.eslintrc` file, then [eslint-plugin-node](https://github.com/mysticatea/eslint-plugin-node) is loaded. ### React diff --git a/index.js b/index.js index b691f65..8450ebf 100644 --- a/index.js +++ b/index.js @@ -5,15 +5,11 @@ const showLoaded = require('./lib/loaded') const { hasAnyDep } = require('./lib/utils') const { configs } = require('./configs') +const plugins = require('./plugins') -const plugins = [] - -const hasBabel = hasAnyDep('babel') const hasReact = hasAnyDep('react') const hasTypescript = hasAnyDep('typescript') -if (hasBabel || hasAnyDep('@babel/core')) plugins.push('babel') - const airbnbDependentcies = ['import'] if (hasReact) airbnbDependentcies.push('jsx-a11y', 'react', 'react-hooks') diff --git a/package.json b/package.json index 1ab4e51..5045cae 100644 --- a/package.json +++ b/package.json @@ -38,38 +38,8 @@ "rimraf": "^3.0.2" }, "devDependencies": { - "babel": "^6.23.0", "eslint": "^7.2.0", - "eslint-config-airbnb": "^18.1.0", - "eslint-config-prettier": "^6.11.0", "eslint-find-rules": "^3.5.0", - "eslint-plugin-array-func": "^3.1.6", - "eslint-plugin-babel": "^5.3.0", - "eslint-plugin-eslint-comments": "^3.2.0", - "eslint-plugin-html": "^6.0.2", - "eslint-plugin-import": "^2.21.2", - "eslint-plugin-json": "^2.1.1", - "eslint-plugin-json-format": "^2.0.1", - "eslint-plugin-jsx-a11y": "^6.2.3", - "eslint-plugin-lodash": "^7.1.0", - "eslint-plugin-lodash-fp": "^2.2.0-a1", - "eslint-plugin-markdown": "^1.0.2", - "eslint-plugin-no-constructor-bind": "^2.0.0", - "eslint-plugin-no-secrets": "^0.6.8", - "eslint-plugin-no-unsanitized": "^3.1.2", - "eslint-plugin-no-use-extend-native": "^0.5.0", - "eslint-plugin-optimize-regex": "^1.2.0", - "eslint-plugin-prettier": "^3.1.3", - "eslint-plugin-promise": "^4.2.1", - "eslint-plugin-ramda": "^2.5.1", - "eslint-plugin-react": "^7.20.0", - "eslint-plugin-react-hooks": "^4.0.4", - "eslint-plugin-scanjs-rules": "^0.2.1", - "eslint-plugin-security": "^1.4.0", - "eslint-plugin-simple-import-sort": "^5.0.3", - "eslint-plugin-sonarjs": "^0.5.0", - "eslint-plugin-switch-case": "^1.1.2", - "eslint-plugin-unicorn": "^20.1.0", "husky": "^4.2.5", "in-publish": "^2.0.1", "prettier": "^2.0.5", @@ -78,6 +48,6 @@ "safe-publish-latest": "^1.1.4" }, "engines": { - "node": ">= 8" + "node": ">= 8.3" } } diff --git a/plugins.js b/plugins.js new file mode 100644 index 0000000..084ba33 --- /dev/null +++ b/plugins.js @@ -0,0 +1,18 @@ +const { cosmiconfigSync } = require('cosmiconfig') + +const { hasAnyDep } = require('./lib/utils') + +const explorerSync = cosmiconfigSync('eslint') +const eslintrc = explorerSync.search() +const { env } = eslintrc.config + +const hasBabel = hasAnyDep('babel') || hasAnyDep('@babel/core') + +const plugins = [] + +if (hasBabel) plugins.push('babel') +if (env.node) plugins.push('node') + +if (env.browser && !hasBabel && !hasAnyDep('typescript')) plugins.push('compat') + +module.exports = plugins diff --git a/rules/compat.js b/rules/compat.js new file mode 100644 index 0000000..12949ba --- /dev/null +++ b/rules/compat.js @@ -0,0 +1,6 @@ +// eslint-disable-next-line no-console +console.log(' eslint-plugin-compat') + +module.exports = { + extends: ['plugin:compat/recommended'], +} diff --git a/rules/node.js b/rules/node.js new file mode 100644 index 0000000..feb97af --- /dev/null +++ b/rules/node.js @@ -0,0 +1,6 @@ +// eslint-disable-next-line no-console +console.log(' eslint-plugin-node') + +module.exports = { + extends: ['plugin:node/recommended'], +}