Skip to content

Commit

Permalink
added support for external formatter module
Browse files Browse the repository at this point in the history
formatter name can be any resolvable (npm) module name or path as used by require()
fixed formatterLoader.ts and ruleLoader.ts CORE folders
* made relative to module.filename (instead of implied working directory)
* resolves rules and formatters correctly when tslint is used by dependents (grunt-tshint etc)
* requires to compile tests to ./build (instead of ./build/test, as module.path is the compiled JS file)
added .gitattributes for fixture line-endings
  • Loading branch information
Bartvds committed Oct 9, 2013
1 parent 4d02f00 commit 092d083
Show file tree
Hide file tree
Showing 10 changed files with 266 additions and 150 deletions.
6 changes: 3 additions & 3 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ module.exports = function(grunt) {
options: {
reporter: 'spec'
},
src: ['build/test/**/*.js']
},
src: ['build/*-tests.js']
}
},

tslint: {
Expand Down Expand Up @@ -78,7 +78,7 @@ module.exports = function(grunt) {
target: 'es5'
},
src: ['test/**/*.ts', '!test/files/**/*.ts'],
dest: 'build/test/tslint-tests.js'
dest: 'build/tslint-tests.js'
}
}
});
Expand Down
23 changes: 14 additions & 9 deletions bin/tslint-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -26542,9 +26542,9 @@ var Lint;
var fs = require("fs");
var path = require("path");
var _s = require("underscore.string");
var moduleDirectory = path.dirname(module.filename);

var CORE_RULES_DIRECTORY = path.join("..", "build", "rules");
var moduleDirectory = path.dirname(module.filename);
var CORE_RULES_DIRECTORY = path.resolve(moduleDirectory, "..", "build", "rules");

function loadRules(ruleConfiguration, rulesDirectory) {
var rules = [];
Expand Down Expand Up @@ -26662,8 +26662,7 @@ var Lint;
var _s = require("underscore.string");

var moduleDirectory = path.dirname(module.filename);

var CORE_FORMATTERS_DIRECTORY = path.join("..", "build", "formatters");
var CORE_FORMATTERS_DIRECTORY = path.resolve(moduleDirectory, "..", "build", "formatters");

function findFormatter(name, formattersDirectory) {
var camelizedName = _s.camelize(name + "Formatter");
Expand All @@ -26680,7 +26679,7 @@ var Lint;
}
}

return undefined;
return loadFormatterModule(name);
}
Lint.findFormatter = findFormatter;

Expand All @@ -26701,6 +26700,16 @@ var Lint;

return undefined;
}

function loadFormatterModule(name) {
var src;
try {
src = require.resolve(name);
} catch (e) {
return undefined;
}
return require(src).Formatter;
}
})(Lint || (Lint = {}));
var TypeScript;
(function (TypeScript) {
Expand Down Expand Up @@ -55662,7 +55671,6 @@ var TypeScript;
FormattingRequestKind[FormattingRequestKind["FormatOnEnter"] = 2] = "FormatOnEnter";
FormattingRequestKind[FormattingRequestKind["FormatOnSemicolon"] = 3] = "FormatOnSemicolon";
FormattingRequestKind[FormattingRequestKind["FormatOnClosingCurlyBrace"] = 4] = "FormatOnClosingCurlyBrace";

FormattingRequestKind[FormattingRequestKind["FormatOnPaste"] = 5] = "FormatOnPaste";
})(Formatting.FormattingRequestKind || (Formatting.FormattingRequestKind = {}));
var FormattingRequestKind = Formatting.FormattingRequestKind;
Expand Down Expand Up @@ -55695,7 +55703,6 @@ var TypeScript;
RuleAction[RuleAction["Ignore"] = 0] = "Ignore";
RuleAction[RuleAction["Space"] = 1] = "Space";
RuleAction[RuleAction["NewLine"] = 2] = "NewLine";

RuleAction[RuleAction["Delete"] = 3] = "Delete";
})(Formatting.RuleAction || (Formatting.RuleAction = {}));
var RuleAction = Formatting.RuleAction;
Expand Down Expand Up @@ -55740,7 +55747,6 @@ var TypeScript;
(function (Formatting) {
(function (RuleFlags) {
RuleFlags[RuleFlags["None"] = 0] = "None";

RuleFlags[RuleFlags["CanDeleteNewLines"] = 1] = "CanDeleteNewLines";
})(Formatting.RuleFlags || (Formatting.RuleFlags = {}));
var RuleFlags = Formatting.RuleFlags;
Expand Down Expand Up @@ -56319,7 +56325,6 @@ var TypeScript;
RulesPosition[RulesPosition["ContextRulesSpecific"] = MaskBitSize * 2] = "ContextRulesSpecific";
RulesPosition[RulesPosition["ContextRulesAny"] = MaskBitSize * 3] = "ContextRulesAny";
RulesPosition[RulesPosition["NoContextRulesSpecific"] = MaskBitSize * 4] = "NoContextRulesSpecific";

RulesPosition[RulesPosition["NoContextRulesAny"] = MaskBitSize * 5] = "NoContextRulesAny";
})(Formatting.RulesPosition || (Formatting.RulesPosition = {}));
var RulesPosition = Formatting.RulesPosition;
Expand Down
Loading

0 comments on commit 092d083

Please sign in to comment.