New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@fimbul/valtyr

Package Overview
Dependencies
Maintainers
2
Versions
175
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fimbul/valtyr - npm Package Compare versions

Comparing version 0.22.0-dev.20200204 to 0.22.0-dev.20201207

9

index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createModule = exports.TslintConfigurationProvider = exports.TslintLineSwitchParser = exports.TslintRuleLoaderHost = exports.TslintFormatterLoaderHost = void 0;
const wotan_1 = require("@fimbul/wotan");
const inversify_1 = require("inversify");
const formatter_loader_1 = require("./src/formatter-loader");
exports.TslintFormatterLoaderHost = formatter_loader_1.TslintFormatterLoaderHost;
Object.defineProperty(exports, "TslintFormatterLoaderHost", { enumerable: true, get: function () { return formatter_loader_1.TslintFormatterLoaderHost; } });
const rule_loader_1 = require("./src/rule-loader");
exports.TslintRuleLoaderHost = rule_loader_1.TslintRuleLoaderHost;
Object.defineProperty(exports, "TslintRuleLoaderHost", { enumerable: true, get: function () { return rule_loader_1.TslintRuleLoaderHost; } });
const line_switches_1 = require("./src/line-switches");
exports.TslintLineSwitchParser = line_switches_1.TslintLineSwitchParser;
Object.defineProperty(exports, "TslintLineSwitchParser", { enumerable: true, get: function () { return line_switches_1.TslintLineSwitchParser; } });
const configuration_provider_1 = require("./src/configuration-provider");
exports.TslintConfigurationProvider = configuration_provider_1.TslintConfigurationProvider;
Object.defineProperty(exports, "TslintConfigurationProvider", { enumerable: true, get: function () { return configuration_provider_1.TslintConfigurationProvider; } });
function createModule() {

@@ -14,0 +15,0 @@ return new inversify_1.ContainerModule((bind) => {

{
"name": "@fimbul/valtyr",
"version": "0.22.0-dev.20200204",
"version": "0.22.0-dev.20201207",
"description": "Wotan plugin to behave almost like TSLint",

@@ -34,3 +34,3 @@ "author": "Klaus Meinhardt",

"peerDependencies": {
"@fimbul/wotan": "0.22.0-dev.20200204",
"@fimbul/wotan": "0.22.0-dev.20201207",
"typescript": ">= 3.3.0 || >= 3.6.0-dev || >= 3.7.0-dev"

@@ -37,0 +37,0 @@ },

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TslintConfigurationProvider = void 0;
const tslib_1 = require("tslib");

@@ -16,109 +17,112 @@ const inversify_1 = require("inversify");

const OFFSET_TO_NODE_MODULES = 3;
let TslintConfigurationProvider = class TslintConfigurationProvider {
constructor(resolver, fs, cacheFactory, builtinResolver, directories, options) {
this.resolver = resolver;
this.fs = fs;
this.cacheFactory = cacheFactory;
this.builtinResolver = builtinResolver;
this.directories = directories;
this.options = options;
this.tslintConfigDir = undefined;
this.baseConfig = undefined;
this.cache = cacheFactory.create();
}
find(fileName) {
fileName = path.dirname(fileName);
let result = this.cache.get(fileName);
if (result === undefined && !this.cache.has(fileName)) {
result = TSLint.Configuration.findConfigurationPath(null, fileName); // tslint:disable-line:no-null-keyword
const { root } = path.parse(fileName);
// prevent infinite loop when result is on different drive
const configDirname = result === undefined || root !== path.parse(result).root ? root : path.dirname(result);
this.cache.set(fileName, result);
while (fileName !== configDirname) {
let TslintConfigurationProvider = /** @class */ (() => {
let TslintConfigurationProvider = class TslintConfigurationProvider {
constructor(resolver, fs, cacheFactory, builtinResolver, directories, options) {
this.resolver = resolver;
this.fs = fs;
this.cacheFactory = cacheFactory;
this.builtinResolver = builtinResolver;
this.directories = directories;
this.options = options;
this.tslintConfigDir = undefined;
this.baseConfig = undefined;
this.cache = cacheFactory.create();
}
find(fileName) {
fileName = path.dirname(fileName);
let result = this.cache.get(fileName);
if (result === undefined && !this.cache.has(fileName)) {
result = TSLint.Configuration.findConfigurationPath(null, fileName); // tslint:disable-line:no-null-keyword
const { root } = path.parse(fileName);
// prevent infinite loop when result is on different drive
const configDirname = result === undefined || root !== path.parse(result).root ? root : path.dirname(result);
this.cache.set(fileName, result);
fileName = path.dirname(fileName);
while (fileName !== configDirname) {
this.cache.set(fileName, result);
fileName = path.dirname(fileName);
}
}
return result;
}
return result;
}
resolve(name, basedir) {
const extensions = [...this.resolver.getDefaultExtensions(), '.json'];
if (name.startsWith('tslint:')) {
try {
if (this.tslintConfigDir === undefined)
this.tslintConfigDir = path.join(this.resolver.resolve('tslint', path.dirname(__dirname), extensions), '../configs');
return this.resolver.resolve(path.join(this.tslintConfigDir, name.substr('tslint:'.length)), '', extensions);
resolve(name, basedir) {
const extensions = [...this.resolver.getDefaultExtensions(), '.json'];
if (name.startsWith('tslint:')) {
try {
if (this.tslintConfigDir === undefined)
this.tslintConfigDir = path.join(this.resolver.resolve('tslint', path.dirname(__dirname), extensions), '../configs');
return this.resolver.resolve(path.join(this.tslintConfigDir, name.substr('tslint:'.length)), '', extensions);
}
catch {
throw new Error(`'${name}' is not a valid builtin configuration, try 'tslint:recommended.'`);
}
}
catch {
throw new Error(`'${name}' is not a valid builtin configuration, try 'tslint:recommended.'`);
}
return this.resolver.resolve(name, basedir, extensions, module.paths.slice(OFFSET_TO_NODE_MODULES));
}
return this.resolver.resolve(name, basedir, extensions, module.paths.slice(OFFSET_TO_NODE_MODULES));
}
load(filename) {
return this.parse(TSLint.Configuration.loadConfigurationFromPath(filename), filename);
}
parse(raw, filename) {
const rulesDirectories = raw.rulesDirectory.length === 0 ? undefined : raw.rulesDirectory;
const overrides = [];
if (raw.rules.size !== 0)
overrides.push({
files: ['*', '!*.js?(x)'],
rules: new Map(Array.from(raw.rules, mapRules)),
});
if (raw.jsRules.size !== 0)
overrides.push({
files: ['*.js?(x)'],
rules: new Map(Array.from(raw.jsRules, mapRules)),
});
return {
overrides,
filename,
extends: this.getBaseConfiguration(),
exclude: raw.linterOptions && raw.linterOptions.exclude && mapExcludes(raw.linterOptions.exclude, path.dirname(filename)),
};
function mapRules([rule, config]) {
return [
rule,
{
load(filename) {
return this.parse(TSLint.Configuration.loadConfigurationFromPath(filename), filename);
}
parse(raw, filename) {
const rulesDirectories = raw.rulesDirectory.length === 0 ? undefined : raw.rulesDirectory;
const overrides = [];
if (raw.rules.size !== 0)
overrides.push({
files: ['*', '!*.js?(x)'],
rules: new Map(Array.from(raw.rules, mapRules)),
});
if (raw.jsRules.size !== 0)
overrides.push({
files: ['*.js?(x)'],
rules: new Map(Array.from(raw.jsRules, mapRules)),
});
return {
overrides,
filename,
extends: this.getBaseConfiguration(),
exclude: raw.linterOptions && raw.linterOptions.exclude && mapExcludes(raw.linterOptions.exclude, path.dirname(filename)),
};
function mapRules([rule, config]) {
return [
rule,
rulesDirectories,
severity: config.ruleSeverity,
options: config.ruleArguments,
},
];
{
rule,
rulesDirectories,
severity: config.ruleSeverity,
options: config.ruleArguments,
},
];
}
}
}
getBaseConfiguration() {
if (this.baseConfig !== undefined)
return this.baseConfig;
if (!this.options.valtyr)
return this.baseConfig = [];
try {
const fullPath = path.join(this.directories.getCurrentDirectory(), '.fimbullinter.yaml');
const configProvider = new wotan_1.DefaultConfigurationProvider(this.fs, this.resolver, this.builtinResolver, this.cacheFactory);
const config = configProvider.parse(this.options.valtyr, fullPath, {
stack: [],
load() {
throw new Error('Global configuration is not allowed to extend other configs.');
},
});
validateGlobalConfig(config);
return this.baseConfig = [config];
getBaseConfiguration() {
if (this.baseConfig !== undefined)
return this.baseConfig;
if (!this.options.valtyr)
return this.baseConfig = [];
try {
const fullPath = path.join(this.directories.getCurrentDirectory(), '.fimbullinter.yaml');
const configProvider = new wotan_1.DefaultConfigurationProvider(this.fs, this.resolver, this.builtinResolver, this.cacheFactory);
const config = configProvider.parse(this.options.valtyr, fullPath, {
stack: [],
load() {
throw new Error('Global configuration is not allowed to extend other configs.');
},
});
validateGlobalConfig(config);
return this.baseConfig = [config];
}
catch (e) {
throw new wotan_1.ConfigurationError(`Error parsing global configuration for 'valtyr': ${e.message}`);
}
}
catch (e) {
throw new wotan_1.ConfigurationError(`Error parsing global configuration for 'valtyr': ${e.message}`);
}
}
};
TslintConfigurationProvider = tslib_1.__decorate([
inversify_1.injectable(),
tslib_1.__metadata("design:paramtypes", [wotan_1.Resolver,
wotan_1.CachedFileSystem,
wotan_1.CacheFactory,
wotan_1.BuiltinResolver,
wotan_1.DirectoryService,
wotan_1.GlobalOptions])
], TslintConfigurationProvider);
};
TslintConfigurationProvider = tslib_1.__decorate([
inversify_1.injectable(),
tslib_1.__metadata("design:paramtypes", [wotan_1.Resolver,
wotan_1.CachedFileSystem,
wotan_1.CacheFactory,
wotan_1.BuiltinResolver,
wotan_1.DirectoryService,
wotan_1.GlobalOptions])
], TslintConfigurationProvider);
return TslintConfigurationProvider;
})();
exports.TslintConfigurationProvider = TslintConfigurationProvider;

@@ -125,0 +129,0 @@ function mapExcludes(excludes, configDir) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TslintFormatterLoaderHost = void 0;
const tslib_1 = require("tslib");

@@ -7,11 +8,14 @@ const inversify_1 = require("inversify");

const bifrost_1 = require("@fimbul/bifrost");
let TslintFormatterLoaderHost = class TslintFormatterLoaderHost {
constructor() {
this.loadCoreFormatter = loadFormatter;
this.loadCustomFormatter = loadFormatter;
}
};
TslintFormatterLoaderHost = tslib_1.__decorate([
inversify_1.injectable()
], TslintFormatterLoaderHost);
let TslintFormatterLoaderHost = /** @class */ (() => {
let TslintFormatterLoaderHost = class TslintFormatterLoaderHost {
constructor() {
this.loadCoreFormatter = loadFormatter;
this.loadCustomFormatter = loadFormatter;
}
};
TslintFormatterLoaderHost = tslib_1.__decorate([
inversify_1.injectable()
], TslintFormatterLoaderHost);
return TslintFormatterLoaderHost;
})();
exports.TslintFormatterLoaderHost = TslintFormatterLoaderHost;

@@ -18,0 +22,0 @@ function loadFormatter(name) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TslintLineSwitchParser = void 0;
const tslib_1 = require("tslib");

@@ -8,48 +9,26 @@ const inversify_1 = require("inversify");

const matchAll = /^/;
let TslintLineSwitchParser = class TslintLineSwitchParser {
parse({ sourceFile }) {
const result = [];
const re = /\/[/*]\s*tslint:(enable|disable)(-line|-next-line)?(:)?/gm;
for (let match = re.exec(sourceFile.text); match !== null; match = re.exec(sourceFile.text)) {
// not using `context.getCommentAtPosition` here is intentional, because it doesn't benefit from caching the converted AST
const comment = tsutils_1.getCommentAtPosition(sourceFile, match.index);
if (comment === undefined || comment.pos !== match.index)
continue;
const ruleNames = sourceFile.text.substring(comment.pos + match[0].length, comment.kind === ts.SyntaxKind.SingleLineCommentTrivia ? comment.end : { pos: comment.pos, end: comment.end }.end - 2);
let rules;
if (/\S/.test(ruleNames)) {
rules = parseRules(ruleNames, comment.pos + match[0].length);
}
else {
rules = match[3] === ':' ? [] : [{ predicate: matchAll }];
}
const enable = match[1] === 'enable';
switch (match[2]) {
case '-line': {
const lineStarts = sourceFile.getLineStarts();
const { line } = ts.getLineAndCharacterOfPosition(sourceFile, comment.pos);
result.push({
rules,
enable,
pos: lineStarts[line],
// no need to switch back if there is no next line
end: lineStarts.length === line + 1 ? undefined : lineStarts[line + 1],
location: { pos: comment.pos, end: comment.end },
});
break;
let TslintLineSwitchParser = /** @class */ (() => {
let TslintLineSwitchParser = class TslintLineSwitchParser {
parse({ sourceFile }) {
const result = [];
const re = /\/[/*]\s*tslint:(enable|disable)(-line|-next-line)?(:)?/gm;
for (let match = re.exec(sourceFile.text); match !== null; match = re.exec(sourceFile.text)) {
// not using `context.getCommentAtPosition` here is intentional, because it doesn't benefit from caching the converted AST
const comment = tsutils_1.getCommentAtPosition(sourceFile, match.index);
if (comment === undefined || comment.pos !== match.index)
continue;
const ruleNames = sourceFile.text.substring(comment.pos + match[0].length, comment.kind === ts.SyntaxKind.SingleLineCommentTrivia ? comment.end : { pos: comment.pos, end: comment.end }.end - 2);
let rules;
if (/\S/.test(ruleNames)) {
rules = parseRules(ruleNames, comment.pos + match[0].length);
}
case '-next-line': {
const lineStarts = sourceFile.getLineStarts();
const line = ts.getLineAndCharacterOfPosition(sourceFile, comment.pos).line + 1;
if (lineStarts.length === line) {
// there is no next line, return an out-of-range switch that can be reported
else {
rules = match[3] === ':' ? [] : [{ predicate: matchAll }];
}
const enable = match[1] === 'enable';
switch (match[2]) {
case '-line': {
const lineStarts = sourceFile.getLineStarts();
const { line } = ts.getLineAndCharacterOfPosition(sourceFile, comment.pos);
result.push({
rules, enable,
pos: sourceFile.end + 1,
end: undefined,
location: { pos: comment.pos, end: comment.end },
});
}
else {
result.push({
rules,

@@ -62,15 +41,40 @@ enable,

});
break;
}
break;
case '-next-line': {
const lineStarts = sourceFile.getLineStarts();
const line = ts.getLineAndCharacterOfPosition(sourceFile, comment.pos).line + 1;
if (lineStarts.length === line) {
// there is no next line, return an out-of-range switch that can be reported
result.push({
rules, enable,
pos: sourceFile.end + 1,
end: undefined,
location: { pos: comment.pos, end: comment.end },
});
}
else {
result.push({
rules,
enable,
pos: lineStarts[line],
// no need to switch back if there is no next line
end: lineStarts.length === line + 1 ? undefined : lineStarts[line + 1],
location: { pos: comment.pos, end: comment.end },
});
}
break;
}
default:
result.push({ rules, enable, pos: comment.pos, end: undefined, location: { pos: comment.pos, end: comment.end } });
}
default:
result.push({ rules, enable, pos: comment.pos, end: undefined, location: { pos: comment.pos, end: comment.end } });
}
return result;
}
return result;
}
};
TslintLineSwitchParser = tslib_1.__decorate([
inversify_1.injectable()
], TslintLineSwitchParser);
};
TslintLineSwitchParser = tslib_1.__decorate([
inversify_1.injectable()
], TslintLineSwitchParser);
return TslintLineSwitchParser;
})();
exports.TslintLineSwitchParser = TslintLineSwitchParser;

@@ -77,0 +81,0 @@ function parseRules(raw, offset) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TslintRuleLoaderHost = void 0;
const tslib_1 = require("tslib");

@@ -7,16 +8,19 @@ const inversify_1 = require("inversify");

const bifrost_1 = require("@fimbul/bifrost");
let TslintRuleLoaderHost = class TslintRuleLoaderHost {
loadCoreRule(name) {
const rule = TSLint.findRule(name);
return rule === undefined ? undefined : bifrost_1.wrapTslintRule(rule, name);
}
loadCustomRule(name, dir) {
const rule = TSLint.findRule(name, dir);
return rule === undefined ? undefined : bifrost_1.wrapTslintRule(rule, name);
}
};
TslintRuleLoaderHost = tslib_1.__decorate([
inversify_1.injectable()
], TslintRuleLoaderHost);
let TslintRuleLoaderHost = /** @class */ (() => {
let TslintRuleLoaderHost = class TslintRuleLoaderHost {
loadCoreRule(name) {
const rule = TSLint.findRule(name);
return rule === undefined ? undefined : bifrost_1.wrapTslintRule(rule, name);
}
loadCustomRule(name, dir) {
const rule = TSLint.findRule(name, dir);
return rule === undefined ? undefined : bifrost_1.wrapTslintRule(rule, name);
}
};
TslintRuleLoaderHost = tslib_1.__decorate([
inversify_1.injectable()
], TslintRuleLoaderHost);
return TslintRuleLoaderHost;
})();
exports.TslintRuleLoaderHost = TslintRuleLoaderHost;
//# sourceMappingURL=rule-loader.js.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc