From 5b39158fbd35804b188de88214c6c217742c6eb5 Mon Sep 17 00:00:00 2001 From: coderiaser Date: Sun, 22 Dec 2024 23:10:09 +0200 Subject: [PATCH] feature: @putout/plugin-putout-config: apply-parens --- packages/plugin-putout-config/README.md | 17 ++++++++++++++ .../lib/apply-esm/fixture/apply-esm-fix.js | 10 +++++++++ .../lib/apply-esm/fixture/apply-esm.js | 10 +++++++++ .../lib/apply-esm/index.js | 14 ++++++++++++ .../lib/apply-esm/index.spec.js | 22 +++++++++++++++++++ .../apply-parens/fixture/apply-parens-fix.js | 5 +++++ .../lib/apply-parens/fixture/apply-parens.js | 5 +++++ .../lib/apply-parens/index.js | 9 ++++++++ .../lib/apply-parens/index.spec.js | 21 ++++++++++++++++++ packages/plugin-putout-config/lib/index.js | 4 ++++ .../test/fixture/apply-esm-fix.js | 10 +++++++++ .../test/fixture/apply-esm.js | 10 +++++++++ .../test/fixture/apply-parens-fix.js | 5 +++++ .../test/fixture/apply-parens.js | 5 +++++ .../test/putout-config.js | 11 +++++++++- 15 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 packages/plugin-putout-config/lib/apply-esm/fixture/apply-esm-fix.js create mode 100644 packages/plugin-putout-config/lib/apply-esm/fixture/apply-esm.js create mode 100644 packages/plugin-putout-config/lib/apply-esm/index.js create mode 100644 packages/plugin-putout-config/lib/apply-esm/index.spec.js create mode 100644 packages/plugin-putout-config/lib/apply-parens/fixture/apply-parens-fix.js create mode 100644 packages/plugin-putout-config/lib/apply-parens/fixture/apply-parens.js create mode 100644 packages/plugin-putout-config/lib/apply-parens/index.js create mode 100644 packages/plugin-putout-config/lib/apply-parens/index.spec.js create mode 100644 packages/plugin-putout-config/test/fixture/apply-esm-fix.js create mode 100644 packages/plugin-putout-config/test/fixture/apply-esm.js create mode 100644 packages/plugin-putout-config/test/fixture/apply-parens-fix.js create mode 100644 packages/plugin-putout-config/test/fixture/apply-parens.js diff --git a/packages/plugin-putout-config/README.md b/packages/plugin-putout-config/README.md index 16585df5e..db0498ac3 100644 --- a/packages/plugin-putout-config/README.md +++ b/packages/plugin-putout-config/README.md @@ -15,6 +15,7 @@ npm i @putout/plugin-putout-config -D - ✅ [apply-conditions](#apply-conditions); - ✅ [apply-esm](#apply-esm); +- ✅ [apply-parens](#apply-parens); - ✅ [apply-for-of](#apply-for-of); - ✅ [apply-labels](#apply-labels); - ✅ [apply-math](#apply-math); @@ -42,6 +43,7 @@ npm i @putout/plugin-putout-config -D "putout-config/apply-math": "on", "putout-config/apply-nodejs": "on", "putout-config/apply-optional-chaining": "on", + "putout-config/apply-parens": "on", "putout-config/apply-tape": "on", "putout-config/apply-types": "on", "putout-config/apply-promises": "on", @@ -79,6 +81,21 @@ Apply [`esm`](https://github.com/coderaiser/putout/tree/master/packages/plugin-e } ``` +## apply-parens + +Apply [`parens`](https://github.com/coderaiser/putout/tree/master/packages/plugin-parens#readme) according to: + +- 🐊[**Putout v37**](https://github.com/coderaiser/putout/releases/tag/v37.0.0): + +```diff +{ + "rules": { +- "add-missing-parens": "on" ++ "parens/add-missing": "on" + } +} +``` + ## apply-optional-chaining Apply [`optional-chaining`](https://github.com/coderaiser/putout/tree/master/packages/plugin-optional-chaining#readme) according to: diff --git a/packages/plugin-putout-config/lib/apply-esm/fixture/apply-esm-fix.js b/packages/plugin-putout-config/lib/apply-esm/fixture/apply-esm-fix.js new file mode 100644 index 000000000..4ad944aa4 --- /dev/null +++ b/packages/plugin-putout-config/lib/apply-esm/fixture/apply-esm-fix.js @@ -0,0 +1,10 @@ +__putout_processor_json({ + "rules": { + "esm/remove-empty-import": "on", + "esm/remove-empty-export": "on", + "esm/group-imports-by-source": "on", + "esm/declare-imports-first": "on", + "esm/remove-quotes-from-import-assertions": "on", + "esm/merge-duplicate-imports": "on" + } +}); diff --git a/packages/plugin-putout-config/lib/apply-esm/fixture/apply-esm.js b/packages/plugin-putout-config/lib/apply-esm/fixture/apply-esm.js new file mode 100644 index 000000000..9f4417f7e --- /dev/null +++ b/packages/plugin-putout-config/lib/apply-esm/fixture/apply-esm.js @@ -0,0 +1,10 @@ +__putout_processor_json({ + "rules": { + "remove-empty/import": "on", + "remove-empty/export": "on", + "group-imports-by-source": "on", + "declare-imports-first": "on", + "remove-quotes-from-import-assertions": "on", + "merge-duplicate-imports": "on" + } +}); diff --git a/packages/plugin-putout-config/lib/apply-esm/index.js b/packages/plugin-putout-config/lib/apply-esm/index.js new file mode 100644 index 000000000..76796c04e --- /dev/null +++ b/packages/plugin-putout-config/lib/apply-esm/index.js @@ -0,0 +1,14 @@ +'use strict'; + +const {createRenameProperty} = require('../rename-property'); + +const v37 = [ + ['remove-empty/import', 'esm/remove-empty-import'], + ['remove-empty/export', 'esm/remove-empty-export'], + ['group-imports-by-source', 'esm/group-imports-by-source'], + ['declare-imports-first', 'esm/declare-imports-first'], + ['remove-quotes-from-import-assertions', 'esm/remove-quotes-from-import-assertions'], + ['merge-duplicate-imports', 'esm/merge-duplicate-imports'], +]; + +module.exports = createRenameProperty(v37); diff --git a/packages/plugin-putout-config/lib/apply-esm/index.spec.js b/packages/plugin-putout-config/lib/apply-esm/index.spec.js new file mode 100644 index 000000000..6d8ebf896 --- /dev/null +++ b/packages/plugin-putout-config/lib/apply-esm/index.spec.js @@ -0,0 +1,22 @@ +'use strict'; + +const {createTest} = require('@putout/test'); +const plugin = require('.'); + +const test = createTest(__dirname, { + printer: 'putout', + plugins: [ + ['apply-esm', plugin], + ], +}); + +test('putout-config: apply-esm: report', (t) => { + t.report('apply-esm', `Rename property: 'remove-empty/import' -> 'esm/remove-empty-import'`); + t.end(); +}); + +test('putout-config: apply-esm: transform', (t) => { + t.transform('apply-esm'); + t.end(); +}); + diff --git a/packages/plugin-putout-config/lib/apply-parens/fixture/apply-parens-fix.js b/packages/plugin-putout-config/lib/apply-parens/fixture/apply-parens-fix.js new file mode 100644 index 000000000..81e6191a9 --- /dev/null +++ b/packages/plugin-putout-config/lib/apply-parens/fixture/apply-parens-fix.js @@ -0,0 +1,5 @@ +__putout_processor_json({ + "rules": { + "parens/add-missing": "on" + } +}); diff --git a/packages/plugin-putout-config/lib/apply-parens/fixture/apply-parens.js b/packages/plugin-putout-config/lib/apply-parens/fixture/apply-parens.js new file mode 100644 index 000000000..d66929f15 --- /dev/null +++ b/packages/plugin-putout-config/lib/apply-parens/fixture/apply-parens.js @@ -0,0 +1,5 @@ +__putout_processor_json({ + "rules": { + "add-missing-parens": "on" + } +}); diff --git a/packages/plugin-putout-config/lib/apply-parens/index.js b/packages/plugin-putout-config/lib/apply-parens/index.js new file mode 100644 index 000000000..2e5604a23 --- /dev/null +++ b/packages/plugin-putout-config/lib/apply-parens/index.js @@ -0,0 +1,9 @@ +'use strict'; + +const {createRenameProperty} = require('../rename-property'); + +const v37 = [ + ['add-missing-parens', 'parens/add-missing'], +]; + +module.exports = createRenameProperty(v37); diff --git a/packages/plugin-putout-config/lib/apply-parens/index.spec.js b/packages/plugin-putout-config/lib/apply-parens/index.spec.js new file mode 100644 index 000000000..9f84f2740 --- /dev/null +++ b/packages/plugin-putout-config/lib/apply-parens/index.spec.js @@ -0,0 +1,21 @@ +'use strict'; + +const {createTest} = require('@putout/test'); +const plugin = require('.'); + +const test = createTest(__dirname, { + plugins: [ + ['apply-parens', plugin], + ], +}); + +test('putout-config: apply-parens: report', (t) => { + t.report('apply-parens', `Rename property: 'add-missing-parens' -> 'parens/add-missing'`); + t.end(); +}); + +test('putout-config: apply-parens: transform', (t) => { + t.transform('apply-parens'); + t.end(); +}); + diff --git a/packages/plugin-putout-config/lib/index.js b/packages/plugin-putout-config/lib/index.js index 3133527a6..ec0585a2c 100644 --- a/packages/plugin-putout-config/lib/index.js +++ b/packages/plugin-putout-config/lib/index.js @@ -1,7 +1,9 @@ 'use strict'; const applyConditions = require('./apply-conditions'); +const applyEsm = require('./apply-esm'); const applyOptionalChaining = require('./apply-optional-chaining'); +const applyParens = require('./apply-parens'); const applyForOf = require('./apply-for-of'); const applyLabels = require('./apply-labels'); const applyMath = require('./apply-math'); @@ -17,11 +19,13 @@ const removeEmptyFile = require('./remove-empty-file'); module.exports.rules = { 'apply-conditions': applyConditions, + 'apply-esm': applyEsm, 'apply-for-of': applyForOf, 'apply-labels': applyLabels, 'apply-math': applyMath, 'apply-nodejs': applyNodejs, 'apply-optional-chaining': applyOptionalChaining, + 'apply-parens': applyParens, 'apply-promises': applyPromises, 'apply-tape': applyTape, 'apply-types': applyTypes, diff --git a/packages/plugin-putout-config/test/fixture/apply-esm-fix.js b/packages/plugin-putout-config/test/fixture/apply-esm-fix.js new file mode 100644 index 000000000..4ad944aa4 --- /dev/null +++ b/packages/plugin-putout-config/test/fixture/apply-esm-fix.js @@ -0,0 +1,10 @@ +__putout_processor_json({ + "rules": { + "esm/remove-empty-import": "on", + "esm/remove-empty-export": "on", + "esm/group-imports-by-source": "on", + "esm/declare-imports-first": "on", + "esm/remove-quotes-from-import-assertions": "on", + "esm/merge-duplicate-imports": "on" + } +}); diff --git a/packages/plugin-putout-config/test/fixture/apply-esm.js b/packages/plugin-putout-config/test/fixture/apply-esm.js new file mode 100644 index 000000000..9f4417f7e --- /dev/null +++ b/packages/plugin-putout-config/test/fixture/apply-esm.js @@ -0,0 +1,10 @@ +__putout_processor_json({ + "rules": { + "remove-empty/import": "on", + "remove-empty/export": "on", + "group-imports-by-source": "on", + "declare-imports-first": "on", + "remove-quotes-from-import-assertions": "on", + "merge-duplicate-imports": "on" + } +}); diff --git a/packages/plugin-putout-config/test/fixture/apply-parens-fix.js b/packages/plugin-putout-config/test/fixture/apply-parens-fix.js new file mode 100644 index 000000000..81e6191a9 --- /dev/null +++ b/packages/plugin-putout-config/test/fixture/apply-parens-fix.js @@ -0,0 +1,5 @@ +__putout_processor_json({ + "rules": { + "parens/add-missing": "on" + } +}); diff --git a/packages/plugin-putout-config/test/fixture/apply-parens.js b/packages/plugin-putout-config/test/fixture/apply-parens.js new file mode 100644 index 000000000..d66929f15 --- /dev/null +++ b/packages/plugin-putout-config/test/fixture/apply-parens.js @@ -0,0 +1,5 @@ +__putout_processor_json({ + "rules": { + "add-missing-parens": "on" + } +}); diff --git a/packages/plugin-putout-config/test/putout-config.js b/packages/plugin-putout-config/test/putout-config.js index e8b9147e6..387ed42d3 100644 --- a/packages/plugin-putout-config/test/putout-config.js +++ b/packages/plugin-putout-config/test/putout-config.js @@ -4,12 +4,21 @@ const {createTest} = require('@putout/test'); const putoutConfig = require('..'); const test = createTest(__dirname, { - printer: 'putout', plugins: [ ['putout-config', putoutConfig], ], }); +test('plugin-putout-config: transform: apply-esm', (t) => { + t.transform('apply-esm'); + t.end(); +}); + +test('plugin-putout-config: transform: apply-parens', (t) => { + t.transform('apply-parens'); + t.end(); +}); + test('plugin-putout-config: transform: apply-conditions', (t) => { t.transform('apply-conditions'); t.end();