eslint-plugin-putout 16.0.1 → 16.2.1

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
@@ -160,6 +160,20 @@ Disabled 🐊**Putout** rules:
160
160
 
161
161
  When you want to enable ability to align spaces on empty lines, while have all benefits of `safe` preset: use `safe+align`.
162
162
 
163
+ ## Flat
164
+
165
+ The time is came for a [FlatConfig](https://eslint.org/blog/2022/08/new-config-system-part-2/). To use it with `eslint-plugin-putout` add to `eslint.config.js`:
166
+
167
+ ```js
168
+ const {recommended} = require('eslint-plugin-putout/config');
169
+ module.exports = [
170
+ ...recommended, {
171
+ },
172
+ ];
173
+ ```
174
+
175
+ `safe` and `safeAlign` supported as well.
176
+
163
177
  ## License
164
178
 
165
179
  MIT
@@ -0,0 +1,42 @@
1
+ 'use strict';
2
+
3
+ const putoutPlugin = require('..');
4
+ const nPlugin = require('eslint-plugin-n');
5
+
6
+ const {FlatCompat} = require('@eslint/eslintrc');
7
+
8
+ const compat = new FlatCompat({
9
+ baseDirectory: __dirname,
10
+ });
11
+
12
+ const rmPlugins = (a) => {
13
+ delete a.plugins;
14
+ return a;
15
+ };
16
+
17
+ const nPluginReady = compat.config(nPlugin.configs.recommended).map(rmPlugins);
18
+
19
+ const config = [{
20
+ plugins: {
21
+ putout: putoutPlugin,
22
+ },
23
+ }];
24
+
25
+ module.exports.recommended = [
26
+ ...nPluginReady,
27
+ ...compat.config(putoutPlugin.configs.recommended),
28
+ ...config,
29
+ ];
30
+
31
+ module.exports.safe = [
32
+ ...nPluginReady,
33
+ ...compat.config(putoutPlugin.configs.safe),
34
+ ...config,
35
+ ];
36
+
37
+ module.exports.safeAlign = [
38
+ ...nPluginReady,
39
+ ...compat.config(putoutPlugin.configs['safe+align']),
40
+ ...config,
41
+ ];
42
+
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const wrap = require('./wrap');
3
+ const {createPlugin} = require('@putout/eslint/create-plugin');
4
4
  const markdown = require('./markdown');
5
5
  const json = require('./json');
6
6
  const yaml = require('./yaml');
@@ -12,7 +12,7 @@ const getRule = (a) => ({
12
12
  });
13
13
 
14
14
  const getWrapRule = (a) => ({
15
- [a]: wrap(require(`./${a}`)),
15
+ [a]: createPlugin(require(`./${a}`)),
16
16
  });
17
17
 
18
18
  module.exports.rules = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-putout",
3
- "version": "16.0.1",
3
+ "version": "16.2.1",
4
4
  "type": "commonjs",
5
5
  "description": "ESLint plugin for 🐊Putout",
6
6
  "release": false,
@@ -11,6 +11,10 @@
11
11
  "type": "git",
12
12
  "url": "git://github.com/coderaiser/putout.git"
13
13
  },
14
+ "exports": {
15
+ ".": "./lib/index.js",
16
+ "./config": "./lib/config/index.js"
17
+ },
14
18
  "keywords": [
15
19
  "putout",
16
20
  "eslint",
@@ -19,6 +23,7 @@
19
23
  ],
20
24
  "author": "coderaiser",
21
25
  "main": "lib/index.js",
