4 * Copyright 2013 Palantir Technologies, Inc.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 Object.defineProperty(exports, "__esModule", { value: true });
19 var tslib_1 = require("tslib");
20 var tsutils_1 = require("tsutils");
21 var ts = require("typescript");
22 var Lint = require("../index");
23 var utils_1 = require("../utils");
24 var className_examples_1 = require("./code-examples/className.examples");
25 var Rule = /** @class */ (function (_super) {
26 tslib_1.__extends(Rule, _super);
28 return _super !== null && _super.apply(this, arguments) || this;
30 Rule.prototype.apply = function (sourceFile) {
31 return this.applyWithFunction(sourceFile, walk);
33 /* tslint:disable:object-literal-sort-keys */
35 ruleName: "class-name",
36 description: "Enforces PascalCased class and interface names.",
37 rationale: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n Makes it easy to differentiate classes from regular variables at a glance.\n\n JavaScript and general programming convention is to refer to classes in PascalCase.\n It's confusing to use camelCase or other conventions for class names.\n "], ["\n Makes it easy to differentiate classes from regular variables at a glance.\n\n JavaScript and general programming convention is to refer to classes in PascalCase.\n It's confusing to use camelCase or other conventions for class names.\n "]))),
38 optionsDescription: "Not configurable.",
40 optionExamples: [true],
42 typescriptOnly: false,
43 codeExamples: className_examples_1.codeExamples,
45 /* tslint:enable:object-literal-sort-keys */
46 Rule.FAILURE_STRING = "Class name must be in pascal case";
48 }(Lint.Rules.AbstractRule));
51 return ts.forEachChild(ctx.sourceFile, function cb(node) {
52 if ((tsutils_1.isClassLikeDeclaration(node) && node.name !== undefined) ||
53 tsutils_1.isInterfaceDeclaration(node)) {
54 if (!utils_1.isPascalCased(node.name.text)) {
55 ctx.addFailureAtNode(node.name, Rule.FAILURE_STRING);
58 return ts.forEachChild(node, cb);