aboutsummaryrefslogtreecommitdiff
path: root/node_modules/tslint/lib/ruleLoader.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/tslint/lib/ruleLoader.js')
-rw-r--r--node_modules/tslint/lib/ruleLoader.js50
1 files changed, 19 insertions, 31 deletions
diff --git a/node_modules/tslint/lib/ruleLoader.js b/node_modules/tslint/lib/ruleLoader.js
index 5afc659c8..f0da87652 100644
--- a/node_modules/tslint/lib/ruleLoader.js
+++ b/node_modules/tslint/lib/ruleLoader.js
@@ -16,13 +16,12 @@
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
+var tslib_1 = require("tslib");
var fs = require("fs");
var path = require("path");
-var configuration_1 = require("./configuration");
var error_1 = require("./error");
var utils_1 = require("./utils");
-var moduleDirectory = path.dirname(module.filename);
-var CORE_RULES_DIRECTORY = path.resolve(moduleDirectory, ".", "rules");
+var CORE_RULES_DIRECTORY = path.resolve(__dirname, "rules");
var cachedRules = new Map();
function loadRules(ruleOptionsList, rulesDirectories, isJs) {
if (isJs === void 0) { isJs = false; }
@@ -54,20 +53,21 @@ function loadRules(ruleOptionsList, rulesDirectories, isJs) {
}
}
if (notFoundRules.length > 0) {
- var warning = (_a = ["\n Could not find implementations for the following rules specified in the configuration:\n ", "\n Try upgrading TSLint and/or ensuring that you have all necessary custom rules installed.\n If TSLint was recently upgraded, you may have old rules configured which need to be cleaned up.\n "], _a.raw = ["\n Could not find implementations for the following rules specified in the configuration:\n ", "\n Try upgrading TSLint and/or ensuring that you have all necessary custom rules installed.\n If TSLint was recently upgraded, you may have old rules configured which need to be cleaned up.\n "], utils_1.dedent(_a, notFoundRules.join("\n ")));
+ var warning = utils_1.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n Could not find implementations for the following rules specified in the configuration:\n ", "\n Try upgrading TSLint and/or ensuring that you have all necessary custom rules installed.\n If TSLint was recently upgraded, you may have old rules configured which need to be cleaned up.\n "], ["\n Could not find implementations for the following rules specified in the configuration:\n ", "\n Try upgrading TSLint and/or ensuring that you have all necessary custom rules installed.\n If TSLint was recently upgraded, you may have old rules configured which need to be cleaned up.\n "])), notFoundRules.join("\n "));
error_1.showWarningOnce(warning);
}
if (notAllowedInJsRules.length > 0) {
- var warning = (_b = ["\n Following rules specified in configuration couldn't be applied to .js or .jsx files:\n ", "\n Make sure to exclude them from \"jsRules\" section of your tslint.json.\n "], _b.raw = ["\n Following rules specified in configuration couldn't be applied to .js or .jsx files:\n ", "\n Make sure to exclude them from \"jsRules\" section of your tslint.json.\n "], utils_1.dedent(_b, notAllowedInJsRules.join("\n ")));
+ var warning = utils_1.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n Following rules specified in configuration couldn't be applied to .js or .jsx files:\n ", "\n Make sure to exclude them from \"jsRules\" section of your tslint.json.\n "], ["\n Following rules specified in configuration couldn't be applied to .js or .jsx files:\n ", "\n Make sure to exclude them from \"jsRules\" section of your tslint.json.\n "])), notAllowedInJsRules.join("\n "));
error_1.showWarningOnce(warning);
}
if (rules.length === 0) {
- error_1.showWarningOnce("No valid rules have been specified");
+ var fileType = isJs ? "JavaScript" : "TypeScript";
+ error_1.showWarningOnce("No valid rules have been specified for " + fileType + " files");
}
return rules;
- var _a, _b;
}
exports.loadRules = loadRules;
+/** @internal private API */
function findRule(name, rulesDirectories) {
var camelizedName = transformName(name);
// first check for core rules
@@ -91,28 +91,15 @@ function transformName(name) {
* @param ruleName - A name of a rule in filename format. ex) "someLintRule"
*/
function loadRule(directory, ruleName) {
- var ruleFullPath = getRuleFullPath(directory, ruleName);
- if (ruleFullPath !== undefined) {
- var ruleModule = require(ruleFullPath);
- if (ruleModule !== undefined) {
- return ruleModule.Rule;
- }
- }
- return "not-found";
-}
-/**
- * Returns the full path to a rule file. Path to rules are resolved using nodes path resolution.
- * This allows developers to write custom rules in TypeScript, which then can be loaded by TS-Node.
- * @param directory - An absolute path to a directory of rules
- * @param ruleName - A name of a rule in filename format. ex) "someLintRule"
- */
-function getRuleFullPath(directory, ruleName) {
+ var ruleFullPath;
try {
- return require.resolve(path.join(directory, ruleName));
+ // Resolve using node's path resolution to allow developers to write custom rules in TypeScript which can be loaded by TS-Node
+ ruleFullPath = require.resolve(path.join(directory, ruleName));
}
- catch (e) {
- return undefined;
+ catch (_a) {
+ return "not-found";
}
+ return require(ruleFullPath).Rule;
}
function loadCachedRule(directory, ruleName, isCustomPath) {
// use cached value if available
@@ -121,15 +108,16 @@ function loadCachedRule(directory, ruleName, isCustomPath) {
if (cachedRule !== undefined) {
return cachedRule === "not-found" ? undefined : cachedRule;
}
- // get absolute path
+ // treat directory as a relative path (which needs to be resolved) if it's a custom rule directory
var absolutePath = directory;
if (isCustomPath) {
- absolutePath = configuration_1.getRelativePath(directory);
- if (absolutePath !== undefined && !fs.existsSync(absolutePath)) {
- throw new error_1.FatalError("Could not find custom rule directory: " + directory);
+ absolutePath = path.resolve(directory);
+ if (!fs.existsSync(absolutePath)) {
+ throw new error_1.FatalError("Could not find custom rule directory: " + absolutePath);
}
}
- var Rule = absolutePath === undefined ? "not-found" : loadRule(absolutePath, ruleName);
+ var Rule = loadRule(absolutePath, ruleName);
cachedRules.set(fullPath, Rule);
return Rule === "not-found" ? undefined : Rule;
}
+var templateObject_1, templateObject_2;