Skip to content

Commit 2c85850

Browse files
alan-agius4hansl
authored andcommitted
fix(@angular-devkit/build-angular): tslint exclude for relative paths
Closes #11773
1 parent 718ee15 commit 2c85850

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

packages/angular_devkit/build_angular/src/tslint/index.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,12 @@ function getFilesToLint(
201201
let programFiles = linter.getFileNames(program);
202202

203203
if (ignore && ignore.length > 0) {
204-
const ignoreMatchers = ignore.map(pattern => new Minimatch(pattern, { dot: true }));
204+
// normalize to support ./ paths
205+
const ignoreMatchers = ignore
206+
.map(pattern => new Minimatch(path.normalize(pattern), { dot: true }));
205207

206208
programFiles = programFiles
207-
.filter(file => !ignoreMatchers.some(matcher => matcher.match(file)));
209+
.filter(file => !ignoreMatchers.some(matcher => matcher.match(path.relative(root, file))));
208210
}
209211

210212
return programFiles;

packages/angular_devkit/build_angular/test/tslint/works_spec_large.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('Tslint Target', () => {
4141
).toPromise().then(done, done.fail);
4242
}, 30000);
4343

44-
it('supports exclude', (done) => {
44+
it('supports exclude with glob', (done) => {
4545
host.writeMultipleFiles(filesWithErrors);
4646
const overrides: Partial<TslintBuilderOptions> = { exclude: ['**/foo.ts'] };
4747

@@ -50,6 +50,24 @@ describe('Tslint Target', () => {
5050
).toPromise().then(done, done.fail);
5151
}, 30000);
5252

53+
it('supports exclude with relative paths', (done) => {
54+
host.writeMultipleFiles(filesWithErrors);
55+
const overrides: Partial<TslintBuilderOptions> = { exclude: ['src/foo.ts'] };
56+
57+
runTargetSpec(host, tslintTargetSpec, overrides).pipe(
58+
tap((buildEvent) => expect(buildEvent.success).toBe(true)),
59+
).toPromise().then(done, done.fail);
60+
}, 30000);
61+
62+
it(`supports exclude with paths starting with './'`, (done) => {
63+
host.writeMultipleFiles(filesWithErrors);
64+
const overrides: Partial<TslintBuilderOptions> = { exclude: ['./src/foo.ts'] };
65+
66+
runTargetSpec(host, tslintTargetSpec, overrides).pipe(
67+
tap((buildEvent) => expect(buildEvent.success).toBe(true)),
68+
).toPromise().then(done, done.fail);
69+
}, 30000);
70+
5371
it('supports fix', (done) => {
5472
host.writeMultipleFiles(filesWithErrors);
5573
const overrides: Partial<TslintBuilderOptions> = { fix: true };

0 commit comments

Comments
 (0)