Skip to content

build: custom tslint rules not executing in IDEs #6817

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 1 commit into from
Sep 6, 2017
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
15 changes: 2 additions & 13 deletions tools/gulp/tasks/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {red} from 'chalk';

// These types lack of type definitions
const madge = require('madge');
const resolveBin = require('resolve-bin');

/** Glob that matches all SCSS or CSS files that should be linted. */
const stylesGlob = '+(tools|src)/**/!(*.bundle).+(css|scss)';
Expand All @@ -28,10 +27,10 @@ task('stylelint', execNodeTask(
));

/** Task to run TSLint against the e2e/ and src/ directories. */
task('tslint', execTsLintTask());
task('tslint', execNodeTask('tslint', tsLintBaseFlags));

/** Task that automatically fixes TSLint warnings. */
task('tslint:fix', execTsLintTask('--fix'));
task('tslint:fix', execNodeTask('tslint', [...tsLintBaseFlags, '--fix']));

/** Task that runs madge to detect circular dependencies. */
task('madge', ['material:clean-build'], () => {
Expand All @@ -51,13 +50,3 @@ task('madge', ['material:clean-build'], () => {
function formatMadgeCircularModules(circularModules: string[][]): string {
return circularModules.map((modulePaths: string[]) => `\n - ${modulePaths.join(' > ')}`).join('');
}

/** Creates a gulp task function that will run TSLint together with ts-node. */
function execTsLintTask(...flags: string[]) {
const tslintBinPath = resolveBin.sync('tslint');
const tsNodeOptions = ['-O', '{"module": "commonjs"}'];

// TS-Node needs the module compiler option to be set to `commonjs` because the transpiled
// TypeScript files will be running inside of NodeJS.
return execNodeTask('ts-node', [...tsNodeOptions, tslintBinPath, ...tsLintBaseFlags, ...flags]);
}
6 changes: 3 additions & 3 deletions tools/tslint-rules/noViewEncapsulationRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ class Walker extends Lint.RuleWalker {
this._enabled = fileGlobs.some(p => minimatch(relativeFilePath, p));
}

visitClassDeclaration(node) {
visitClassDeclaration(node: ts.ClassDeclaration) {
if (!this._enabled || !node.decorators) {
return;
}

node.decorators
.map(decorator => decorator.expression)
.map(decorator => decorator.expression as any)
.filter(expression => expression.expression.getText() === 'Component')
.filter(expression => expression.arguments.length && expression.arguments[0].properties)
.forEach(expression => {
const hasTurnedOffEncapsulation = expression.arguments[0].properties.some(prop => {
const hasTurnedOffEncapsulation = expression.arguments[0].properties.some((prop: any) => {
const value = prop.initializer.getText();
return prop.name.getText() === 'encapsulation' && value.endsWith('.None');
});
Expand Down
13 changes: 13 additions & 0 deletions tools/tslint-rules/tsLoaderRule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const path = require('path');
const Lint = require('tslint');

// Custom rule that registers all of the custom rules, written in TypeScript, with ts-node.
// This is necessary, because `tslint` and IDEs won't execute any rules that aren't in a .js file.
require('ts-node').register({
project: path.join(__dirname, '../gulp/tsconfig.json')
});

// Add a noop rule so tslint doesn't complain.
exports.Rule = class Rule extends Lint.Rules.AbstractRule {
apply() {}
}
2 changes: 1 addition & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"linebreak-style": [true, "LF"],

// Custom Rules

"ts-loader": true,
"no-exposed-todo": true,
"no-view-encapsulation": [
true,
Expand Down