Skip to content

Commit b36ba4b

Browse files
committed
feature: @putout/plugin-apply-consistent-blocks: add
1 parent 2c227ce commit b36ba4b

File tree

80 files changed

+427
-173
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+427
-173
lines changed

README.md

+31-14
Original file line numberDiff line numberDiff line change
@@ -1254,28 +1254,26 @@ function world(a) {
12541254

12551255
</details>
12561256

1257-
<details><summary>convert <code>esm</code> to <code>commonjs</code> (disabled)</summary>
1258-
1259-
```diff
1260-
-import hello from 'world';
1261-
+const hello = require('world');
1262-
```
1263-
1264-
</details>
1265-
<details><summary>convert <code>commonjs</code> to <code>esm</code> (disabled)</summary>
1257+
<details><summary>convert <code>replace</code> to <code>replaceAll</code> (<a href=https://github.com/tc39/proposal-string-replaceall>stage-4</a>)</summary>
12661258

12671259
```diff
1268-
-const hello = require('world');
1269-
+import hello from 'world';
1260+
-'hello'.replace(/hello/g, 'world');
1261+
+'hello'.replaceAll('hello', 'world');
12701262
```
12711263

12721264
</details>
12731265

1274-
<details><summary>convert <code>replace</code> to <code>replaceAll</code> (<a href=https://github.com/tc39/proposal-string-replaceall>stage-4</a>)</summary>
1266+
<details><summary>apply consistent-blocks</summary>
12751267

12761268
```diff
1277-
-'hello'.replace(/hello/g, 'world');
1278-
+'hello'.replaceAll('hello', 'world');
1269+
-if (a)
1270+
+if (a) {
1271+
b();
1272+
+} else {
1273+
-else {
1274+
c();
1275+
d();
1276+
}
12791277
```
12801278

12811279
</details>
@@ -1740,6 +1738,24 @@ async () => {
17401738

17411739
### Node.js
17421740

1741+
<details><summary>convert <code>esm</code> to <code>commonjs</code> (disabled)</summary>
1742+
1743+
```diff
1744+
-import hello from 'world';
1745+
+const hello = require('world');
1746+
```
1747+
1748+
</details>
1749+
1750+
<details><summary>convert <code>commonjs</code> to <code>esm</code> (disabled)</summary>
1751+
1752+
```diff
1753+
-const hello = require('world');
1754+
+import hello from 'world';
1755+
```
1756+
1757+
</details>
1758+
17431759
<details><summary>convert <code>fs.promises</code> to <code>fs/promises</code> for <a href=https://nodejs.org/dist/latest-v15.x/docs/api/fs.html#fs_fs_promises_api>node.js</a></summary>
17441760

17451761
```diff
@@ -1904,6 +1920,7 @@ It has a lot plugins divided by groups:
19041920

19051921
| Package | Version |
19061922
|--------|-------|
1923+
| [`@putout/plugin-apply-consistent-blocks`](/packages/plugin-apply-consistent-blocks#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-apply-consistent-blocks.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-apply-consistent-blocks) |
19071924
| [`@putout/plugin-apply-at`](/packages/plugin-apply-at#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-apply-at.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-apply-at) |
19081925
| [`@putout/plugin-apply-dot-notation`](/packages/plugin-apply-dot-notation#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-apply-dot-notation.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-apply-dot-notation) |
19091926
| [`@putout/plugin-apply-starts-with`](/packages/plugin-apply-starts-with#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-apply-starts-with.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-apply-starts-with) |

packages/cli-cache/lib/cache.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,8 @@ const hash = (a) => murmur(a).result()
114114
.toString(36);
115115

116116
const createGetOptionsCache = ({version}) => (options) => {
117-
if (!optionsHashCache.has(options)) {
117+
if (!optionsHashCache.has(options))
118118
optionsHashCache.set(options, hash(`${version}_${nodeVersion}_${stringify(options)}`));
119-
}
120119

121120
return optionsHashCache.get(options);
122121
};

packages/cli-cache/lib/is-no-definition.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ module.exports = (places) => {
44
for (const {rule, message} of places) {
55
const shortRule = rule.replace('eslint/', '');
66

7-
if (message === `Definition for rule '${shortRule}' was not found.`) {
7+
if (message === `Definition for rule '${shortRule}' was not found.`)
88
return true;
9-
}
109
}
1110

1211
return false;

packages/compare/lib/comparators.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,8 @@ module.exports.runComparators = (node, template, {add, templateStore}) => {
7373
while (++i < n) {
7474
const compare = comparators[i];
7575

76-
if (compare(node, template, {add, templateStore})) {
76+
if (compare(node, template, {add, templateStore}))
7777
return true;
78-
}
7978
}
8079

8180
return false;

packages/compare/lib/vars.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,8 @@ function getValues({waysFrom, node}) {
102102
else if (isArgsStr(name) || isJSXChildrenStr(name) || isJSXAttributesStr(name))
103103
way = way.replace(/\.0$/, '');
104104

105-
if (!isJSXElement(node)) {
105+
if (!isJSXElement(node))
106106
way = way.replace(/\.expression$/, '');
107-
}
108107

109108
result[name] = result[name] || parseExpression(jessy(way, node));
110109
}

packages/engine-loader/lib/processors/parse-processor-names.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ module.exports = (plugins) => {
1818
if (isArray(plugin)) {
1919
const [pluginName, fn] = plugin;
2020

21-
if (isOff(fn)) {
21+
if (isOff(fn))
2222
continue;
23-
}
2423

2524
if (isOn(fn)) {
2625
result.push([pluginName]);

packages/engine-loader/test/load-plugins.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ test('putout: loader: user plugin', (t) => {
3232
if (!name.indexOf(`@putout/plugin-${rmVars}`))
3333
return false;
3434

35-
if (name === `putout-plugin-${rmVars}`) {
35+
if (name === `putout-plugin-${rmVars}`)
3636
return name;
37-
}
3837

3938
return _findPath(name, paths);
4039
});

packages/engine-runner/lib/replace/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,8 @@ const getFilter = (match = stubMatch, options) => (path) => {
149149
for (const [from, matchProperty] of all) {
150150
const nodeFrom = template.ast(from);
151151

152-
if (!compare(path.node, nodeFrom)) {
152+
if (!compare(path.node, nodeFrom))
153153
continue;
154-
}
155154

156155
const waysFrom = findVarsWays(nodeFrom);
157156
const {node} = path;

packages/engine-runner/lib/replace/watermark.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ function create(from, to, path) {
4141

4242
module.exports.init = init;
4343
function init({path, program}) {
44-
if (path.node) {
44+
if (path.node)
4545
path.node[name] = path.node[name] || new Set();
46-
}
4746

4847
program.node[name] = program.node[name] || new Set();
4948
}

packages/engine-runner/lib/run-fix.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ const tryToFix = (fix, {path, position, options}) => {
2020
.getProgramParent()
2121
.crawl();
2222

23-
if (!e) {
23+
if (!e)
2424
return;
25-
}
2625

2726
e.loc = e.loc || position;
2827

packages/eslint-plugin-putout/lib/putout/parse-error.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ module.exports.parseError = ({code, message, name}) => {
44
if (message.includes('buildError'))
55
return 'Parser error';
66

7-
if (code === 'ERR_REQUIRE_ESM') {
7+
if (code === 'ERR_REQUIRE_ESM')
88
return `☝️ Looks like '${name}' is ESM, extend from 'plugin:putout/esm'`;
9-
}
109

1110
return message;
1211
};

packages/eslint-plugin-putout/lib/single-property-destructuring/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ module.exports.filter = ({node, text, getText, getCommentsInside}) => {
4848
};
4949

5050
module.exports.fix = ({text, node, getText}) => {
51-
if (isImportDeclaration(node)) {
51+
if (isImportDeclaration(node))
5252
return text.replace(NewLinesReg, '');
53-
}
5453

5554
const {id} = node;
5655
const idText = getText(id);

packages/eslint/lib/create-plugin/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,8 @@ function isLastNodeInBody(node) {
146146
const {length} = node.parent.body;
147147
const n = length - 1;
148148

149-
if (node === node.parent?.body?.[n]) {
149+
if (node === node.parent?.body?.[n])
150150
return true;
151-
}
152151
}
153152

154153
return false;

packages/operate/lib/compute.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,8 @@ function isExtractable(path) {
8181
if (!path.isIdentifier() && !path.isLiteral())
8282
return false;
8383

84-
if (parentPath.isObjectProperty({computed})) {
84+
if (parentPath.isObjectProperty({computed}))
8585
return !usedInAssignment(path);
86-
}
8786

8887
return false;
8988
}

packages/operate/lib/remove.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ const getComments = (path) => {
4040

4141
const {parentPath} = path;
4242

43-
if (path.isVariableDeclarator() && isOneDeclaration(parentPath)) {
43+
if (path.isVariableDeclarator() && isOneDeclaration(parentPath))
4444
return parentPath.node.comments;
45-
}
4645

4746
return [];
4847
};

packages/operator-filesystem/lib/filesystem.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ module.exports.findFile = (node, name) => {
4141
for (const filenamePath of traverseProperties(node, 'filename')) {
4242
const {value} = filenamePath.node.value;
4343

44-
if (value === name || getRegExp(name).test(value)) {
44+
if (value === name || getRegExp(name).test(value))
4545
filePaths.push(filenamePath.parentPath);
46-
}
4746
}
4847

4948
return filePaths;

packages/plugin-apply-at/lib/apply-at.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ module.exports.filter = (path) => {
1010
if (parentPath.isAssignmentExpression())
1111
return false;
1212

13-
if (compare(path, '__a[length - __b]')) {
13+
if (compare(path, '__a[length - __b]'))
1414
return compare(path.parentPath.parentPath.getPrevSibling(), 'const {length} = __a');
15-
}
1615

1716
return true;
1817
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": [
3+
"plugin:n/recommended",
4+
"plugin:putout/recommended"
5+
],
6+
"plugins": [
7+
"n",
8+
"putout"
9+
]
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
*.swp
3+
yarn-error.log
4+
5+
coverage
6+
.idea
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {run} from 'madrun';
2+
3+
export default {
4+
'test': () => `tape 'lib/**/*.spec.js' 'test/*.js'`,
5+
'watch:test': async () => `nodemon -w lib -w test -x ${await run('test')}`,
6+
'lint': () => `putout .`,
7+
'fresh:lint': () => run('lint', '--fresh'),
8+
'lint:fresh': () => run('lint', '--fresh'),
9+
'fix:lint': () => run('lint', '--fix'),
10+
'coverage': async () => `c8 ${await run('test')}`,
11+
'report': () => 'c8 report --reporter=lcov',
12+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.*
2+
test
3+
yarn-error.log
4+
fixture
5+
*.spec.js
6+
7+
coverage
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"check-coverage": true,
3+
"all": true,
4+
"exclude": [
5+
"**/*.spec.*",
6+
"**/fixture",
7+
"test",
8+
".*.*"
9+
],
10+
"branches": 100,
11+
"lines": 100,
12+
"functions": 100,
13+
"statements": 100
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"printer": "putout",
3+
"match": {
4+
"README.md": {
5+
"apply-at": "off"
6+
}
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) coderaiser
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)