26
+ "commitType": "colon",
22
27
  "scripts": {
23
28
  "wisdom": "madrun wisdom",
24
29
  "test": "madrun test",
@@ -38,7 +43,9 @@
38
43
  "@babel/eslint-parser": "^7.15.0",
39
44
  "@babel/plugin-syntax-class-properties": "^7.12.1",
40
45
  "@babel/traverse": "^7.16.3",
46
+ "@eslint/eslintrc": "^1.3.1",
41
47
  "@putout/engine-parser": "^5.0.0",
48
+ "@putout/eslint": "^1.3.0",
42
49
  "@putout/eslint-config": "^7.0.0",
43
50
  "@typescript-eslint/eslint-plugin": "^5.5.0",
44
51
  "@typescript-eslint/parser": "^5.4.0",
package/lib/wrap.js DELETED
@@ -1,128 +0,0 @@
1
- 'use strict';
2
-
3
- const prepare = (plugin, context, options) => (node) => {
4
- const {filter, report} = plugin;
5
-
6
- const source = context.getSourceCode();
7
- const filename = context.getFilename();
8
- const getText = source.getText.bind(source);
9
- const getCommentsBefore = source.getCommentsBefore.bind(source);
10
- const getCommentsAfter = source.getCommentsAfter.bind(source);
11
- const getCommentsInside = source.getCommentsInside.bind(source);
12
-
13
- const getSpacesBeforeNode = createGetSpacesBeforeNode({
14
- getText,
15
- });
16
-
17
- const getSpacesAfterNode = createGetSpacesAfterNode({
18
- getText,
19
- });
20
-
21
- const text = getText(node);
22
-
23
- const result = filter({
24
- text,
25
- node,
26
- options,
27
- getText,
28
- getCommentsBefore,
29
- getCommentsAfter,
30
- getCommentsInside,
31
- getSpacesBeforeNode,
32
- getSpacesAfterNode,
33
- filename,
34
- });
35
-
36
- if (!result)
37
- return;
38
-
39
- const fix = prepareFix(plugin.fix, {
40
- filename,
41
- node,
42
- text,
43
- getText,
44
- });
45
-
46
- context.report({
47
- node,
48
- message: report(node),
49
- fix,
50
- });
51
- };
52
-
53
- const prepareFix = (fix, {node, text, getText, filename}) => (fixer) => {
54
- const fixed = fix({
55
- node,
56
- text,
57
- getText,
58
- filename,
59
- });
60
-
61
- return [
62
- fixer.replaceText(node, fixed),
63
- ];
64
- };
65
-
66
- module.exports = (plugin) => {
67
- const meta = getMeta(plugin);
68
-
69
- return {
70
- meta,
71
- create(context) {
72
- const {options} = context;
73
- const prepared = prepare(plugin, context, options);
74
- const names = plugin.include({options});
75
-
76
- return getTraversers(names, prepared);
77
- },
78
- };
79
- };
80
-
81
- function getMeta(plugin) {
82
- const {
83
- type = 'layout',
84
- recommended = true,
85
- fixable = 'whitespace',
86
- } = plugin;
87
-
88
- return {
89
- type,
90
- docs: {
91
- recommended,
92
- },
93
- schema: {},
94
- fixable,
95
- };
96
- }
97
-
98
- function getTraversers(names, plugin) {
99
- const traversers = {};
100
-
101
- for (const name of names)
102
- traversers[name] = plugin;
103
-
104
- return traversers;
105
- }
106
-
107
- const createGetSpacesBeforeNode = ({getText}) => (node, text = getText(node)) => {
108
- let spaces = '';
109
- let i = 0;
110
-
111
- while (!spaces || /^[ \n]+$/.test(spaces))
112
- spaces = getText(node, ++i)
113
- .replace(text, '');
114
-
115
- return spaces.slice(1);
116
- };
117
-
118
- const createGetSpacesAfterNode = ({getText}) => (node, {text = getText(node)}) => {
119
- let spaces = '';
120
- let i = 0;
121
-
122
- while (!spaces || /^[ \n;]+$/.test(spaces))
123
- spaces = getText(node, 0, ++i)
124
- .replace(text, '');
125
-
126
- return spaces.slice(0, -1);
127
- };
128
-