putout 27.4.0 → 27.7.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/ChangeLog +24 -0
- package/lib/cli/process-file.js +1 -1
- package/package.json +3 -3
- package/lib/cli/eslint/index.js +0 -152
package/ChangeLog
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
2022.08.28, v27.7.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- @putout/eslint: add
|
|
5
|
+
- package: @putout/eslint v1.0.0
|
|
6
|
+
|
|
7
|
+
2022.08.27, v27.6.0
|
|
8
|
+
|
|
9
|
+
fix:
|
|
10
|
+
- @putout/engine-runner: merge-visitors: add ☝️
|
|
11
|
+
|
|
12
|
+
feature:
|
|
13
|
+
- putout: cli: eslint: move out getESLint
|
|
14
|
+
- @putout/plugin-remove-empty: nested-pattern: Traverser -> Includer
|
|
15
|
+
- @putout/plugin-remove-empty: nested-pattern: add support of ArrayPattern
|
|
16
|
+
|
|
17
|
+
2022.08.26, v27.5.0
|
|
18
|
+
|
|
19
|
+
feature:
|
|
20
|
+
- package: @putout/plugin-remove-empty v9.0.0
|
|
21
|
+
- @putout/plugin-remove-empty: apply getRule
|
|
22
|
+
- @putout/plugin-remove-empty: drop support of 🐊 < 27
|
|
23
|
+
- @putout/plugin-remove-empty: add support of nested patterns (#109)
|
|
24
|
+
|
|
1
25
|
2022.08.25, v27.4.0
|
|
2
26
|
|
|
3
27
|
feature:
|
package/lib/cli/process-file.js
CHANGED
|
@@ -6,7 +6,7 @@ const putout = require('../..');
|
|
|
6
6
|
const merge = require('../merge');
|
|
7
7
|
const parseMatch = require('../parse-options/parse-match');
|
|
8
8
|
|
|
9
|
-
const eslint = require('
|
|
9
|
+
const eslint = require('@putout/eslint');
|
|
10
10
|
const parseError = require('./parse-error');
|
|
11
11
|
|
|
12
12
|
const getMatchedOptions = (name, options) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "putout",
|
|
3
|
-
"version": "27.
|
|
3
|
+
"version": "27.7.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "🐊 Pluggable and configurable code transformer with built-in ESLint, Babel and support of js, jsx, typescript, flow, markdown, yaml and json",
|
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
"./cli": "./lib/cli/index.js",
|
|
20
20
|
"./cli/run": "./lib/cli/runner/work",
|
|
21
21
|
"./loader": "./lib/loader.mjs",
|
|
22
|
-
"./eslint": "./lib/cli/eslint/index.js",
|
|
23
22
|
"./package.json": "./package.json"
|
|
24
23
|
},
|
|
25
24
|
"bin": {
|
|
@@ -58,6 +57,7 @@
|
|
|
58
57
|
"@putout/engine-parser": "^5.0.0",
|
|
59
58
|
"@putout/engine-processor": "^6.0.0",
|
|
60
59
|
"@putout/engine-runner": "^14.0.0",
|
|
60
|
+
"@putout/eslint": "^1.0.0",
|
|
61
61
|
"@putout/formatter-codeframe": "^4.0.0",
|
|
62
62
|
"@putout/formatter-dump": "^4.0.0",
|
|
63
63
|
"@putout/formatter-frame": "^3.0.0",
|
|
@@ -134,7 +134,7 @@
|
|
|
134
134
|
"@putout/plugin-remove-debugger": "^5.0.0",
|
|
135
135
|
"@putout/plugin-remove-duplicate-case": "^2.0.0",
|
|
136
136
|
"@putout/plugin-remove-duplicate-keys": "^3.0.0",
|
|
137
|
-
"@putout/plugin-remove-empty": "^
|
|
137
|
+
"@putout/plugin-remove-empty": "^9.0.0",
|
|
138
138
|
"@putout/plugin-remove-iife": "^1.0.0",
|
|
139
139
|
"@putout/plugin-remove-nested-blocks": "^6.0.0",
|
|
140
140
|
"@putout/plugin-remove-unreachable-code": "^1.0.0",
|
package/lib/cli/eslint/index.js
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const tryCatch = require('try-catch');
|
|
4
|
-
const tryToCatch = require('try-to-catch');
|
|
5
|
-
|
|
6
|
-
const [, eslint] = tryCatch(require, 'eslint');
|
|
7
|
-
const {ESLint} = eslint || {};
|
|
8
|
-
|
|
9
|
-
const {keys} = Object;
|
|
10
|
-
const overrideConfigFile = process.env.ESLINT_CONFIG_FILE;
|
|
11
|
-
|
|
12
|
-
const eslintId = ' (eslint)';
|
|
13
|
-
|
|
14
|
-
const noConfigFound = (config, configError) => {
|
|
15
|
-
if (configError && configError.messageTemplate === 'no-config-found')
|
|
16
|
-
return true;
|
|
17
|
-
|
|
18
|
-
if (configError)
|
|
19
|
-
return false;
|
|
20
|
-
|
|
21
|
-
if (!keys(config.rules).length)
|
|
22
|
-
return true;
|
|
23
|
-
|
|
24
|
-
return false;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const cutNewLine = ({message}) => ({
|
|
28
|
-
message: message.replace(/\n.*/, ''),
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const getESLint = ({fix, config}) => {
|
|
32
|
-
const eslint = new ESLint({
|
|
33
|
-
fix,
|
|
34
|
-
overrideConfig: {
|
|
35
|
-
ignorePatterns: [
|
|
36
|
-
'!.*',
|
|
37
|
-
],
|
|
38
|
-
...config,
|
|
39
|
-
},
|
|
40
|
-
...overrideConfigFile && {
|
|
41
|
-
overrideConfigFile,
|
|
42
|
-
useEslintrc: false,
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
return {
|
|
47
|
-
calculateConfigForFile: eslint.calculateConfigForFile.bind(eslint),
|
|
48
|
-
lintText: eslint.lintText.bind(eslint),
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
module.exports = async ({name, code, fix, config, putout = false}) => {
|
|
53
|
-
const noChanges = [
|
|
54
|
-
code,
|
|
55
|
-
[],
|
|
56
|
-
];
|
|
57
|
-
|
|
58
|
-
if (!ESLint)
|
|
59
|
-
return noChanges;
|
|
60
|
-
|
|
61
|
-
const [eslintError, eslint] = await tryToCatch(getESLint, {
|
|
62
|
-
fix,
|
|
63
|
-
config,
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
if (eslintError)
|
|
67
|
-
return [
|
|
68
|
-
code,
|
|
69
|
-
[convertToPlace(cutNewLine(eslintError))],
|
|
70
|
-
];
|
|
71
|
-
|
|
72
|
-
const [configError, finalConfig] = await tryToCatch(eslint.calculateConfigForFile, name);
|
|
73
|
-
|
|
74
|
-
if (noConfigFound(finalConfig, configError))
|
|
75
|
-
return noChanges;
|
|
76
|
-
|
|
77
|
-
if (configError) {
|
|
78
|
-
return [
|
|
79
|
-
code,
|
|
80
|
-
[convertToPlace(parseError(configError))],
|
|
81
|
-
];
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
!putout && disablePutout(finalConfig);
|
|
85
|
-
|
|
86
|
-
// that's right, we disabled "putout" rules in "config"
|
|
87
|
-
// and now it located in eslint's cache
|
|
88
|
-
const results = await eslint.lintText(code, {
|
|
89
|
-
filePath: name,
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
if (!results.length)
|
|
93
|
-
return noChanges;
|
|
94
|
-
|
|
95
|
-
const [report] = results;
|
|
96
|
-
const {output} = report;
|
|
97
|
-
const places = report.messages.map(convertToPlace);
|
|
98
|
-
|
|
99
|
-
return [
|
|
100
|
-
output || code,
|
|
101
|
-
places,
|
|
102
|
-
];
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
module.exports._noConfigFound = noConfigFound;
|
|
106
|
-
|
|
107
|
-
const parseRule = (rule) => rule || 'parser';
|
|
108
|
-
|
|
109
|
-
module.exports.convertToPlace = convertToPlace;
|
|
110
|
-
function convertToPlace({ruleId = 'parser', message, line = 0, column = 0}) {
|
|
111
|
-
const rule = `${parseRule(ruleId)}${eslintId}`;
|
|
112
|
-
|
|
113
|
-
return {
|
|
114
|
-
rule,
|
|
115
|
-
message: replaceControlChars(message),
|
|
116
|
-
position: {
|
|
117
|
-
line,
|
|
118
|
-
column,
|
|
119
|
-
},
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function disablePutout(config) {
|
|
124
|
-
if (!config.rules['putout/putout'])
|
|
125
|
-
return;
|
|
126
|
-
|
|
127
|
-
config.rules['putout/putout'] = 'off';
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// when eslint config got errors, table formatter used for reporting
|
|
131
|
-
// can't show control characters and crash
|
|
132
|
-
//
|
|
133
|
-
// https://stackoverflow.com/questions/26741455/how-to-remove-control-characters-from-string
|
|
134
|
-
const replaceControlChars = (a) => a.replace(/[\x00-\x1F]/g, '. ');
|
|
135
|
-
|
|
136
|
-
function parseError(e) {
|
|
137
|
-
const {
|
|
138
|
-
messageTemplate,
|
|
139
|
-
messageData,
|
|
140
|
-
message,
|
|
141
|
-
} = e;
|
|
142
|
-
|
|
143
|
-
if (messageTemplate !== 'plugin-missing')
|
|
144
|
-
return {
|
|
145
|
-
message: replaceControlChars(message),
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
return {
|
|
149
|
-
message: `Plugin missing: ${messageData.pluginName}`,
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
|