@putout/eslint 1.2.0 → 1.3.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/README.md CHANGED
@@ -92,6 +92,12 @@ module.exports.filter = (path) => {
92
92
  };
93
93
  ```
94
94
 
95
+ The main difference with [Includer](https://github.com/coderaiser/putout/tree/master/packages/engine-runner#includer) is:
96
+
97
+ - `fix` works with text;
98
+ - `include` does not support 🦎[PutoutScript](https://github.com/coderaiser/putout/blob/master/docs/putout-script.md#-putoutscript);
99
+ - there is no `exclude`;
100
+
95
101
  Take a look at more sophisticated example, rule [`remove-duplicate-extensions`](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout/lib/remove-duplicate-extensions#readme):
96
102
 
97
103
  ```js
@@ -139,7 +145,9 @@ module.exports.rules = {
139
145
  };
140
146
  ```
141
147
 
142
- ### `lint(code, {fix, plugins})`
148
+ ### `lint(source, {fix, plugins, options, filename})`
149
+
150
+ When you need to run **ESLint** with one plugin (*rule*), just use `lint` it will do the thing.
143
151
 
144
152
  ```js
145
153
  const lint = require('@putout/eslint/lint');
@@ -153,6 +161,22 @@ const [code, places] = lint('debugger', {
153
161
  });
154
162
  ```
155
163
 
164
+ When you want to skip plugins, and just provide `options` and `filename` you can:
165
+
166
+ ```js
167
+ const lint = require('@putout/eslint/lint');
168
+ const removeDebugger = require('./remove-debugger');
169
+
170
+ const [code, places] = lint('debugger', {
171
+ filename: 'index.js',
172
+ options: [{
173
+ rules: {
174
+ semi: 'error',
175
+ },
176
+ }],
177
+ });
178
+ ```
179
+
156
180
  ## License
157
181
 
158
182
  MIT
package/lib/lint/index.js CHANGED
@@ -3,31 +3,42 @@
3
3
  const {Linter} = require('eslint');
4
4
  const {convertToPlace} = require('../eslint.js');
5
5
 
6
- module.exports.lint = (source, {fix = true, plugins}) => {
7
- const [name, plugin] = plugins[0];
6
+ module.exports.lint = (source, {fix = true, plugins, filename, options = []}) => {
8
7
  const linter = new Linter({
9
8
  configType: 'flat',
10
9
  });
11
10
 
12
- const options = {
13
- rules: {
14
- [`${name}/plugin`]: 'error',
15
- },
16
- plugins: {
17
- [name]: {
18
- rules: {
19
- plugin,
11
+ const allOptions = [];
12
+
13
+ if (plugins) {
14
+ const [name, plugin] = plugins[0];
15
+ allOptions.push({
16
+ rules: {
17
+ [`${name}/plugin`]: 'error',
18
+ },
19
+ plugins: {
20
+ [name]: {
21
+ rules: {
22
+ plugin,
23
+ },
20
24
  },
21
25
  },
22
- },
23
- };
26
+ });
27
+ }
28
+
29
+ allOptions.push(...options);
30
+
31
+ const mainOptions = {};
32
+
33
+ if (filename)
34
+ mainOptions.filename = filename;
24
35
 
25
36
  if (!fix) {
26
- const places = linter.verify(source, options).map(convertToPlace);
37
+ const places = linter.verify(source, allOptions, mainOptions).map(convertToPlace);
27
38
  return [source, places];
28
39
  }
29
40
 
30
- const {output, messages} = linter.verifyAndFix(source, options);
41
+ const {output, messages} = linter.verifyAndFix(source, allOptions, mainOptions);
31
42
 
32
43
  return [output, messages.map(convertToPlace)];
33
44
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/eslint",
3
- "version": "1.2.0",
3
+ "version": "1.3.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",