Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for reportFiles option #179

Merged
merged 4 commits into from
Oct 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v0.4.14

* [Add support for `reportFiles` option](https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/179) (#179)

## v0.4.13

* [Merge in `compilerOptions` prior to calling `parseJsonConfigFileContent`](https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/176) (#176)
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ List of typescript diagnostic codes to ignore.
* **ignoreLints** `string[]`:
List of tslint rule names to ignore.

* **reportFiles** `string[]`:
Only report errors on files matching these glob patterns. This can be useful when certain types definitions have errors that are not fatal to your application. Default: `[]`.

```js
// in webpack.config.js
new ForkTsCheckerWebpackPlugin({ reportFiles: ['src/**/*.{ts,tsx}', '!src/skip.ts'] })
```

* **colors** `boolean`:
If `false`, disables built-in colors in logger messages. Default: `true`.

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fork-ts-checker-webpack-plugin",
"version": "0.4.13",
"version": "0.4.14",
"description": "Runs typescript type checker and linter on separate process.",
"main": "lib/index.js",
"types": "lib/types/index.d.ts",
Expand Down Expand Up @@ -52,6 +52,7 @@
"@types/babel-code-frame": "^6.20.1",
"@types/chokidar": "^1.7.5",
"@types/lodash": "^4.14.117",
"@types/micromatch": "^3.1.0",
"@types/minimatch": "^3.0.1",
"@types/node": "^8.0.26",
"@types/resolve": "0.0.4",
Expand Down Expand Up @@ -88,6 +89,7 @@
"chalk": "^2.4.1",
"chokidar": "^2.0.4",
"lodash": "^4.17.11",
"micromatch": "^3.1.10",
"minimatch": "^3.0.4",
"resolve": "^1.5.0",
"tapable": "^1.0.0"
Expand Down
24 changes: 24 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as process from 'process';
import * as childProcess from 'child_process';
import chalk, { Chalk } from 'chalk';
import * as fs from 'fs';
import * as micromatch from 'micromatch';
import * as os from 'os';
import * as webpack from 'webpack';
import isString = require('lodash/isString');
Expand Down Expand Up @@ -45,6 +46,7 @@ interface Options {
async: boolean;
ignoreDiagnostics: number[];
ignoreLints: string[];
reportFiles: string[];
colors: boolean;
logger: Logger;
formatter: 'default' | 'codeframe' | Formatter;
Expand Down Expand Up @@ -77,6 +79,7 @@ class ForkTsCheckerWebpackPlugin {
watch: string[];
ignoreDiagnostics: number[];
ignoreLints: string[];
reportFiles: string[];
logger: Logger;
silent: boolean;
async: boolean;
Expand Down Expand Up @@ -130,6 +133,7 @@ class ForkTsCheckerWebpackPlugin {
: options.watch || [];
this.ignoreDiagnostics = options.ignoreDiagnostics || [];
this.ignoreLints = options.ignoreLints || [];
this.reportFiles = options.reportFiles || [];
this.logger = options.logger || console;
this.silent = options.silent === true; // default false
this.async = options.async !== false; // default true
Expand Down Expand Up @@ -674,6 +678,26 @@ class ForkTsCheckerWebpackPlugin {
);
}

if (this.reportFiles.length) {
const reportFilesPredicate = (diagnostic: NormalizedMessage): boolean => {
if (diagnostic.file) {
const relativeFileName = path.relative(
this.compiler.options.context,
diagnostic.file
);
const matchResult = micromatch([relativeFileName], this.reportFiles);

if (matchResult.length === 0) {
return false;
}
}
return true;
};

this.diagnostics = this.diagnostics.filter(reportFilesPredicate);
this.lints = this.lints.filter(reportFilesPredicate);
}

if ('hooks' in this.compiler) {
// webpack 4
this.compiler.hooks.forkTsCheckerReceive.call(
Expand Down
31 changes: 22 additions & 9 deletions test/integration/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,26 @@ describe('[INTEGRATION] index', function() {
it('should detect paths', function() {
var plugin = new ForkTsCheckerWebpackPlugin({ tslint: true });

expect(plugin.tsconfig).to.be.equal('./tsconfig.json');
expect(plugin.tslint).to.be.equal('./tslint.json');
expect(plugin.tsconfig).to.equal('./tsconfig.json');
expect(plugin.tslint).to.equal('./tslint.json');
});

it('should set logger to console by default', function() {
var plugin = new ForkTsCheckerWebpackPlugin({});

expect(plugin.logger).to.be.equal(console);
expect(plugin.logger).to.equal(console);
});

it('should set watch to empty array by default', function() {
var plugin = new ForkTsCheckerWebpackPlugin({});

expect(plugin.watch).to.be.deep.equal([]);
expect(plugin.watch).to.deep.equal([]);
});

it('should set watch to one element array for string', function() {
var plugin = new ForkTsCheckerWebpackPlugin({ watch: '/test' });

expect(plugin.watch).to.be.deep.equal(['/test']);
expect(plugin.watch).to.deep.equal(['/test']);
});

it('should work without configuration', function(callback) {
Expand Down Expand Up @@ -227,8 +227,8 @@ describe('[INTEGRATION] index', function() {
});

function compareResults() {
expect(errorsA).to.be.deep.equal(errorsB);
expect(warningsA).to.be.deep.equal(warningsB);
expect(errorsA).to.deep.equal(errorsB);
expect(warningsA).to.deep.equal(warningsB);
callback();
}
});
Expand Down Expand Up @@ -284,7 +284,7 @@ describe('[INTEGRATION] index', function() {
var compiler = createCompiler({}, true);

compiler.run(function(error, stats) {
expect(stats.compilation.errors.length).to.be.equal(1);
expect(stats.compilation.errors.length).to.equal(1);
callback();
});
});
Expand All @@ -293,7 +293,20 @@ describe('[INTEGRATION] index', function() {
var compiler = createCompiler({ checkSyntacticErrors: true }, true);

compiler.run(function(error, stats) {
expect(stats.compilation.errors.length).to.be.equal(2);
expect(stats.compilation.errors.length).to.equal(2);
callback();
});
});

it('should only show errors matching paths specified in reportFiles when provided', function(callback) {
var compiler = createCompiler(
{ checkSyntacticErrors: true, reportFiles: ['**/index.ts'] },
true
);

compiler.run(function(error, stats) {
expect(stats.compilation.errors.length).to.equal(1);
expect(stats.compilation.errors[0].file.endsWith('index.ts')).to.be.true;
callback();
});
});
Expand Down