Skip to content

Commit 487a24e

Browse files
committed
feature: @putout/cli-process-file: add
1 parent 34c38b8 commit 487a24e

File tree

28 files changed

+302
-59
lines changed

28 files changed

+302
-59
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": [
3+
"plugin:n/recommended",
4+
"plugin:putout/recommended"
5+
],
6+
"plugins": [
7+
"n",
8+
"putout"
9+
]
10+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
*.swp
3+
yarn-error.log
4+
5+
coverage
6+
.idea
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
const {run} = require('madrun');
4+
5+
module.exports = {
6+
'test': () => `tape 'lib/**/*.spec.*'`,
7+
'watch:test': async () => `nodemon -w lib -x ${await run('test')}`,
8+
'lint': () => `putout .`,
9+
'fresh:lint': () => run('lint', '--fresh'),
10+
'lint:fresh': () => run('lint', '--fresh'),
11+
'fix:lint': () => run('lint', '--fix'),
12+
'coverage': async () => `c8 ${await run('test')}`,
13+
'report': () => 'c8 report --reporter=lcov',
14+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.*
2+
*.spec.*
3+
test
4+
fixture
5+
yarn-error.log
6+
7+
coverage
8+
*.config.*
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"check-coverage": true,
3+
"all": true,
4+
"exclude": [
5+
"**/*.spec.*",
6+
"**/fixture",
7+
"test",
8+
".*.*",
9+
"**/*.config.*"
10+
],
11+
"branches": 100,
12+
"lines": 100,
13+
"functions": 100,
14+
"statements": 100
15+
}

packages/cli-process-file/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) coderaiser
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# @putout/cli-process-file [![NPM version][NPMIMGURL]][NPMURL]
2+
3+
[NPMIMGURL]: https://img.shields.io/npm/v/@putout/cli-process-file.svg?style=flat&longCache=true
4+
[NPMURL]: https://npmjs.org/package/@putout/cli-process-file "npm"
5+
6+
Process file using 🐊**Putout**, **Samadhi** and **ESLint**.
7+
8+
## Install
9+
10+
```
11+
npm i @putout/cli-process-file
12+
```
13+
14+
## Example
15+
16+
```js
17+
import initProcessFile from '@putout/cli-process-file';
18+
19+
const processFile = initProcessFile({
20+
fix: true,
21+
});
22+
23+
const {code, places} = await processFile({
24+
source: `
25+
const a = b.a
26+
`,
27+
});
28+
29+
// returns
30+
['const {a} = b;', [{
31+
rule: 'no-undef (eslint)',
32+
message: '\'b\' is not defined.',
33+
position: {
34+
line: 2,
35+
column: 13,
36+
},
37+
}]];
38+
```
39+
40+
## License
41+
42+
MIT
File renamed without changes.
File renamed without changes.

packages/putout/lib/cli/process-file.js renamed to packages/cli-process-file/lib/process-file.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,29 @@
22

33
const tryToCatch = require('try-to-catch');
44
const eslint = require('@putout/eslint');
5-
6-
const {putoutAsync} = require('../..');
7-
const merge = require('../merge');
8-
const parseMatch = require('../parse-options/parse-match');
5+
const {parseMatch} = require('putout/parse-match');
6+
const {mergeOptions} = require('putout/merge-options');
7+
const parseError = require('putout/parse-error');
8+
const {putoutAsync} = require('putout');
99

1010
const {simpleImport} = require('./simple-import');
11-
const parseError = require('../parse-error');
1211

1312
const getMatchedOptions = (name, options) => {
1413
if (!name.includes('{'))
1514
return options;
1615

17-
return merge(options, parseMatch(name, options.match));
16+
return mergeOptions(options, parseMatch(name, options.match));
1817
};
1918

20-
module.exports = ({fix, fixCount, isFlow, logError, raw}) => async function processFile({name, source, startLine, options, again}) {
19+
module.exports = ({fix, fixCount, isFlow, logError, raw}) => async function processFile(overrides) {
20+
const {
21+
name = '<input>',
22+
source,
23+
startLine,
24+
options = {},
25+
again,
26+
} = overrides;
27+
2128
const {configurePrinter} = await import('./printer/printer.mjs');
2229
const isTS = /\.tsx?$/.test(name) || /{tsx?}$/.test(name);
2330
const {printer, ...matchedOptions} = getMatchedOptions(name, options);

0 commit comments

Comments
 (0)