putout 35.17.0 → 35.19.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 CHANGED
@@ -1,12 +1,23 @@
1
+ 2024.05.03, v35.19.0
2
+
3
+ fix:
4
+ - b47fc0082 eslint-plugin-putout: long-properties-destructuring: ImportDeclaration: no imported
5
+
6
+ feature:
7
+ - 06c23903c putout: @putout/plugin-apply-overrides v1.0.0
8
+ - 78a37907a eslint-plugin-putout: long-properties-destructuring: add support of ImportDeclaration (align with @putout/printer maxPropertiesLengthInOneLine)
9
+
10
+ 2024.04.29, v35.18.0
11
+
12
+ feature:
13
+ - 94b8e8908 putout: parse-options: rulesdir: exclude *.md
14
+ - 2a817e8a5 @putout/operate: insertAfter: wrap ExpressionStatement when current path is Statement and node not
15
+
1
16
  2024.04.28, v35.17.0
2
17
 
3
18
  fix:
4
19
  - a87e7e06c @putout/plugin-nodejs: add-node-predynamic: Identifier
5
20
  - 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
21
 
11
22
  feature:
12
23
  - 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 resultOptions = merge(readCodeMods(), readRules('./', rulesdir), mergedOptions, mergedDefaultsMatch, mergedMatch);
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(resultOptions);
76
+ validateOptions(finalMergedOptions);
60
77
 
61
78
  return {
62
- ...resultOptions,
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.17.0",
3
+ "version": "35.19.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",
@@ -90,6 +90,7 @@
90
90
  "@putout/plugin-apply-early-return": "^3.0.0",
91
91
  "@putout/plugin-apply-flat-map": "^2.0.0",
92
92
  "@putout/plugin-apply-optional-chaining": "^5.0.0",
93
+ "@putout/plugin-apply-overrides": "^1.0.0",
93
94
  "@putout/plugin-apply-starts-with": "^1.0.0",
94
95
  "@putout/plugin-apply-template-literals": "^3.0.0",
95
96
  "@putout/plugin-browserlist": "^2.0.0",
package/putout.json CHANGED
@@ -190,6 +190,7 @@
190
190
  "apply-optional-chaining",
191
191
  "apply-starts-with",
192
192
  "apply-template-literals",
193
+ "apply-overrides",
193
194
  "extract-object-properties",
194
195
  "extract-sequence-expressions",
195
196
  "madrun",