diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d1d6a4..a1148b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org). Except add new rule (it is breaking changed by default). +## 91.1.0 - 2018-12-07 + +- Added: `utils.modifyPresetRules("presetName", callback)` helper (allow enable/disable preset rules). + ## 91.0.0 - 2018-12-07 - Changed: `react` present doesn't extend `esnext` preset. diff --git a/__tests__/utils.js b/__tests__/utils.js new file mode 100644 index 0000000..6dd7b54 --- /dev/null +++ b/__tests__/utils.js @@ -0,0 +1,23 @@ +import test from "ava"; +import { utils } from ".."; + +test("modifyPresetRules", t => { + const modifiedNodePresetRules = utils.modifyPresetRules("node", () => false); + + // Specify rule + t.true(modifiedNodePresetRules["global-require"] === false); + // From extend plugin + t.true(modifiedNodePresetRules["node/no-deprecated-api"] === false); + + const modifiedEsnextPresetRules = utils.modifyPresetRules( + "esnext", + () => false + ); + + // Specify rule + t.true(modifiedEsnextPresetRules["consistent-return"] === false); + // From extend plugin + t.true(modifiedEsnextPresetRules["promise/catch-or-return"] === false); + // From `eslint:recommended` + t.true(modifiedEsnextPresetRules["no-unreachable"] === false); +}); diff --git a/index.js b/index.js index fa61a87..9c55499 100644 --- a/index.js +++ b/index.js @@ -11,6 +11,7 @@ const lodash = require("./lib/config/lodash"); const markdown = require("./lib/config/markdown"); const node = require("./lib/config/node"); const react = require("./lib/config/react"); +const utils = require("./lib/utils"); const configs = { all, @@ -28,5 +29,5 @@ const configs = { module.exports = { configs, - rules: {} + utils }; diff --git a/lib/.eslintrc.json b/lib/.eslintrc.json deleted file mode 100644 index c81d24d..0000000 --- a/lib/.eslintrc.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "rules": { - "quotes": "off", - "sort-keys": "off", - "quote-props": ["error", "always"] - } -} diff --git a/lib/utils.js b/lib/utils.js new file mode 100644 index 0000000..d29657a --- /dev/null +++ b/lib/utils.js @@ -0,0 +1,22 @@ +"use strict"; + +const eslint = require("eslint"); +const path = require("path"); + +function modifyPresetRules(presetName, modificator) { + // eslint-disable-next-line import/no-dynamic-require, global-require + const config = require(path.resolve(__dirname, "config", presetName)); + const cli = new eslint.CLIEngine({ + baseConfig: config, + useEslintrc: false + }); + const presetRules = cli.config.baseConfig.rules; + + Object.keys(presetRules).forEach(rule => { + presetRules[rule] = modificator(presetRules[rule]); + }); + + return presetRules; +} + +module.exports = { modifyPresetRules }; diff --git a/package-lock.json b/package-lock.json index 58d9919..e39066e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-itgalaxy", - "version": "91.0.0", + "version": "91.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 929a02f..0c5a052 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-itgalaxy", - "version": "91.0.0", + "version": "91.1.0", "description": "Itgalaxy org's ESLint rules and configs.", "keywords": [ "eslint", @@ -103,6 +103,16 @@ "./lib/config/markdown.js" ], "overrides": [ + { + "files": [ + "lib/config/**/*.{js,mjs,jsx}" + ], + "rules": { + "quotes": "off", + "sort-keys": "off", + "quote-props": ["error", "always"] + } + }, { "files": [ "**/__tests__/**/*.{js,mjs,jsx}"