@putout/plugin-putout-config 4.0.0 β†’ 4.1.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.
package/README.md CHANGED
@@ -17,6 +17,7 @@ npm i @putout/plugin-putout-config -D
17
17
  {
18
18
  "rules": {
19
19
  "putout-config/convert-boolean-to-string": "on",
20
+ "putout-config/move-formatter-up": "on",
20
21
  "putout-config/remove-empty": "on"
21
22
  }
22
23
  }
@@ -46,6 +47,34 @@ npm i @putout/plugin-putout-config -D
46
47
  }
47
48
  ```
48
49
 
50
+ ## move-formatter-up
51
+
52
+ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/48ce05b358a9118250acdc0b35df0fc8/50aeb680193ab4cd5d247e098ff90be8d4092111).
53
+
54
+ ### ❌ Example of incorrect code
55
+
56
+ ```json
57
+ {
58
+ "parser": "babel",
59
+ "rules": {
60
+ "remove-unused-variables": "off"
61
+ },
62
+ "formatter": "progress-bar"
63
+ }
64
+ ```
65
+
66
+ ### βœ… Example of correct code
67
+
68
+ ```json
69
+ {
70
+ "parser": "babel",
71
+ "formatter": "progress-bar",
72
+ "rules": {
73
+ "remove-unused-variables": "off"
74
+ }
75
+ }
76
+ ```
77
+
49
78
  ## remove-empty
50
79
 
51
80
  ### ❌ Example of incorrect code
package/lib/index.js CHANGED
@@ -2,8 +2,10 @@
2
2
 
3
3
  const convertBooleanToString = require('./convert-boolean-to-string');
4
4
  const removeEmpty = require('./remove-empty');
5
+ const MoveFormatterUp = require('./move-formatter-up');
5
6
 
6
7
  module.exports.rules = {
7
8
  'convert-boolean-to-string': convertBooleanToString,
8
9
  'remove-empty': removeEmpty,
10
+ 'move-formatter-up': MoveFormatterUp,
9
11
  };
@@ -0,0 +1,44 @@
1
+ 'use strict';
2
+
3
+ const {operator} = require('putout');
4
+ const {
5
+ insertAfter,
6
+ remove,
7
+ getProperties,
8
+ getProperty,
9
+ } = operator;
10
+
11
+ module.exports.report = () => `Move 'formatter' up`;
12
+
13
+ module.exports.match = () => ({
14
+ '__putout_processor(__object)': (vars, path) => {
15
+ const objectPath = path.get('arguments.0');
16
+ const formatterPath = getProperty(objectPath, 'formatter');
17
+
18
+ if (!formatterPath)
19
+ return false;
20
+
21
+ const next = formatterPath.getNextSibling().node;
22
+ const prev = formatterPath.getPrevSibling().node;
23
+
24
+ return !next && prev;
25
+ },
26
+ });
27
+
28
+ module.exports.replace = () => ({
29
+ '__putout_processor(__object)': (vars, path) => {
30
+ const objectPath = path.get('arguments.0');
31
+ const {formatterPath, parserPath} = getProperties(objectPath, ['formatter', 'parser']);
32
+
33
+ const {node} = formatterPath;
34
+
35
+ remove(formatterPath);
36
+
37
+ if (!parserPath)
38
+ objectPath.node.properties.unshift(node);
39
+ else if (!parserPath.getPrevSibling().node)
40
+ insertAfter(parserPath, node);
41
+
42
+ return path;
43
+ },
44
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-putout-config",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin helps to maintain putout config",