@putout/eslint 1.1.0 β†’ 1.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.
package/README.md CHANGED
@@ -34,7 +34,7 @@ const [source, places] = await eslint({
34
34
  Isn't it looks similar to 🐊**Putout** way? It definitely is! But... It has a couple differences you should remember:
35
35
 
36
36
  - ☝️ *[🐊**Putout** returns object with `code` and `places` properties](https://github.com/coderaiser/putout#plugins).*
37
- - ☝️ * **ESLint** has a `name` property that is used to calculate configuration file. *
37
+ - ☝️ ***ESLint** has a `name` property that is used to calculate configuration file.*
38
38
 
39
39
  And you can even override any of **ESLint** βš™οΈ options with help of `config` property:
40
40
 
@@ -135,10 +135,24 @@ Or just:
135
135
  const {createPlugin} = require('@putout/eslint/create-plugin');
136
136
 
137
137
  module.exports.rules = {
138
- 'remove-duplicate-extensions': createPlugin('remove-duplicate-extensions'),
138
+ 'remove-duplicate-extensions': createPlugin(require('./remove-duplicate-extensions')),
139
139
  };
140
140
  ```
141
141
 
142
+ ### `lint(code, {fix, plugins})`
143
+
144
+ ```js
145
+ const lint = require('@putout/eslint/lint');
146
+ const removeDebugger = require('./remove-debugger');
147
+
148
+ const [code, places] = lint('debugger', {
149
+ fix: true, // default
150
+ plugins: [
151
+ ['remove-debugger', createPlugin(removeDebugger)],
152
+ ],
153
+ });
154
+ ```
155
+
142
156
  ## License
143
157
 
144
158
  MIT
@@ -114,6 +114,7 @@ const createGetSpacesBeforeNode = ({getText}) => (node, text = getText(node)) =>
114
114
 
115
115
  return spaces.slice(1);
116
116
  };
117
+ module.exports.createGetSpaceBeforeNode = createGetSpacesBeforeNode;
117
118
 
118
119
  const createGetSpacesAfterNode = ({getText}) => (node, {text = getText(node)}) => {
119
120
  let spaces = '';
@@ -125,4 +126,4 @@ const createGetSpacesAfterNode = ({getText}) => (node, {text = getText(node)}) =
125
126
 
126
127
  return spaces.slice(0, -1);
127
128
  };
128
-
129
+ module.exports.createGetSpacesAfterNode = createGetSpacesAfterNode;
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ const {Linter} = require('eslint');
4
+ const {convertToPlace} = require('../eslint.js');
5
+
6
+ module.exports.lint = (source, {fix = true, plugins}) => {
7
+ const [name, plugin] = plugins[0];
8
+ const linter = new Linter({
9
+ configType: 'flat',
10
+ });
11
+
12
+ const options = {
13
+ rules: {
14
+ [`${name}/plugin`]: 'error',
15
+ },
16
+ plugins: {
17
+ [name]: {
18
+ rules: {
19
+ plugin,
20
+ },
21
+ },
22
+ },
23
+ };
24
+
25
+ if (!fix) {
26
+ const places = linter.verify(source, options).map(convertToPlace);
27
+ return [source, places];
28
+ }
29
+
30
+ const {output, messages} = linter.verifyAndFix(source, options);
31
+
32
+ return [output, messages.map(convertToPlace)];
33
+ };
34
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/eslint",
3
- "version": "1.1.0",
3
+ "version": "1.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",
@@ -12,7 +12,8 @@
12
12
  "changelog": false,
13
13
  "exports": {
14
14
  ".": "./lib/eslint.js",
15
- "./create-plugin": "./lib/create-plugin/index.js"
15
+ "./create-plugin": "./lib/create-plugin/index.js",
16
+ "./lint": "./lib/lint/index.js"
16
17
  },
17
18
  "repository": {
18
19
  "type": "git",