Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.option('-o, --override-config ', 'Override single config item', (opt, opts) => {
if (typeof(opts) === 'undefined') {
opts = [];
}
const [path, val] = opt.split('=');
if (typeof(path) === 'undefined' || typeof(val) === 'undefined') {
// tslint:disable-next-line
console.warn('Invalid format for invalid config. Correct is -> jsonpath=value');
return opts;
}
try {
jp.parse(path);
} catch (e) {
// tslint:disable-next-line
console.warn('JSONPath is invalid', e);
}
opts.push({ path, val });
return opts;
})
.parse(process.argv);
(opt, opts) => {
if (typeof opts === 'undefined') {
opts = [];
}
const [path, val] = opt.split('=');
if (typeof path === 'undefined' || typeof val === 'undefined') {
// tslint:disable-next-line
console.warn(
'Invalid format for invalid config. Correct is -> jsonpath=value'
);
return opts;
}
try {
jp.parse(path);
} catch (e) {
// tslint:disable-next-line
console.warn('JSONPath is invalid', e);
}
opts.push({ path, val });
return opts;
}
);
function isDefinitePath(path) {
if (CACHE.has(path)) {
return CACHE.get(path);
}
const parsed = JSONPath.parse(path);
const result = !parsed.find(({ expression: { type }, scope }) => {
// http://goessner.net/articles/JsonPath/
// https://github.com/jayway/JsonPath#what-is-returned-when
return INDEFINITE_TYPES.has(type) || INDEFINITE_SCOPES.has(scope);
});
CACHE.set(path, result);
return result;
}
public registerRule = (rule: types.LintRule) => {
if (!rule.severity) {
rule.severity = this.opts.defaultSeverity;
}
try {
jp.parse(rule.path);
} catch (e) {
throw new SyntaxError(`Invalid JSON path for rule '${rule.name}': ${rule.path}\n\n${e}`);
}
// update rules object
this.rules[rule.name] = {
rule: rule,
apply: generateRule(rule),
};
// update paths object (ensure uniqueness)
if (!this.paths[rule.path]) {
this.paths[rule.path] = [];
}
let present = false;
for (const ruleName of this.paths[rule.path]) {
public GetJsonQueryAt(position: Position): string | null {
const lines = this.document.split("\n");
const potentialQuery: string = (lines[position.line].match(/\B\$[.[].+/g) || [])[0];
try {
parse(potentialQuery);
} catch (e) {
return null;
}
return potentialQuery;
}
matches(rel) {
if (rel && !rel.constructor === String) {
return false
}
try {
const parsed = jsonPath.parse(rel)
return !!parsed.length
} catch (e) {
return false
}
}
function parentLoc(jspath:string)
{
const path = jp.parse(jspath);
if (path.length < 2) {
throw new Error("Path has no parent: " + path);
}
const last = path[path.length - 1];
path.splice(path.length - 1, 1);
checkSimpleSubscript(jspath, last);
return {
path: path,
key: last.expression.value
};
}