eslint-plugin-typescript
Version:
TypeScript plugin for ESLint
50 lines (44 loc) • 1.59 kB
JavaScript
/**
* @fileoverview Enforces the use of `as Type` assertions instead of `<Type>` assertions.
* @author Patricio Trevino
*/
;
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
)
}
});
}
};
}
};