Skip to content

Commit 270da98

Browse files
committed
feature(@putout/processor-typescript) add
1 parent 5ba4c31 commit 270da98

File tree

15 files changed

+264
-3
lines changed

15 files changed

+264
-3
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ Here is a list of built-int processors:
113113
| [`@putout/processor-markdown`](/packages/processor-markdown) | [![npm](https://img.shields.io/npm/v/@putout/processor-markdown.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/processor-markdown) | [![Dependency Status](https://david-dm.org/coderaiser/putout.svg?path=packages/processor-markdown)](https://david-dm.org/coderaiser/putout?path=packages/processor-markdown) |
114114
| [`@putout/processor-ignore`](/packages/processor-ignore) | [![npm](https://img.shields.io/npm/v/@putout/processor-ignore.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/processor-ignore) | [![Dependency Status](https://david-dm.org/coderaiser/putout.svg?path=packages/processor-ignore)](https://david-dm.org/coderaiser/putout?path=packages/processor-ignore) |
115115
| [`@putout/processor-yaml`](/packages/processor-yaml) | [![npm](https://img.shields.io/npm/v/@putout/processor-yaml.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/processor-yaml) | [![Dependency Status](https://david-dm.org/coderaiser/putout.svg?path=packages/processor-yaml)](https://david-dm.org/coderaiser/putout?path=packages/processor-yaml) |
116-
| [`@putout/processor-css`](/packages/processor-css) | [![npm](https://img.shields.io/npm/v/@putout/processor-css.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/processor-css) | [![Dependency Status](https://david-dm.org/coderaiser/putout.svg?path=packages/processor-css)](https://david-dm.org/coderaiser/putout?path=packages/processor-css) |
117-
| [`@putout/processor-html`](/packages/processor-html) | [![npm](https://img.shields.io/npm/v/@putout/processor-html.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/processor-html) | [![Dependency Status](https://david-dm.org/coderaiser/putout.svg?path=packages/processor-html)](https://david-dm.org/coderaiser/putout?path=packages/processor-html) |
116+
| [`@putout/processor-css`](/packages/processor-css) | [![npm](https://img.shields.io/npm/v/@putout/processor-css.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/processor-css) | [![Dependency Status](https://david-dm.org/coderaiser/putout.svg?path=packages/processor-css)](https://david-dm.org/coderaiser/putout?path=packages/processor-css) || [`@putout/processor-html`](/packages/processor-html) | [![npm](https://img.shields.io/npm/v/@putout/processor-html.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/processor-html) | [![Dependency Status](https://david-dm.org/coderaiser/putout.svg?path=packages/processor-html)](https://david-dm.org/coderaiser/putout?path=packages/processor-html) |
117+
| [`@putout/processor-typescript`](/packages/processor-typescript) | [![npm](https://img.shields.io/npm/v/@putout/processor-typescript.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/processor-typescript) | [![Dependency Status](https://david-dm.org/coderaiser/putout.svg?path=packages/processor-typescript)](https://david-dm.org/coderaiser/putout?path=packages/processor-typescript) |
118118

119119
## API
120120

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"overrides": [{
3+
"files": "test/*.js",
4+
"rules": {
5+
"node/no-missing-require": "off"
6+
}
7+
}],
8+
"extends": [
9+
"plugin:node/recommended",
10+
"plugin:putout/recommended"
11+
],
12+
"plugins": [
13+
"putout",
14+
"node"
15+
]
16+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
*.swp
3+
yarn-error.log
4+
5+
coverage
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {run} from 'madrun';
2+
3+
export default {
4+
'test': () => `tape 'lib/**/*.spec.js' 'test/*.js'`,
5+
'watch:test': async () => `nodemon -w lib -w test -x ${await run('test')}`,
6+
'lint': () => `putout .`,
7+
'fresh:lint': () => run('lint', '--fresh'),
8+
'lint:fresh': () => run('lint', '--fresh'),
9+
'fix:lint': () => run('lint', '--fix'),
10+
'coverage': async () => `c8 ${await run('test')}`,
11+
'report': () => 'c8 report --reporter=lcov',
12+
};
13+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.*
2+
*.spec.js
3+
test
4+
yarn-error.log
5+
fixture
6+
7+
coverage
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"check-coverage": true,
3+
"all": true,
4+
"exclude": [
5+
"**/*.spec.*",
6+
"**/fixture",
7+
"test",
8+
".*.*"
9+
],
10+
"branches": 100,
11+
"lines": 100,
12+
"functions": 100,
13+
"statements": 100
14+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"rules": {
3+
"putout": "on"
4+
}
5+
}
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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# @putout/processor-typescript [![NPM version][NPMIMGURL]][NPMURL] [![Dependency Status][DependencyStatusIMGURL]][DependencyStatusURL]
2+
3+
[NPMIMGURL]: https://img.shields.io/npm/v/@putout/processor-typescript.svg?style=flat&longCache=true
4+
[NPMURL]: https://npmjs.org/package/@putout/processor-typescript "npm"
5+
6+
[DependencyStatusURL]: https://david-dm.org/coderaiser/putout?path=packages/processor-typescript
7+
[DependencyStatusIMGURL]: https://david-dm.org/coderaiser/putout.svg?path=packages/processor-typescript
8+
9+
`putout` processor adds support of type check for `typescript` files.
10+
11+
## Install
12+
13+
```
14+
npm i @putout/processor-typescript -D
15+
```
16+
17+
## Usage
18+
19+
```json
20+
{
21+
"processors": [
22+
"typescript"
23+
]
24+
}
25+
```
26+
27+
## License
28+
29+
MIT
30+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
3+
module.exports.files = [
4+
'*.ts',
5+
'*.tsx',
6+
];
7+
8+
module.exports.process = (rawSource) => {
9+
const {Project} = require('ts-morph');
10+
const project = new Project();
11+
12+
const sourceFile = project.createSourceFile('__putout_processor_typescript.ts', rawSource);
13+
const diagnostics = sourceFile.getPreEmitDiagnostics();
14+
15+
const places = diagnostics.map(toPlace);
16+
17+
return [rawSource, places];
18+
};
19+
20+
function toPlace(diagnostic) {
21+
return {
22+
rule: 'type-check (typescript)',
23+
message: diagnostic.getMessageText(),
24+
position: {
25+
line: diagnostic.getLineNumber(),
26+
column: 1,
27+
},
28+
};
29+
}
30+

0 commit comments

Comments
 (0)