Skip to content

Commit f9ccb34

Browse files
committed
feature: @putout/operator-parens: add
1 parent 9331e96 commit f9ccb34

File tree

17 files changed

+226
-98
lines changed

17 files changed

+226
-98
lines changed

packages/operate/README.md

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -254,39 +254,6 @@ const object = template.ast('x({"a": "b"})');
254254
const [propertyPath] = traverseProperties(object, 'a');
255255
```
256256

257-
### `addParens(path: Path)`
258-
259-
Add parens around expression depending on used `printer`:
260-
261-
- ✅ set `node.extra.parenthesized: true` when `@putout/printer` used;
262-
- ✅ set add `ParenthesizedExpression` or `TSParenthesizedType` when `babel` used;
263-
264-
```js
265-
addParens(path);
266-
```
267-
268-
### `removeParens(path: Path)`
269-
270-
Remove parens around expression depending on used `printer`:
271-
272-
- ✅ set `node.extra.parenthesized: false` when `@putout/printer` used;
273-
- ✅ remove `ParenthesizedExpression` or `TSParenthesizedType` when `babel` used;
274-
275-
```js
276-
removeParens(path);
277-
```
278-
279-
### `hasParens(path: Path)`
280-
281-
Check if `path` has parens around expression depending on used `printer`:
282-
283-
- ✅ checks `node.extra.parenthesized` when `@putout/printer` used;
284-
- ✅ check if parent node type is `ParenthesizedExpression` or `TSParenthesizedType` when `babel` used;
285-
286-
```js
287-
hasParens(path);
288-
```
289-
290257
## License
291258

292259
MIT

packages/operate/lib/operate.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ const {renameProperty} = require('./rename-property');
1313
const {setLiteralValue} = require('./set-literal-value');
1414
const {getPathAfterRequires} = require('./get-path-after-requires');
1515

16-
const {
17-
addParens,
18-
removeParens,
19-
hasParens,
20-
} = require('./parens');
21-
2216
const {
2317
getProperty,
2418
getProperties,
@@ -54,10 +48,6 @@ module.exports.rename = rename;
5448
module.exports.renameProperty = renameProperty;
5549
module.exports.setLiteralValue = setLiteralValue;
5650

57-
module.exports.addParens = addParens;
58-
module.exports.hasParens = hasParens;
59-
module.exports.removeParens = removeParens;
60-
6151
module.exports.getProperty = getProperty;
6252
module.exports.getProperties = getProperties;
6353
module.exports.traverseProperties = traverseProperties;

packages/operate/test/operate.js

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,57 +1053,3 @@ test('putout: operate: getLiteralRaw', (t) => {
10531053
t.equal(result, raw);
10541054
t.end();
10551055
});
1056-
1057-
test('putout: operate: addParens', (t) => {
1058-
const source = 'const a: boolean = true;';
1059-
const ast = parse(source, {
1060-
printer: 'babel',
1061-
isTS: true,
1062-
});
1063-
1064-
traverse(ast, {
1065-
TSBooleanKeyword(path) {
1066-
operate.addParens(path);
1067-
path.stop();
1068-
},
1069-
});
1070-
1071-
const result = print(ast, {
1072-
printer: 'babel',
1073-
});
1074-
1075-
const expected = 'const a: (boolean) = true;\n';
1076-
1077-
t.equal(result, expected);
1078-
t.end();
1079-
});
1080-
1081-
test('putout: operate: removeParens', (t) => {
1082-
const source = '(b = 3)';
1083-
const ast = parse(source);
1084-
1085-
traverse(ast, {
1086-
AssignmentExpression: operate.removeParens,
1087-
});
1088-
1089-
const result = print(ast);
1090-
const expected = 'b = 3;\n';
1091-
1092-
t.equal(result, expected);
1093-
t.end();
1094-
});
1095-
1096-
test('putout: operate: hasParens', (t) => {
1097-
let result;
1098-
const source = 'b = 3';
1099-
const ast = parse(source);
1100-
1101-
traverse(ast, {
1102-
AssignmentExpression: (path) => {
1103-
result = operate.hasParens(path);
1104-
},
1105-
});
1106-
1107-
t.notOk(result);
1108-
t.end();
1109-
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": [
3+
"plugin:n/recommended",
4+
"plugin:putout/safe+align"
5+
],
6+
"plugins": [
7+
"n",
8+
"putout"
9+
]
10+
}
Lines changed: 6 additions & 0 deletions
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
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {run} from 'madrun';
2+
3+
export default {
4+
'prepublishOnly': () => run(['lint', 'test']),
5+
'test': () => `tape 'test/*.js' 'lib/**/*.spec.js'`,
6+
'watch:test': async () => `nodemon -w lib -x ${await run('test')}`,
7+
'lint': () => 'putout .',
8+
'fresh:lint': () => run('lint', '--fresh'),
9+
'lint:fresh': () => run('lint', '--fresh'),
10+
'fix:lint': () => run('lint', '--fix'),
11+
'coverage': async () => `c8 ${await run('test')}`,
12+
'report': () => 'c8 report --reporter=lcov',
13+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.*
2+
*.spec.js
3+
test
4+
fixture
5+
yarn-error.log
6+
7+
coverage
8+
*.config.*
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"check-coverage": true,
3+
"all": true,
4+
"exclude": [
5+
"**/*.spec.*",
6+
"**/fixture",
7+
"test",
8+
".*.*",
9+
"**/*.config.*"
10+
],
11+
"branches": 100,
12+
"lines": 100,
13+
"functions": 100,
14+
"statements": 100
15+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"printer": "putout",
3+
"match": {
4+
"*.md": {
5+
"declare": "off",
6+
"putout/convert-traverse-to-scan": "off",
7+
"putout/apply-remove": "off",
8+
"putout/declare": "on"
9+
}
10+
},
11+
"plugins": ["putout"]
12+
}

packages/operator-parens/LICENSE

Lines changed: 21 additions & 0 deletions
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)