UNPKG

eslint-plugin-typescript

Version:
50 lines (44 loc) 1.59 kB
/** * @fileoverview Enforces the use of `as Type` assertions instead of `<Type>` assertions. * @author Patricio Trevino */ "use strict"; const util = require("../util"); //------------------------------------------------------------------------------ // Rule Definition //------------------------------------------------------------------------------ module.exports = { meta: { docs: { description: "Enforces the use of `as Type` assertions instead of `<Type>` assertions", extraDescription: [ util.tslintRule("no-angle-bracket-type-assertion") ], category: "Style", url: "https://github.com/nzakas/eslint-plugin-typescript/blob/master/docs/rules/no-angle-bracket-type-assertion.md" }, schema: [] }, create(context) { const sourceCode = context.getSourceCode(); //---------------------------------------------------------------------- // Public //---------------------------------------------------------------------- return { TSTypeAssertionExpression(node) { context.report({ node, message: "Prefer 'as {{cast}}' instead of '<{{cast}}>' when doing type assertions", data: { cast: sourceCode.getText( node.typeAnnotation.typeAnnotation ) } }); } }; } };