build: add tslint rule for consistent file name casing (#14536)

Adds a tslint rule to enforce that the casing on our filenames is consistent. The tslint rule files are excluded, because their names have to be in camel case and end with `Rule`.
This commit is contained in:
Kristiyan Kostadinov
2018-12-18 05:15:24 +01:00
committed by Jeremy Elbourn
parent d304b41a0e
commit 9e05af3aa4
13 changed files with 64 additions and 10 deletions
+2 -2
View File
@@ -5,7 +5,7 @@ load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")
ts_library(
name = "sass_bundle_lib",
srcs = ["sass_bundle.ts"],
srcs = ["sass-bundle.ts"],
deps = [
"@matdeps//@types/node",
"@matdeps//scss-bundle",
@@ -21,5 +21,5 @@ nodejs_binary(
"@matdeps//source-map-support",
":sass_bundle_lib",
],
entry_point = "angular_material/tools/sass_bundle.js",
entry_point = "angular_material/tools/sass-bundle.js",
)
+1 -1
View File
@@ -1,5 +1,5 @@
import {task} from 'gulp';
import {execNodeTask} from '../util/task_helpers';
import {execNodeTask} from '../util/task-helpers';
import {join} from 'path';
import {buildConfig, sequenceTask} from 'material2-build-tools';
+1 -1
View File
@@ -1,5 +1,5 @@
import {task} from 'gulp';
import {cleanTask} from '../util/task_helpers';
import {cleanTask} from '../util/task-helpers';
import {buildConfig} from 'material2-build-tools';
+1 -1
View File
@@ -1,5 +1,5 @@
import {task, dest} from 'gulp';
import {tsBuildTask, copyTask, serverTask} from '../util/task_helpers';
import {tsBuildTask, copyTask, serverTask} from '../util/task-helpers';
import {join} from 'path';
import {
buildConfig,
+1 -1
View File
@@ -7,7 +7,7 @@ import {
getActiveBrowserSyncInstance,
ngcBuildTask,
serverTask
} from '../util/task_helpers';
} from '../util/task-helpers';
const {outputDir, packagesDir, projectDir} = buildConfig;
+1 -1
View File
@@ -3,7 +3,7 @@ import {readdirSync, readFileSync, statSync} from 'fs';
import {task} from 'gulp';
import {IMinimatch, Minimatch} from 'minimatch';
import {join} from 'path';
import {execNodeTask} from '../util/task_helpers';
import {execNodeTask} from '../util/task-helpers';
/** Glob that matches all SCSS or CSS files that should be linted. */
const styleGlob = 'src/**/*.+(css|scss)';
+1 -1
View File
@@ -5,7 +5,7 @@ import {task} from 'gulp';
import {buildConfig, sequenceTask} from 'material2-build-tools';
import * as minimist from 'minimist';
import {join} from 'path';
import {execTask} from '../../util/task_helpers';
import {execTask} from '../../util/task-helpers';
/** Packages that will be published to NPM by the release task. */
export const releasePackages = [
+1 -1
View File
@@ -1,5 +1,5 @@
import {dest, task} from 'gulp';
import {ngcBuildTask, tsBuildTask, copyTask, execTask} from '../util/task_helpers';
import {ngcBuildTask, tsBuildTask, copyTask, execTask} from '../util/task-helpers';
import {join} from 'path';
import {copySync} from 'fs-extra';
import {buildConfig, buildScssPipeline, sequenceTask} from 'material2-build-tools';
+1 -1
View File
@@ -1,5 +1,5 @@
import {watchFiles} from 'material2-build-tools';
import {getActiveBrowserSyncInstance} from './task_helpers';
import {getActiveBrowserSyncInstance} from './task-helpers';
/**
* Function that watches a set of file globs and runs the specified tasks if a file
@@ -0,0 +1,49 @@
import * as path from 'path';
import * as ts from 'typescript';
import * as Lint from 'tslint';
import * as minimatch from 'minimatch';
/**
* Rule that enforces consistent file name casing across files. This a simplified version of the
* `file-casing-rule` from tslint which adds the ability to ignore certain files.
* TODO(crisbeto): we may be able to replace this rule with once the following changes are released:
* https://github.com/palantir/tslint/pull/4206
*/
export class Rule extends Lint.Rules.AbstractRule {
apply(sourceFile: ts.SourceFile) {
return this.applyWithWalker(new Walker(sourceFile, this.getOptions()));
}
}
class Walker extends Lint.RuleWalker {
/** Whether the current file should be checked. */
private _enabled: boolean;
constructor(sourceFile: ts.SourceFile, options: Lint.IOptions) {
super(sourceFile, options);
const ignorePattern = options.ruleArguments;
const relativeFilePath = path.relative(process.cwd(), sourceFile.fileName);
this._enabled = ignorePattern.every(p => !minimatch(relativeFilePath, p));
}
visitSourceFile(sourceFile: ts.SourceFile) {
if (!this._enabled) {
return;
}
const fileName = path.basename(sourceFile.fileName);
for (let i = 0; i < fileName.length; i++) {
const character = fileName[i];
// Ensure that the current character is an allowed separator and is in lower case.
if (character === '_' || character !== character.toLowerCase()) {
this.addFailureAt(0, 0, 'File name must be in kebab-case.');
}
}
super.visitSourceFile(sourceFile);
}
}
+5
View File
@@ -129,6 +129,11 @@
"./tools/package-tools/rollup-globals.ts",
"src/+(lib|cdk|material-examples|material-experimental|cdk-experimental)/!(schematics)**/*.ts"
],
"file-name-casing-scoped": [
true,
// Exclude lint rule files since they have to always be camel cased and end with `Rule`.
"**/*Rule.ts"
],
"no-unescaped-html-tag": true
},
"linterOptions": {