@putout/plugin-printer 8.23.1 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,65 +0,0 @@
1
- import {operator, types} from 'putout';
2
-
3
- const {
4
- isIdentifier,
5
- isCallExpression,
6
- } = types;
7
-
8
- const {setLiteralValue} = operator;
9
-
10
- export const report = ({path, where}) => {
11
- const {value} = path.node;
12
- const withoutColon = addColon(value, where);
13
-
14
- return `Remove useless colon: '${value}' -> '${withoutColon}'`;
15
- };
16
-
17
- export const fix = ({path, where}) => {
18
- const {value} = path.node;
19
- setLiteralValue(path, addColon(value, where));
20
- };
21
- export const traverse = ({push}) => ({
22
- StringLiteral(path) {
23
- const call = path.find(isCallExpression);
24
-
25
- if (!call)
26
- return;
27
-
28
- if (!isIdentifier(call.node.callee, {name: 'createTypeChecker'}))
29
- return;
30
-
31
- const {value} = path.node;
32
- const where = createWhere(value);
33
-
34
- if (where.length)
35
- push({
36
- path,
37
- where,
38
- });
39
- },
40
- });
41
-
42
- function createWhere(value) {
43
- const where = [];
44
-
45
- if (value.length !== 2)
46
- return where;
47
-
48
- if (value === '+:')
49
- where.push('after-plus');
50
-
51
- if (value === '-:')
52
- where.push('after-minus');
53
-
54
- return where;
55
- }
56
-
57
- function addColon(value, where) {
58
- if (where.includes('after-plus'))
59
- value = value.replace('+:', '+');
60
-
61
- if (where.includes('after-minus'))
62
- value = value.replace('-:', '-');
63
-
64
- return value;
65
- }
@@ -1,79 +0,0 @@
1
- import {operator, types} from 'putout';
2
-
3
- const {
4
- isIdentifier,
5
- isCallExpression,
6
- } = types;
7
-
8
- const {setLiteralValue} = operator;
9
-
10
- export const report = ({path, where}) => {
11
- const {value} = path.node;
12
- const withoutNot = removeNot(value, where);
13
-
14
- return `Avoid useless '!': '${value}' -> '${withoutNot}'`;
15
- };
16
-
17
- export const fix = ({path, where}) => {
18
- const {value} = path.node;
19
- setLiteralValue(path, removeNot(value, where));
20
- };
21
- export const traverse = ({push}) => ({
22
- StringLiteral(path) {
23
- const call = path.find(isCallExpression);
24
-
25
- if (!call)
26
- return;
27
-
28
- if (!isIdentifier(call.node.callee, {name: 'createTypeChecker'}))
29
- return;
30
-
31
- const {value} = path.node;
32
- const where = createWhere(value);
33
-
34
- if (where.length)
35
- push({
36
- path,
37
- where,
38
- });
39
- },
40
- });
41
-
42
- function createWhere(value) {
43
- const where = [];
44
- const includes = value.includes.bind(value);
45
- const endsWith = value.endsWith.bind(value);
46
- const push = where.push.bind(where);
47
-
48
- const tools = {
49
- push,
50
- includes,
51
- endsWith,
52
- };
53
-
54
- if (includes('!+'))
55
- traceNot(tools);
56
-
57
- if (includes('!-'))
58
- traceNot(tools);
59
-
60
- return where;
61
- }
62
-
63
- function traceNot({push, includes}) {
64
- if (includes('!+'))
65
- push('before-plus');
66
-
67
- if (includes('!-'))
68
- push('before-minus');
69
- }
70
-
71
- function removeNot(value, where) {
72
- if (where.includes('before-plus'))
73
- value = value.replace('!+', '-');
74
-
75
- if (where.includes('before-minus'))
76
- value = value.replace('!-', '+');
77
-
78
- return value;
79
- }
@@ -1,70 +0,0 @@
1
- import {operator, types} from 'putout';
2
-
3
- const {
4
- isIdentifier,
5
- isCallExpression,
6
- } = types;
7
-
8
- const {setLiteralValue} = operator;
9
-
10
- export const report = ({path, where}) => {
11
- const {value} = path.node;
12
- const withoutNot = removePath(value, where);
13
-
14
- return `Avoid useless 'path': '${value}' -> '${withoutNot}'`;
15
- };
16
-
17
- export const fix = ({path, where}) => {
18
- const {value} = path.node;
19
- setLiteralValue(path, removePath(value, where));
20
- };
21
- export const traverse = ({push}) => ({
22
- StringLiteral(path) {
23
- const call = path.find(isCallExpression);
24
-
25
- if (!call)
26
- return;
27
-
28
- if (!isIdentifier(call.node.callee, {name: 'createTypeChecker'}))
29
- return;
30
-
31
- const {value} = path.node;
32
- const where = createWhere(value);
33
-
34
- if (where.length)
35
- push({
36
- path,
37
- where,
38
- });
39
- },
40
- });
41
-
42
- function createWhere(value) {
43
- const where = [];
44
- const includes = value.includes.bind(value);
45
- const endsWith = value.endsWith.bind(value);
46
- const push = where.push.bind(where);
47
-
48
- const tools = {
49
- push,
50
- includes,
51
- endsWith,
52
- };
53
-
54
- if (includes('path.'))
55
- tracePath(tools);
56
-
57
- return where;
58
- }
59
-
60
- function tracePath({push, includes}) {
61
- if (includes('path.'))
62
- push('path');
63
- }
64
-
65
- function removePath(value, where) {
66
- if (where.includes('path'))
67
- value = value.replace('path.', '');
68
-
69
- return value;
70
- }
@@ -1,78 +0,0 @@
1
- import {operator, types} from 'putout';
2
-
3
- const {
4
- isIdentifier,
5
- isCallExpression,
6
- } = types;
7
-
8
- const {setLiteralValue} = operator;
9
-
10
- export const report = ({path, where}) => {
11
- const {value} = path.node;
12
- const withSpaces = removeSpaces(value, where);
13
-
14
- return `Remove useless spaces: '${value}' -> '${withSpaces}'`;
15
- };
16
-
17
- export const fix = ({path, where}) => {
18
- const {value} = path.node;
19
- setLiteralValue(path, removeSpaces(value, where));
20
- };
21
- export const traverse = ({push}) => ({
22
- StringLiteral(path) {
23
- const call = path.find(isCallExpression);
24
-
25
- if (!call)
26
- return;
27
-
28
- if (!isIdentifier(call.node.callee, {name: 'createTypeChecker'}))
29
- return;
30
-
31
- const {value} = path.node;
32
- const where = createWhere(value);
33
-
34
- if (where.length)
35
- push({
36
- path,
37
- where,
38
- });
39
- },
40
- });
41
-
42
- function createWhere(value) {
43
- const where = [];
44
- const includes = value.includes.bind(value);
45
- const endsWith = value.endsWith.bind(value);
46
- const push = where.push.bind(where);
47
-
48
- const tools = {
49
- push,
50
- includes,
51
- endsWith,
52
- };
53
-
54
- traceColon(tools);
55
- traceSpaces(tools);
56
-
57
- return where;
58
- }
59
-
60
- function traceSpaces({push, includes}) {
61
- if (includes(' '))
62
- push('double-spaces');
63
- }
64
-
65
- function traceColon({push, includes}) {
66
- if (includes(' :'))
67
- push('before-colon');
68
- }
69
-
70
- function removeSpaces(value, where) {
71
- if (where.includes('before-colon'))
72
- value = value.replace(' :', ':');
73
-
74
- if (where.includes('double-spaces'))
75
- value = value.replaceAll(' ', ' ');
76
-
77
- return value;
78
- }
@@ -1,67 +0,0 @@
1
- import {operator, types} from 'putout';
2
-
3
- const {
4
- isStringLiteral,
5
- isArrayExpression,
6
- isIdentifier,
7
- isCallExpression,
8
- } = types;
9
-
10
- const {replaceWith} = operator;
11
-
12
- export const report = (path) => {
13
- return `Remove useless tuple from: ${path}`;
14
- };
15
-
16
- export const fix = (path) => {
17
- const [element] = path.node.elements;
18
- replaceWith(path, element);
19
- };
20
-
21
- export const traverse = ({push}) => ({
22
- ArrayExpression(path) {
23
- const {parentPath} = path;
24
-
25
- if (!isCallExpression(parentPath))
26
- return;
27
-
28
- if (!isIdentifier(parentPath.node.callee, {name: 'createTypeChecker'}))
29
- return;
30
-
31
- const elements = path.get('elements');
32
-
33
- if (isConsistent(elements))
34
- return;
35
-
36
- for (const element of elements) {
37
- if (isArrayExpression(element))
38
- push(element);
39
- }
40
- },
41
- });
42
-
43
- const isCountElementsTuple = (count) => (a) => {
44
- if (!isArrayExpression(a))
45
- return false;
46
-
47
- const {length} = a.node.elements;
48
-
49
- return length === count;
50
- };
51
-
52
- function isConsistent(elements) {
53
- const stringsCount = elements.filter(isStringLiteral).length;
54
-
55
- if (elements.length === stringsCount)
56
- return true;
57
-
58
- const identifiersCount = elements.filter(isIdentifier).length;
59
-
60
- if (elements.length === identifiersCount)
61
- return true;
62
-
63
- if (elements.filter(isCountElementsTuple(3)).length)
64
- return true;
65
-
66
- return elements.filter(isCountElementsTuple(2)).length;
67
- }
@@ -1,32 +0,0 @@
1
- import {operator} from 'putout';
2
-
3
- const CMP = {
4
- '<': '>=',
5
- '>': '<=',
6
- '<=': '>',
7
- '>=': '<',
8
- };
9
-
10
- const OPERATORS = Object.keys(CMP);
11
-
12
- const {setLiteralValue} = operator;
13
-
14
- export const report = () => `Reverse comparison`;
15
-
16
- export const match = () => ({
17
- '["__a", "__b", __c]': ({__a, __b}) => {
18
- if (!OPERATORS.includes(__b.value))
19
- return false;
20
-
21
- return __a.value.endsWith('!');
22
- },
23
- });
24
-
25
- export const replace = () => ({
26
- '["__a", "__b", __c]': ({__a, __b}, path) => {
27
- setLiteralValue(__a, __a.value.slice(0, -5));
28
- setLiteralValue(__b, CMP[__b.value]);
29
-
30
- return path;
31
- },
32
- });
package/lib/types.js DELETED
@@ -1,22 +0,0 @@
1
- import {types} from 'putout';
2
-
3
- const TYPES_EXISTS = new Set([
4
- 'CommentBlock',
5
- '+',
6
- '-',
7
- ]);
8
-
9
- const TYPES_NOT_EXISTS = new Set([
10
- 'ExportDeclaration',
11
- 'Function',
12
- ]);
13
-
14
- export function isTypeExists(type) {
15
- if (TYPES_NOT_EXISTS.has(type))
16
- return false;
17
-
18
- if (types[`is${type}`])
19
- return true;
20
-
21
- return TYPES_EXISTS.has(type);
22
- }