Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-no-type-assertion

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-no-type-assertion - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

16

lib/rules/no-type-assertion.js

@@ -8,3 +8,4 @@ module.exports = {

messages: {
typeAssertion: "Do not use as operator to assert expression type",
angleBracketAssertion: "Do not use type assertion",
asAssertion: "Do not use as operator for type assertion",
},

@@ -16,2 +17,13 @@ schema: [],

return {
TSTypeAssertion(node) {
const { typeAnnotation } = node;
if (typeAnnotation.type === "TSTypeReference") {
const { typeName } = typeAnnotation;
if (typeName.type === "Identifier" && typeName.name === "const") {
return;
}
}
context.report({ node, messageId: "angleBracketAssertion" });
},
TSAsExpression(node) {

@@ -26,3 +38,3 @@ const { typeAnnotation } = node;

context.report({ node, messageId: "typeAssertion" });
context.report({ node, messageId: "asAssertion" });
},

@@ -29,0 +41,0 @@ };

6

package.json
{
"name": "eslint-plugin-no-type-assertion",
"version": "1.0.1",
"version": "1.1.0",
"description": "Disallow type assertions in TypeScript code",

@@ -22,3 +22,3 @@ "main": "lib/index.js",

"scripts": {
"test": "mocha tests --recursive",
"test": "jest tests",
"prettier": "prettier --check \"{lib,test}/**/*.js\""

@@ -32,3 +32,3 @@ },

"eslint": "^7.0.0",
"mocha": "^7.1.2",
"jest": "^26.0.1",
"prettier": "^2.0.5",

@@ -35,0 +35,0 @@ "typescript": "^3.9.3"

# eslint-plugin-no-type-assertion
Disallow type assertions in TypeScript code. The rule will forbid `as` operator when used for changing the expression type, unless it's used for [const assertions](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html#const-assertions).
Disallow type assertions in TypeScript code. The rule will forbid both `as` operator, as well as angle-bracketed syntax, unlessused for [const assertions](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html#const-assertions).
The following code becomes invalid:
```typescript
const foo: unknown = 42;
const bar = <number>foo;
const baz = foo as number;
```
## Installation

@@ -52,2 +61,6 @@

### 1.1.0
- Add support for angle-bracketed assertion syntax
### 1.0.1

@@ -54,0 +67,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc