Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
parsed.Diagnostics.forEach((element: ClangTidyDiagnostic) => {
const name: string = element.DiagnosticName;
const severity = name.endsWith('error') ?
DiagnosticSeverity.Error : DiagnosticSeverity.Warning;
const message: string = `${element.Message} (${name})`;
// Helper function to ensure absolute paths and required registrations are made.
function fixPath(filePath: string): string {
if (filePath && !path.isAbsolute(filePath)) {
filePath = path.resolve(path.dirname(Uri.parse(textDocument.uri).fsPath),
filePath);
}
if (!(filePath in diagnostics)) {
diagnostics[filePath] = [];
}
// Resolve replacement.FileOffset and replacement.Length into a range.
let doc: TextDocument | undefined = undefined;
const transformCfnLintSeverity = (errorType: string): DiagnosticSeverity => {
switch (errorType) {
case "Warning":
return DiagnosticSeverity.Warning
case "Informational":
return DiagnosticSeverity.Information
case "Hint":
return DiagnosticSeverity.Hint
default:
// always fallback to error
return DiagnosticSeverity.Error
}
}
const webhintToDiagnosticServerity = (severity: Severity): DiagnosticSeverity => {
switch (severity) {
case 4:
return DiagnosticSeverity.Error;
case 3:
return DiagnosticSeverity.Warning;
case 2:
return DiagnosticSeverity.Hint;
case 1:
return DiagnosticSeverity.Information;
default:
return DiagnosticSeverity.Information;
}
};
function convertDiagnosticCategory(category: ts.DiagnosticCategory): DiagnosticSeverity {
switch (category) {
case ts.DiagnosticCategory.Error:
return DiagnosticSeverity.Error
case ts.DiagnosticCategory.Warning:
return DiagnosticSeverity.Warning
case ts.DiagnosticCategory.Message:
return DiagnosticSeverity.Information
case ts.DiagnosticCategory.Suggestion:
return DiagnosticSeverity.Hint
}
}
private updateLinter() {
let rules: Iterable = new Set();
const projectConfig = this.settings.projectConfig;
let configDiagnostic = this.settings.projectConfigDiagnostic;
if (projectConfig.lint) {
const lintConfig = projectConfig.lint;
if (lintConfig.rules) {
try {
rules = registry.getRules(lintConfig.rules);
} catch (e) {
configDiagnostic = {
code: 'linter-registry-error',
message: e && e.message || '' + e,
severity: DiagnosticSeverity.Error,
source: 'polymer-ide',
range:
{start: {line: 0, character: 0}, end: {line: 0, character: 0}}
};
}
}
this.warningCodesToFilterOut = new Set(lintConfig.ignoreWarnings);
this.fileGlobsToFilterOut =
(lintConfig.filesToIgnore ||
[]).map((glob) => new minimatch.Minimatch(glob, {}));
}
const polymerJsonDiagnostics = [];
if (configDiagnostic) {
polymerJsonDiagnostics.push(configDiagnostic);
}
export const parseToDiagnostics = (
error: ParseError,
diagnostics: DiagnosticUri[] = [],
): DiagnosticUri[] => {
diagnostics.push(
createDiagnosticUri(
error.token,
error.message,
DiagnosticSeverity.Error,
DIAGNOSTICS.PARSER_ERROR,
),
);
for (const inner of error.inner) {
parseToDiagnostics(inner, diagnostics);
}
return diagnostics;
};
private severity(error: any): Severity {
return (error.severity === 3) ? Severity.Warning : Severity.Error;
}
ava('basic defined test', (t) => {
const defineSource = readFileSync(definedPath, 'utf8');
const results = resolveSource(defineSource);
t.is(0, results.scan.scanErrors.length);
t.is(0, results.parse.parseErrors.length);
t.true(results.resolveError.length > 0);
for (const [error, location] of zip(results.resolveError, definedLocations)) {
t.is(DiagnosticSeverity.Error, error.severity);
t.deepEqual(location.start, error.range.start);
t.deepEqual(location.end, error.range.end);
}
});
references.hash[referenceKey].forEach(reference => {
const customTag = CUSTOM_TAGS_BY_TYPE[reference.type]
if (
!customTag.referenceEntityTypes.some(
(entityType: ReferenceEntityType) => {
return Boolean(
referenceables.hash[entityType].contains(
reference.key
)
)
}
)
) {
diagnostics.push({
severity: DiagnosticSeverity.Error,
range: {
start: document.positionAt(reference.node.start),
end: document.positionAt(reference.node.end)
},
message: `[Serverless IDE]: Cannot find ${customTag.referenceEntityTypes
.map((entityType: ReferenceEntityType) =>
entityType.toLowerCase()
)
.join(" or ")} with key "${reference.key}"`
})
}
})
})
export function mapSeverity(severity): DiagnosticSeverity {
switch (severity) {
case 'error':
return DiagnosticSeverity.Error;
case 'warn':
return DiagnosticSeverity.Warning;
default:
return DiagnosticSeverity.Hint;
}
}