@putout/plugin-printer 8.17.0 → 8.18.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.
@@ -0,0 +1,59 @@
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 = addArrow(value, where);
13
+
14
+ return `Add missing arrow: '${value}' -> '${withSpaces}'`;
15
+ };
16
+
17
+ export const fix = ({path, where}) => {
18
+ const {value} = path.node;
19
+ setLiteralValue(path, addArrow(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.startsWith('+: !') && !value.includes('->'))
46
+ where.push('after-colon');
47
+
48
+ if (value.startsWith('-: !') && !value.includes('->'))
49
+ where.push('after-colon');
50
+
51
+ return where;
52
+ }
53
+
54
+ function addArrow(value, where) {
55
+ if (where.includes('after-colon'))
56
+ value = value.replace(': !', ': -> !');
57
+
58
+ return value;
59
+ }
@@ -36,14 +36,19 @@ export const fix = (path) => {
36
36
  const {node} = path;
37
37
 
38
38
  if (isIdentifier(path) || isCallExpression(path)) {
39
- replaceWith(path, arrayExpression([stringLiteral('+'), node]));
39
+ replaceWith(path, arrayExpression([
40
+ stringLiteral('+'),
41
+ node,
42
+ ]));
40
43
  return;
41
44
  }
42
45
 
43
46
  const {value} = node;
44
47
 
45
48
  if (isStringLiteral(path) && !/^[+-]/.test(value)) {
46
- replaceWith(path, arrayExpression([stringLiteral(`+: -> ${value}`)]));
49
+ replaceWith(path, arrayExpression([
50
+ stringLiteral(`+: -> ${value}`),
51
+ ]));
47
52
  return;
48
53
  }
49
54
 
package/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import * as addMissingArrowToTypeChecker from './add-missing-arrow-to-type-checker/index.js';
1
2
  import * as removeUselessArrowFromTypeChecker from './remove-useless-arrow-from-type-checker/index.js';
2
3
  import * as removeUselessPathFromTypeChecker from './remove-useless-path-from-type-checker/index.js';
3
4
  import * as reverseComparisonInTypeChecker from './reverse-comparison-in-type-checker/index.js';
@@ -48,4 +49,5 @@ export const rules = {
48
49
  'reverse-comparison-in-type-checker': reverseComparisonInTypeChecker,
49
50
  'remove-useless-path-from-type-checker': removeUselessPathFromTypeChecker,
50
51
  'remove-useless-arrow-from-type-checker': removeUselessArrowFromTypeChecker,
52
+ 'add-missing-arrow-to-type-checker': addMissingArrowToTypeChecker,
51
53
  };
@@ -1,4 +1,21 @@
1
- const checkArgs = ({__args}) => __args.length;
1
+ import {types, operator} from 'putout';
2
+
3
+ const {isImportSpecifier} = types;
4
+ const {getBindingPath} = operator;
5
+
6
+ const checkArgs = ({__args}, path) => {
7
+ if (!__args.length)
8
+ return false;
9
+
10
+ const {name} = path.node.callee;
11
+
12
+ const bindingPath = getBindingPath(path, name);
13
+
14
+ if (!bindingPath)
15
+ return true;
16
+
17
+ return !isImportSpecifier(bindingPath);
18
+ };
2
19
 
3
20
  export const report = () => 'Remove useless argument';
4
21
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-printer",
3
- "version": "8.17.0",
3
+ "version": "8.18.0",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin adds support of transformations for @putout/printer",
@@ -43,13 +43,12 @@
43
43
  "@putout/plugin-remove-nested-blocks": "*",
44
44
  "@putout/test": "^15.0.0",
45
45
  "eslint": "^10.0.0",
46
- "eslint-plugin-n": "^17.0.0",
47
46
  "eslint-plugin-putout": "^31.0.0",
48
47
  "madrun": "^13.0.0",
49
- "montag": "^1.2.1",
48
+ "montag": "^2.0.0",
50
49
  "nodemon": "^3.0.1",
51
50
  "superc8": "^12.0.0",
52
- "supertape": "^12.7.0"
51
+ "supertape": "^13.0.0"
53
52
  },
54
53
  "peerDependencies": {
55
54
  "putout": ">=42"