Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('disallows `);
expect(warnings).toEqual([
{
code: expect.any(Number),
level: DiagnosticLevel.Error,
message: expect.stringContaining(
`The <style> element is disallowed inside the template.`
),
location: EXPECTED_LOCATION,
},
]);
});
</style>
it('event handler attribute', () => {
const { warnings } = parseTemplate(`<template><h1></h1></template>`);
expect(warnings).toContainEqual({
code: expect.any(Number),
level: DiagnosticLevel.Error,
message: expect.stringContaining('Event handler should be an expression'),
location: EXPECTED_LOCATION,
});
});
});
warning => warning.level === DiagnosticLevel.Error
);
import { DiagnosticLevel } from '@lwc/errors';
import templateCompiler from '@lwc/template-compiler';
import { TextDocument, Diagnostic, DiagnosticSeverity, Range } from 'vscode-languageserver';
import { DIAGNOSTIC_SOURCE } from '../constants';
const LEVEL_MAPPING: Map = new Map([
[DiagnosticLevel.Log, DiagnosticSeverity.Information],
[DiagnosticLevel.Warning, DiagnosticSeverity.Warning],
[DiagnosticLevel.Error, DiagnosticSeverity.Error],
[DiagnosticLevel.Fatal, DiagnosticSeverity.Error],
]);
export default function lint(document: TextDocument): Diagnostic[] {
const source = document.getText();
const { warnings } = templateCompiler(source, {});
return warnings.map(warning => {
const { start = 0, length = 0 } = warning.location || { start: 0, length: 0 };
return {
range: toRange(document, start, length),
message: warning.message,
severity: LEVEL_MAPPING.get(warning.level),
source: DIAGNOSTIC_SOURCE,
};
const fatalError = result.warnings.find(warning => warning.level === DiagnosticLevel.Error);
if (fatalError) {
const fatalError = result.warnings.find(warning => warning.level === DiagnosticLevel.Error);
if (fatalError) {