47a1811e0b
This commit performs a modularization of the Language Service's existing diagnostic messages. Such a modularization has two primary advantages: - Centralization and decoupling of error messages from the code that generates them makes it easy to add/delete/edit diagnostic messages, and allows for independent iteration of diagnostic messages and diagnostic generation. - Prepares for additional features like annotating the locations where a diagnostic is generated and enabling the configuration of which diagnostics should be reported by the language service. Although it would be preferable to place the diagnostics registry in an independent JSON file, for ease of typing diagnostic types as an enum variant of 'ts.DiagnosticCategory', the registry is stored as an object. Part of #32663. PR Close #35678
29 lines
839 B
TypeScript
29 lines
839 B
TypeScript
/**
|
|
* @license
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.io/license
|
|
*/
|
|
|
|
import * as ts from 'typescript';
|
|
import {DiagnosticMessage, createDiagnostic} from '../src/diagnostic_messages';
|
|
|
|
describe('create diagnostic', () => {
|
|
it('should format and create diagnostics correctly', () => {
|
|
const diagnosticMessage: DiagnosticMessage = {
|
|
message: 'Check that %1 contains %2',
|
|
kind: 'Error',
|
|
};
|
|
|
|
const diagnostic =
|
|
createDiagnostic({start: 0, end: 1}, diagnosticMessage, 'testCls', 'testMethod');
|
|
|
|
expect(diagnostic).toEqual({
|
|
kind: ts.DiagnosticCategory.Error,
|
|
message: 'Check that testCls contains testMethod',
|
|
span: {start: 0, end: 1},
|
|
});
|
|
});
|
|
});
|