diff --git a/tools/BUILD.bazel b/tools/BUILD.bazel index cc4ef29f91e..be341e19671 100644 --- a/tools/BUILD.bazel +++ b/tools/BUILD.bazel @@ -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", ) diff --git a/tools/gulp/tasks/aot.ts b/tools/gulp/tasks/aot.ts index 2db1c107f7f..e3e5bd8f9d6 100644 --- a/tools/gulp/tasks/aot.ts +++ b/tools/gulp/tasks/aot.ts @@ -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'; diff --git a/tools/gulp/tasks/clean.ts b/tools/gulp/tasks/clean.ts index 842f5cc8e1b..29fceb81d9e 100644 --- a/tools/gulp/tasks/clean.ts +++ b/tools/gulp/tasks/clean.ts @@ -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'; diff --git a/tools/gulp/tasks/development.ts b/tools/gulp/tasks/development.ts index 1468644f99b..06aff1b56eb 100644 --- a/tools/gulp/tasks/development.ts +++ b/tools/gulp/tasks/development.ts @@ -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, diff --git a/tools/gulp/tasks/e2e.ts b/tools/gulp/tasks/e2e.ts index b484f32cf48..5e328fec3ba 100644 --- a/tools/gulp/tasks/e2e.ts +++ b/tools/gulp/tasks/e2e.ts @@ -7,7 +7,7 @@ import { getActiveBrowserSyncInstance, ngcBuildTask, serverTask -} from '../util/task_helpers'; +} from '../util/task-helpers'; const {outputDir, packagesDir, projectDir} = buildConfig; diff --git a/tools/gulp/tasks/lint.ts b/tools/gulp/tasks/lint.ts index c03e43194be..c8b87f27557 100644 --- a/tools/gulp/tasks/lint.ts +++ b/tools/gulp/tasks/lint.ts @@ -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)'; diff --git a/tools/gulp/tasks/publish/publish-task.ts b/tools/gulp/tasks/publish/publish-task.ts index 0e3cd1e6e1a..0e86ca36de0 100644 --- a/tools/gulp/tasks/publish/publish-task.ts +++ b/tools/gulp/tasks/publish/publish-task.ts @@ -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 = [ diff --git a/tools/gulp/tasks/universal.ts b/tools/gulp/tasks/universal.ts index c866d4383eb..43aae6405ef 100644 --- a/tools/gulp/tasks/universal.ts +++ b/tools/gulp/tasks/universal.ts @@ -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'; diff --git a/tools/gulp/util/task_helpers.ts b/tools/gulp/util/task-helpers.ts similarity index 100% rename from tools/gulp/util/task_helpers.ts rename to tools/gulp/util/task-helpers.ts diff --git a/tools/gulp/util/watch-files-reload.ts b/tools/gulp/util/watch-files-reload.ts index b60bfde5437..e7f82856d51 100644 --- a/tools/gulp/util/watch-files-reload.ts +++ b/tools/gulp/util/watch-files-reload.ts @@ -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 diff --git a/tools/sass_bundle.ts b/tools/sass-bundle.ts similarity index 100% rename from tools/sass_bundle.ts rename to tools/sass-bundle.ts diff --git a/tools/tslint-rules/fileNameCasingScopedRule.ts b/tools/tslint-rules/fileNameCasingScopedRule.ts new file mode 100644 index 00000000000..06ff4177636 --- /dev/null +++ b/tools/tslint-rules/fileNameCasingScopedRule.ts @@ -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); + } +} diff --git a/tslint.json b/tslint.json index 1bd198990d5..8eb7456ca0d 100644 --- a/tslint.json +++ b/tslint.json @@ -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": {