@fimbul/wotan
Version:
Pluggable TypeScript and JavaScript linter
59 lines • 2.31 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.RuleLoader = void 0;
const tslib_1 = require("tslib");
const inversify_1 = require("inversify");
const ymir_1 = require("@fimbul/ymir");
const debug = require("debug");
const bind_decorator_1 = require("bind-decorator");
const utils_1 = require("../utils");
const log = debug('wotan:ruleLoader');
let RuleLoader = class RuleLoader {
constructor(host, logger, cache) {
this.host = host;
this.logger = logger;
this.cache = cache.create();
}
loadRule(name, directories) {
if (directories === undefined) {
const ctor = utils_1.resolveCachedResult(this.cache, name, this.loadCoreRule);
if (ctor === undefined)
this.logger.warn(`Could not find core rule '${name}'.`);
return ctor;
}
for (const dir of directories) {
const ctor = utils_1.resolveCachedResult(this.cache, `${dir}💩${name}`, this.loadCustomRule);
if (ctor !== undefined)
return ctor;
}
this.logger.warn(`Could not find rule '${name}' in '${directories.join()}'.`);
return;
}
loadCoreRule(name) {
log('Loading core rule %s', name);
return this.host.loadCoreRule(name);
}
loadCustomRule(cacheKey) {
const [directory, name] = cacheKey.split('💩');
log('Looking for %s in directory %s', name, directory);
return this.host.loadCustomRule(name, directory);
}
};
tslib_1.__decorate([
bind_decorator_1.default,
tslib_1.__metadata("design:type", Function),
tslib_1.__metadata("design:paramtypes", [String]),
tslib_1.__metadata("design:returntype", void 0)
], RuleLoader.prototype, "loadCoreRule", null);
tslib_1.__decorate([
bind_decorator_1.default,
tslib_1.__metadata("design:type", Function),
tslib_1.__metadata("design:paramtypes", [String]),
tslib_1.__metadata("design:returntype", void 0)
], RuleLoader.prototype, "loadCustomRule", null);
RuleLoader = tslib_1.__decorate([
inversify_1.injectable(),
tslib_1.__metadata("design:paramtypes", [ymir_1.RuleLoaderHost, ymir_1.MessageHandler, ymir_1.CacheFactory])
], RuleLoader);
exports.RuleLoader = RuleLoader;
//# sourceMappingURL=rule-loader.js.map
;