1 | var __extends = (this && this.__extends) || function (d, b) {
|
2 | for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
3 | function __() { this.constructor = d; }
|
4 | __.prototype = b.prototype;
|
5 | d.prototype = new __();
|
6 | };
|
7 | var ErrorTolerantWalker = require('./utils/ErrorTolerantWalker');
|
8 | var Utils = require('./utils/Utils');
|
9 | var Rule = (function (_super) {
|
10 | __extends(Rule, _super);
|
11 | function Rule() {
|
12 | _super.apply(this, arguments);
|
13 | }
|
14 | Rule.prototype.apply = function (sourceFile) {
|
15 | return this.applyWithWalker(new ExportNameWalker(sourceFile, this.getOptions()));
|
16 | };
|
17 | Rule.getExceptions = function (options) {
|
18 | if (options.ruleArguments instanceof Array) {
|
19 | return options.ruleArguments[0];
|
20 | }
|
21 | if (options instanceof Array) {
|
22 | return options;
|
23 | }
|
24 | return null;
|
25 | };
|
26 | Rule.FAILURE_STRING = 'The exported module name must match the file name. Found: ';
|
27 | return Rule;
|
28 | })(Lint.Rules.AbstractRule);
|
29 | exports.Rule = Rule;
|
30 | var ExportNameWalker = (function (_super) {
|
31 | __extends(ExportNameWalker, _super);
|
32 | function ExportNameWalker() {
|
33 | _super.apply(this, arguments);
|
34 | }
|
35 | ExportNameWalker.prototype.visitExportAssignment = function (node) {
|
36 | var exportedName = node.expression.getText();
|
37 | var regex = new RegExp(exportedName + '\..*');
|
38 | if (!regex.test(this.getFilename())) {
|
39 | if (!this.isSuppressed(exportedName)) {
|
40 | var failureString = Rule.FAILURE_STRING + this.getSourceFile().fileName + ' and ' + exportedName;
|
41 | var failure = this.createFailure(node.expression.getStart(), node.expression.getWidth(), failureString);
|
42 | this.addFailure(failure);
|
43 | }
|
44 | }
|
45 | _super.prototype.visitExportAssignment.call(this, node);
|
46 | };
|
47 | ExportNameWalker.prototype.getFilename = function () {
|
48 | var filename = this.getSourceFile().fileName;
|
49 | var lastSlash = filename.lastIndexOf('/');
|
50 | if (lastSlash > -1) {
|
51 | return filename.substring(lastSlash + 1);
|
52 | }
|
53 | return filename;
|
54 | };
|
55 | ExportNameWalker.prototype.isSuppressed = function (exportedName) {
|
56 | var allExceptions = Rule.getExceptions(this.getOptions());
|
57 | return Utils.exists(allExceptions, function (exception) {
|
58 | return new RegExp(exception).test(exportedName);
|
59 | });
|
60 | };
|
61 | return ExportNameWalker;
|
62 | })(ErrorTolerantWalker);
|
63 |
|
\ | No newline at end of file |