@putout/eslint 2.0.1 → 2.2.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.
@@ -1,10 +1,13 @@
1
1
  'use strict';
2
2
 
3
3
  const prepare = (plugin, context, options) => (node) => {
4
- const {filter, report} = plugin;
4
+ const {
5
+ filter,
6
+ report,
7
+ } = plugin;
5
8
 
6
- const source = context.getSourceCode();
7
- const filename = context.getFilename();
9
+ const source = context.sourceCode;
10
+ const {filename} = context;
8
11
  const getText = source.getText.bind(source);
9
12
  const getCommentsBefore = source.getCommentsBefore.bind(source);
10
13
  const getCommentsAfter = source.getCommentsAfter.bind(source);
@@ -31,7 +34,7 @@ const prepare = (plugin, context, options) => (node) => {
31
34
  getSpacesBeforeNode,
32
35
  getSpacesAfterNode,
33
36
  filename,
34
- });
37
+ }, options);
35
38
 
36
39
  if (!result)
37
40
  return;
@@ -71,7 +74,10 @@ module.exports.createPlugin = (plugin) => {
71
74
  create(context) {
72
75
  const {options} = context;
73
76
  const prepared = prepare(plugin, context, options);
74
- const names = plugin.include({options});
77
+
78
+ const names = plugin.include({
79
+ options,
80
+ });
75
81
 
76
82
  return getTraversers(names, prepared);
77
83
  },
@@ -112,11 +118,11 @@ const createGetSpacesBeforeNode = ({getText}) => (node, text = getText(node)) =>
112
118
  return '';
113
119
 
114
120
  while (!spaces || /^[ \n]+$/.test(spaces))
115
- spaces = getText(node, ++i)
116
- .replace(text, '');
121
+ spaces = getText(node, ++i).replace(text, '');
117
122
 
118
123
  return spaces.slice(1);
119
124
  };
125
+
120
126
  module.exports.createGetSpacesBeforeNode = createGetSpacesBeforeNode;
121
127
 
122
128
  const createGetSpacesAfterNode = ({getText}) => (node, text = getText(node)) => {
@@ -129,8 +135,7 @@ const createGetSpacesAfterNode = ({getText}) => (node, text = getText(node)) =>
129
135
  let i = 0;
130
136
 
131
137
  while (!spaces || reg.test(spaces))
132
- spaces = getText(node, 0, ++i)
133
- .replace(text, '');
138
+ spaces = getText(node, 0, ++i).replace(text, '');
134
139
 
135
140
  return spaces.slice(0, -1);
136
141
  };
@@ -149,4 +154,3 @@ function isLastNodeInBody(node) {
149
154
 
150
155
  return false;
151
156
  }
152
-
package/lib/eslint.js CHANGED
@@ -43,6 +43,7 @@ module.exports = async ({name, code, fix, config, putout = false}) => {
43
43
  return noChanges;
44
44
 
45
45
  const {getESLint} = ESLint;
46
+
46
47
  const [eslintError, eslint] = await tryToCatch(getESLint, {
47
48
  name,
48
49
  fix,
@@ -50,11 +51,13 @@ module.exports = async ({name, code, fix, config, putout = false}) => {
50
51
  overrideConfigFile,
51
52
  });
52
53
 
53
- if (eslintError)
54
- return [
55
- code,
56
- [convertToPlace(cutNewLine(eslintError))],
54
+ if (eslintError) {
55
+ const places = [
56
+ convertToPlace(cutNewLine(eslintError)),
57
57
  ];
58
+
59
+ return [code, places];
60
+ }
58
61
 
59
62
  const [configError, finalConfig] = await tryToCatch(eslint.calculateConfigForFile, name);
60
63
 
@@ -62,16 +65,17 @@ module.exports = async ({name, code, fix, config, putout = false}) => {
62
65
  return noChanges;
63
66
 
64
67
  if (configError) {
65
- return [
66
- code,
67
- [convertToPlace(parseError(configError))],
68
+ const places = [
69
+ convertToPlace(parseError(configError)),
68
70
  ];
71
+
72
+ return [code, places];
69
73
  }
70
74
 
71
75
  !putout && disablePutout(finalConfig);
72
-
73
76
  // that's right, we disabled "putout" rules in "config"
74
77
  // and now it located in eslint's cache
78
+
75
79
  const results = await eslint.lintText(code, {
76
80
  filePath: name,
77
81
  });
@@ -81,7 +85,9 @@ module.exports = async ({name, code, fix, config, putout = false}) => {
81
85
 
82
86
  const [report] = results;
83
87
  const {output} = report;
84
- const places = report.messages
88
+
89
+ const places = report
90
+ .messages
85
91
  .map(convertToPlace)
86
92
  .filter(Boolean);
87
93
 
@@ -141,4 +147,3 @@ function parseError(e) {
141
147
  message: `Plugin missing: ${messageData.pluginName}`,
142
148
  };
143
149
  }
144
-
@@ -75,4 +75,3 @@ function getFlatESLint({fix, config, overrideConfigFile, ESLintOverride = FlatES
75
75
 
76
76
  return eslint;
77
77
  }
78
-
package/lib/lint/index.js CHANGED
@@ -12,6 +12,7 @@ module.exports.lint = (source, {fix = true, plugins, filename, options = []}) =>
12
12
 
13
13
  if (plugins) {
14
14
  const [name, plugin] = plugins[0];
15
+
15
16
  allOptions.push({
16
17
  rules: {
17
18
  [`${name}/plugin`]: 'error',
@@ -34,12 +35,17 @@ module.exports.lint = (source, {fix = true, plugins, filename, options = []}) =>
34
35
  mainOptions.filename = filename;
35
36
 
36
37
  if (!fix) {
37
- const places = linter.verify(source, allOptions, mainOptions).map(convertToPlace);
38
+ const places = linter
39
+ .verify(source, allOptions, mainOptions)
40
+ .map(convertToPlace);
41
+
38
42
  return [source, places];
39
43
  }
40
44
 
41
- const {output, messages} = linter.verifyAndFix(source, allOptions, mainOptions);
45
+ const {
46
+ output,
47
+ messages,
48
+ } = linter.verifyAndFix(source, allOptions, mainOptions);
42
49
 
43
50
  return [output, messages.map(convertToPlace)];
44
51
  };
45
-
@@ -4,4 +4,3 @@ module.exports.simpleImport = async (url) => {
4
4
  const result = await import(url);
5
5
  return result.default || result;
6
6
  };
7
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/eslint",
3
- "version": "2.0.1",
3
+ "version": "2.2.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Wrapper that simplifies ESLint API and makes it compatible with 🐊Putout",
@@ -37,9 +37,10 @@
37
37
  "eslint"
38
38
  ],
39
39
  "devDependencies": {
40
+ "@putout/plugin-eslint-plugin": "*",
40
41
  "c8": "^7.5.0",
41
42
  "eslint": "^8.0.1",
42
- "eslint-plugin-n": "^15.2.4",
43
+ "eslint-plugin-n": "^16.0.0",
43
44
  "eslint-plugin-putout": "^17.0.0",
44
45
  "just-camel-case": "^4.0.2",
45
46
  "lerna": "^6.0.1",