putout 35.17.0 → 35.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.
- package/ChangeLog +6 -4
- package/lib/parse-options/index.js +26 -35
- package/lib/parse-options/read-rules.js +44 -0
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
2024.04.29, v35.18.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 94b8e8908 putout: parse-options: rulesdir: exclude *.md
|
|
5
|
+
- 2a817e8a5 @putout/operate: insertAfter: wrap ExpressionStatement when current path is Statement and node not
|
|
6
|
+
|
|
1
7
|
2024.04.28, v35.17.0
|
|
2
8
|
|
|
3
9
|
fix:
|
|
4
10
|
- a87e7e06c @putout/plugin-nodejs: add-node-predynamic: Identifier
|
|
5
11
|
- ca542fb12 @putout/eslint: no config found: Flat Config error -> RC error
|
|
6
|
-
- 949e898c9 feature: @putout/plugin-nodejs: add-node-presimplify
|
|
7
|
-
- 1551e9f04 feature: @putout/plugin-nodejs: add-node-predynamic import
|
|
8
|
-
- 08acf9555 feature: @putout/plugin-nodejs: add-node-preadd require
|
|
9
|
-
- 6744c616f feature: @putout/plugin-nodejs: add-node-prereport
|
|
10
12
|
|
|
11
13
|
feature:
|
|
12
14
|
- 9f76b2a51 putout: @putout/quick-lint v1.0.0
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const process = require('node:process');
|
|
4
4
|
const {homedir} = require('node:os');
|
|
5
|
-
const {readdirSync} = require('node:fs');
|
|
5
|
+
const {readdirSync: _readdirSync} = require('node:fs');
|
|
6
6
|
|
|
7
7
|
const {dirname, join} = require('node:path');
|
|
8
8
|
|
|
@@ -16,10 +16,11 @@ const merge = require('../merge');
|
|
|
16
16
|
const recursiveRead = require('./recursive-read');
|
|
17
17
|
const applyModuleTypeRules = require('./apply-module-type-rules');
|
|
18
18
|
const {validateOptions} = require('./validate-options');
|
|
19
|
+
const {readRules} = require('./read-rules');
|
|
19
20
|
|
|
20
21
|
const home = homedir();
|
|
21
22
|
|
|
22
|
-
module.exports = (info = {}) => {
|
|
23
|
+
module.exports = (info = {}, overrides = {}) => {
|
|
23
24
|
const {
|
|
24
25
|
rulesdir,
|
|
25
26
|
name = '',
|
|
@@ -29,6 +30,8 @@ module.exports = (info = {}) => {
|
|
|
29
30
|
readCodeMods = _readCodeMods,
|
|
30
31
|
} = info;
|
|
31
32
|
|
|
33
|
+
const {cwd = process.cwd(), readdirSync = _readdirSync} = overrides;
|
|
34
|
+
|
|
32
35
|
const [dir, customOptions] = readOptions(name);
|
|
33
36
|
const homeOptions = readHomeOptions();
|
|
34
37
|
const defaultMatch = parseMatch(name, defaultOptions.match);
|
|
@@ -54,12 +57,26 @@ module.exports = (info = {}) => {
|
|
|
54
57
|
|
|
55
58
|
const mergedMatch = merge(customOptions, options, parseMatch(name, options.match));
|
|
56
59
|
|
|
57
|
-
const
|
|
60
|
+
const resultOptionsList = [
|
|
61
|
+
readCodeMods({
|
|
62
|
+
cwd,
|
|
63
|
+
readdirSync,
|
|
64
|
+
}),
|
|
65
|
+
readRules('./', rulesdir, {
|
|
66
|
+
cwd,
|
|
67
|
+
readdirSync,
|
|
68
|
+
}),
|
|
69
|
+
mergedOptions,
|
|
70
|
+
mergedDefaultsMatch,
|
|
71
|
+
mergedMatch,
|
|
72
|
+
];
|
|
73
|
+
|
|
74
|
+
const finalMergedOptions = merge(...resultOptionsList);
|
|
58
75
|
|
|
59
|
-
validateOptions(
|
|
76
|
+
validateOptions(finalMergedOptions);
|
|
60
77
|
|
|
61
78
|
return {
|
|
62
|
-
...
|
|
79
|
+
...finalMergedOptions,
|
|
63
80
|
dir,
|
|
64
81
|
};
|
|
65
82
|
};
|
|
@@ -86,35 +103,6 @@ function _readOptions(name) {
|
|
|
86
103
|
return ['', {}];
|
|
87
104
|
}
|
|
88
105
|
|
|
89
|
-
const isInclude = (a) => a[0] !== '.' && !/(^not-rule-.*|^node_modules$)/.test(a);
|
|
90
|
-
|
|
91
|
-
function readRules(dirOpt, rulesDir) {
|
|
92
|
-
if (!rulesDir)
|
|
93
|
-
return {};
|
|
94
|
-
|
|
95
|
-
let dir = join(dirOpt, rulesDir);
|
|
96
|
-
|
|
97
|
-
if (!dir.startsWith('/'))
|
|
98
|
-
dir = join(process.cwd(), rulesDir);
|
|
99
|
-
|
|
100
|
-
const [e, names] = tryCatch(readdirSync, dir);
|
|
101
|
-
|
|
102
|
-
if (e)
|
|
103
|
-
return {};
|
|
104
|
-
|
|
105
|
-
const plugins = [];
|
|
106
|
-
|
|
107
|
-
for (const name of names.filter(isInclude)) {
|
|
108
|
-
const full = join(dir, name);
|
|
109
|
-
|
|
110
|
-
plugins.push(`import:${full}`);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return {
|
|
114
|
-
plugins,
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
|
|
118
106
|
const _readHomeOptions = once(() => {
|
|
119
107
|
const name = join(home, '.putout.json');
|
|
120
108
|
const [, data = {}] = tryCatch(require, name);
|
|
@@ -122,4 +110,7 @@ const _readHomeOptions = once(() => {
|
|
|
122
110
|
return data;
|
|
123
111
|
});
|
|
124
112
|
|
|
125
|
-
const _readCodeMods = once(() => readRules(home, '.putout'
|
|
113
|
+
const _readCodeMods = once(({cwd, readdirSync}) => readRules(home, '.putout', {
|
|
114
|
+
cwd,
|
|
115
|
+
readdirSync,
|
|
116
|
+
}));
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {join} = require('node:path');
|
|
4
|
+
|
|
5
|
+
const tryCatch = require('try-catch');
|
|
6
|
+
|
|
7
|
+
const isInclude = (a) => {
|
|
8
|
+
if (a[0] === '.')
|
|
9
|
+
return false;
|
|
10
|
+
|
|
11
|
+
if (/(^not-rule-.*|^node_modules$)/.test(a))
|
|
12
|
+
return false;
|
|
13
|
+
|
|
14
|
+
return !a.endsWith('.md');
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
module.exports.readRules = (dirOpt, rulesDir, overrides) => {
|
|
18
|
+
if (!rulesDir)
|
|
19
|
+
return {};
|
|
20
|
+
|
|
21
|
+
const {cwd, readdirSync} = overrides;
|
|
22
|
+
|
|
23
|
+
let dir = join(dirOpt, rulesDir);
|
|
24
|
+
|
|
25
|
+
if (!dir.startsWith('/'))
|
|
26
|
+
dir = join(cwd, rulesDir);
|
|
27
|
+
|
|
28
|
+
const [e, names] = tryCatch(readdirSync, dir);
|
|
29
|
+
|
|
30
|
+
if (e)
|
|
31
|
+
return {};
|
|
32
|
+
|
|
33
|
+
const plugins = [];
|
|
34
|
+
|
|
35
|
+
for (const name of names.filter(isInclude)) {
|
|
36
|
+
const full = join(dir, name);
|
|
37
|
+
|
|
38
|
+
plugins.push(`import:${full}`);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
plugins,
|
|
43
|
+
};
|
|
44
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "putout",
|
|
3
|
-
"version": "35.
|
|
3
|
+
"version": "35.18.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",
|