@putout/cli-ruler
Advanced tools
+11
-7
| import {join} from 'path'; | ||
| import tryToCatch from 'try-to-catch'; | ||
@@ -7,6 +6,11 @@ import * as ruleProcessor from './rule-processor.js'; | ||
| const cwd = process.cwd(); | ||
| const {parse, stringify} = JSON; | ||
| export async function ruler({disable, disableAll, enable, enableAll, readFile, writeFile}, places) { | ||
| const { | ||
| parse, | ||
| stringify, | ||
| } = JSON; | ||
| export async function ruler(places, {disable, disableAll, enable, enableAll, readFile, writeFile}) { | ||
| const name = join(cwd, '.putout.json'); | ||
| const defaultData = stringify({ | ||
@@ -22,9 +26,9 @@ rules: {}, | ||
| if (enable) | ||
| updated = ruleProcessor.enable(object, enable); | ||
| updated = ruleProcessor.enable(enable, object); | ||
| else if (disable) | ||
| updated = ruleProcessor.disable(object, disable); | ||
| updated = ruleProcessor.disable(disable, object); | ||
| else if (enableAll) | ||
| updated = ruleProcessor.enableAll(object, places); | ||
| updated = ruleProcessor.enableAll(places, object); | ||
| else if (disableAll) | ||
| updated = ruleProcessor.disableAll(object, places); | ||
| updated = ruleProcessor.disableAll(places, object); | ||
@@ -31,0 +35,0 @@ await writeFile(name, stringify(updated, null, 4)); |
+10
-10
| const getRule = (a) => a.rule; | ||
| const initRules = (config) => { | ||
@@ -12,3 +13,3 @@ config.rules = config.rules || {}; | ||
| const isPutoutRule = (rule) => { | ||
| if (/^parser/.test(rule)) | ||
| if (rule.startsWith('parser')) | ||
| return false; | ||
@@ -22,3 +23,3 @@ | ||
| export const disableAll = (config, places) => { | ||
| export const disableAll = (places, config) => { | ||
| initRules(config); | ||
@@ -30,6 +31,6 @@ | ||
| for (const rule of existingRules) | ||
| disable(config, rule); | ||
| disable(rule, config); | ||
| for (const rule of rules) | ||
| disable(config, rule); | ||
| disable(rule, config); | ||
@@ -39,3 +40,3 @@ return config; | ||
| export function enable(config, rule) { | ||
| export function enable(rule, config) { | ||
| initRules(config); | ||
@@ -51,3 +52,3 @@ | ||
| export function disable(config, rule) { | ||
| export function disable(rule, config) { | ||
| initRules(config); | ||
@@ -66,3 +67,3 @@ | ||
| export const enableAll = (config, places) => { | ||
| export const enableAll = (places, config) => { | ||
| initRules(config); | ||
@@ -72,6 +73,6 @@ const rules = parseRules(places); | ||
| for (const rule of Object.keys(config.rules)) | ||
| enable(config, rule); | ||
| enable(rule, config); | ||
| for (const rule of rules) | ||
| enable(config, rule); | ||
| enable(rule, config); | ||
@@ -84,2 +85,1 @@ return config; | ||
| } | ||
+7
-8
| { | ||
| "name": "@putout/cli-ruler", | ||
| "version": "2.0.0", | ||
| "version": "3.0.0", | ||
| "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)", | ||
@@ -33,16 +33,15 @@ "description": "toggle rules in .putout.json", | ||
| "devDependencies": { | ||
| "@putout/test": "^4.0.0", | ||
| "c8": "^7.5.0", | ||
| "eslint": "^8.0.1", | ||
| "eslint-plugin-node": "^11.0.0", | ||
| "eslint-plugin-putout": "^13.0.0", | ||
| "lerna": "^4.0.0", | ||
| "madrun": "^8.0.1", | ||
| "eslint-plugin-n": "^16.0.0", | ||
| "eslint-plugin-putout": "^17.0.0", | ||
| "lerna": "^6.0.1", | ||
| "madrun": "^9.0.0", | ||
| "nodemon": "^2.0.1", | ||
| "putout": "*", | ||
| "supertape": "^6.0.0" | ||
| "supertape": "^8.0.0" | ||
| }, | ||
| "license": "MIT", | ||
| "engines": { | ||
| "node": ">=14" | ||
| "node": ">=16" | ||
| }, | ||
@@ -49,0 +48,0 @@ "publishConfig": { |
+10
-8
@@ -21,2 +21,3 @@ # @putout/cli-ruler [![NPM version][NPMIMGURL]][NPMURL] | ||
| ```js | ||
| import {rule} from '@putout/cli-ruler'; | ||
| import { | ||
@@ -27,8 +28,9 @@ readFile, | ||
| import {rule} from '@putout/cli-ruler'; | ||
| const places = [{ | ||
| rule: 'remove-unused-variables', | ||
| message: '"a" is defined but never used', | ||
| position: {line: 3, column: 6}, | ||
| position: { | ||
| line: 3, | ||
| column: 6, | ||
| }, | ||
| }]; | ||
@@ -42,3 +44,3 @@ | ||
| await ruler(options, places); | ||
| await ruler(places, options); | ||
| ``` | ||
@@ -63,2 +65,3 @@ | ||
| ```js | ||
| import ruler from '@putout/cli-ruler'; | ||
| import { | ||
@@ -69,5 +72,4 @@ readFile, | ||
| import ruler from '@putout/cli-ruler'; | ||
| const places = []; | ||
| const places = []; | ||
| const options = { | ||
@@ -79,3 +81,3 @@ enable: 'remove-unused-variables', | ||
| await ruler(options, places); | ||
| await ruler(places, options); | ||
| ``` | ||
@@ -93,3 +95,3 @@ | ||
| Same with `disable` | ||
| Same with `disable`. | ||
@@ -96,0 +98,0 @@ ## License |
6144
0.18%9
-10%79
3.95%94
2.17%