Skip to content

Commit

Permalink
feature: @putout/plugin-putout-config: apply-parens
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Dec 22, 2024
1 parent f64bb95 commit 5b39158
Show file tree
Hide file tree
Showing 15 changed files with 157 additions and 1 deletion.
17 changes: 17 additions & 0 deletions packages/plugin-putout-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
});
10 changes: 10 additions & 0 deletions packages/plugin-putout-config/lib/apply-esm/fixture/apply-esm.js
Original file line number Diff line number Diff line change
@@ -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"
}
});
14 changes: 14 additions & 0 deletions packages/plugin-putout-config/lib/apply-esm/index.js
Original file line number Diff line number Diff line change
@@ -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);
22 changes: 22 additions & 0 deletions packages/plugin-putout-config/lib/apply-esm/index.spec.js
Original file line number Diff line number Diff line change
@@ -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();
});

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
__putout_processor_json({
"rules": {
"parens/add-missing": "on"
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
__putout_processor_json({
"rules": {
"add-missing-parens": "on"
}
});
9 changes: 9 additions & 0 deletions packages/plugin-putout-config/lib/apply-parens/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

const {createRenameProperty} = require('../rename-property');

const v37 = [
['add-missing-parens', 'parens/add-missing'],
];

module.exports = createRenameProperty(v37);
21 changes: 21 additions & 0 deletions packages/plugin-putout-config/lib/apply-parens/index.spec.js
Original file line number Diff line number Diff line change
@@ -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();
});

4 changes: 4 additions & 0 deletions packages/plugin-putout-config/lib/index.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions packages/plugin-putout-config/test/fixture/apply-esm-fix.js
Original file line number Diff line number Diff line change
@@ -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"
}
});
10 changes: 10 additions & 0 deletions packages/plugin-putout-config/test/fixture/apply-esm.js
Original file line number Diff line number Diff line change
@@ -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"
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
__putout_processor_json({
"rules": {
"parens/add-missing": "on"
}
});
5 changes: 5 additions & 0 deletions packages/plugin-putout-config/test/fixture/apply-parens.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
__putout_processor_json({
"rules": {
"add-missing-parens": "on"
}
});
11 changes: 10 additions & 1 deletion packages/plugin-putout-config/test/putout-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 5b39158

Please sign in to comment.