Skip to content

Commit 6b9c936

Browse files
devversionkara
authored andcommitted
build: use minimatch for no-view-encapsulation rule (#6621)
1 parent f104101 commit 6b9c936

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

tools/tslint-rules/noViewEncapsulationRule.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
const Lint = require('tslint');
2+
const path = require('path');
3+
const minimatch = require('minimatch');
4+
25
const ERROR_MESSAGE = 'Components must turn off view encapsulation.';
36

47
// TODO(crisbeto): combine this with the OnPush rule when it gets in.
@@ -17,11 +20,14 @@ class Walker extends Lint.RuleWalker {
1720
constructor(file, options) {
1821
super(...arguments);
1922

20-
// Whitelist with regular expressions to use when determining which files to lint.
21-
const whitelist = options.ruleArguments;
23+
// Globs that are used to determine which files to lint.
24+
const fileGlobs = options.ruleArguments || [];
25+
26+
// Relative path for the current TypeScript source file.
27+
const relativeFilePath = path.relative(process.cwd(), file.fileName);
2228

2329
// Whether the file should be checked at all.
24-
this._enabled = !whitelist.length || whitelist.some(p => new RegExp(p).test(file.fileName));
30+
this._enabled = fileGlobs.some(p => minimatch(relativeFilePath, p));
2531
}
2632

2733
visitClassDeclaration(node) {

tslint.json

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,9 @@
2727
"no-shadowed-variable": true,
2828
"no-unused-expression": true,
2929
"no-var-keyword": true,
30-
"no-exposed-todo": true,
3130
"member-access": [true, "no-public"],
3231
"no-debugger": true,
3332
"no-unused-variable": [true, {"ignore-pattern": "^_"}],
34-
"no-rxjs-patch-imports": [
35-
true,
36-
"src/+(lib|cdk)/**/*.ts"
37-
],
38-
"missing-rollup-globals": [
39-
true,
40-
"./tools/package-tools/rollup-globals.ts",
41-
"src/+(lib|cdk|material-examples)/**/*.ts"
42-
],
4333
"one-line": [
4434
true,
4535
"check-catch",
@@ -79,10 +69,6 @@
7969
"check-type",
8070
"check-preblock"
8171
],
82-
"no-view-encapsulation": [
83-
true,
84-
"(lib|cdk)\/((?!spec.ts).)*.ts$"
85-
],
8672
// Bans jasmine helper functions that will prevent the CI from properly running tests.
8773
"ban": [
8874
true,
@@ -97,6 +83,26 @@
9783
"import-blacklist": [true, "rxjs"],
9884
// Avoids inconsistent linebreak styles in source files. Forces developers to use LF linebreaks.
9985
"linebreak-style": [true, "LF"],
100-
"require-license-banner": [true, "src/+(lib|cdk)/**/!(*.spec).ts"]
86+
87+
// Custom Rules
88+
89+
"no-exposed-todo": true,
90+
"no-view-encapsulation": [
91+
true,
92+
"src/+(lib|cdk)/**/!(*.spec).ts"
93+
],
94+
"require-license-banner": [
95+
true,
96+
"src/+(lib|cdk)/**/!(*.spec).ts"
97+
],
98+
"no-rxjs-patch-imports": [
99+
true,
100+
"src/+(lib|cdk)/**/*.ts"
101+
],
102+
"missing-rollup-globals": [
103+
true,
104+
"./tools/package-tools/rollup-globals.ts",
105+
"src/+(lib|cdk|material-examples)/**/*.ts"
106+
]
101107
}
102108
}

0 commit comments

Comments
 (0)