Skip to content

build: use minimatch for no-view-encapsulation rule #6621

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

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions tools/tslint-rules/noViewEncapsulationRule.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const Lint = require('tslint');
const path = require('path');
const minimatch = require('minimatch');

const ERROR_MESSAGE = 'Components must turn off view encapsulation.';

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

// Whitelist with regular expressions to use when determining which files to lint.
const whitelist = options.ruleArguments;
// Globs that are used to determine which files to lint.
const fileGlobs = options.ruleArguments || [];

// Relative path for the current TypeScript source file.
const relativeFilePath = path.relative(process.cwd(), file.fileName);

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

visitClassDeclaration(node) {
Expand Down
36 changes: 21 additions & 15 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,9 @@
"no-shadowed-variable": true,
"no-unused-expression": true,
"no-var-keyword": true,
"no-exposed-todo": true,
"member-access": [true, "no-public"],
"no-debugger": true,
"no-unused-variable": [true, {"ignore-pattern": "^_"}],
"no-rxjs-patch-imports": [
true,
"src/+(lib|cdk)/**/*.ts"
],
"missing-rollup-globals": [
true,
"./tools/package-tools/rollup-globals.ts",
"src/+(lib|cdk|material-examples)/**/*.ts"
],
"one-line": [
true,
"check-catch",
Expand Down Expand Up @@ -79,10 +69,6 @@
"check-type",
"check-preblock"
],
"no-view-encapsulation": [
true,
"(lib|cdk)\/((?!spec.ts).)*.ts$"
],
// Bans jasmine helper functions that will prevent the CI from properly running tests.
"ban": [
true,
Expand All @@ -97,6 +83,26 @@
"import-blacklist": [true, "rxjs"],
// Avoids inconsistent linebreak styles in source files. Forces developers to use LF linebreaks.
"linebreak-style": [true, "LF"],
"require-license-banner": [true, "src/+(lib|cdk)/**/!(*.spec).ts"]

// Custom Rules

"no-exposed-todo": true,
"no-view-encapsulation": [
true,
"src/+(lib|cdk)/**/!(*.spec).ts"
],
"require-license-banner": [
true,
"src/+(lib|cdk)/**/!(*.spec).ts"
],
"no-rxjs-patch-imports": [
true,
"src/+(lib|cdk)/**/*.ts"
],
"missing-rollup-globals": [
true,
"./tools/package-tools/rollup-globals.ts",
"src/+(lib|cdk|material-examples)/**/*.ts"
]
}
}