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

eslint-plugin-typescript

Package Overview
Dependencies
Maintainers
2
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-typescript - npm Package Compare versions

Comparing version 0.13.0 to 0.14.0-rc.1

16

docs/rules/no-unused-vars.md
# Prevent TypeScript-specific constructs from being erroneously flagged as unused (no-unused-vars)
This rule only has an effect when the `no-unused-vars` core rule is enabled.
It ensures that TypeScript-specific constructs, such as implemented interfaces, are not erroneously flagged as unused.
## Configuration
***This rule only has an effect when the `no-unused-vars` core rule is enabled.***
See [the core ESLint docs](https://eslint.org/docs/rules/no-unused-vars) for how to configure the base `no-unused-vars` rule.
```JSON
{
"rules": {
"no-unused-vars": "error",
"typescript/no-unused-vars": "error",
}
}
```
## Rule Details

@@ -8,0 +20,0 @@

@@ -94,3 +94,8 @@ /**

];
const aliasTypes = ["TSLastTypeNode", "TSArrayType", "TSTypeReference"];
const aliasTypes = [
"TSLastTypeNode",
"TSArrayType",
"TSTypeReference",
"TSLiteralType"
];

@@ -97,0 +102,0 @@ //----------------------------------------------------------------------

48

lib/rules/no-unused-vars.js

@@ -126,3 +126,8 @@ /**

case "TSTypeParameter": {
markTypeAnnotationAsUsed(annotation.constraint);
if (annotation.constraint) {
markTypeAnnotationAsUsed(annotation.constraint);
}
if (annotation.default) {
markTypeAnnotationAsUsed(annotation.default);
}
break;

@@ -215,2 +220,14 @@ }

/**
* Checks the given expression and marks any type parameters as used.
* @param {ASTNode} node the relevant AST node.
* @returns {void}
* @private
*/
function markExpressionAsUsed(node) {
if (node.typeParameters && node.typeParameters.params) {
node.typeParameters.params.forEach(markTypeAnnotationAsUsed);
}
}
/**
* Checks the given interface and marks it as used.

@@ -236,3 +253,3 @@ * Generic arguments are also included in the check.

/**
* Checks the given function return type and marks it as used.
* Checks the given function and marks return types and type parameter constraints as used.
* @param {ASTNode} node the relevant AST node.

@@ -242,3 +259,6 @@ * @returns {void}

*/
function markFunctionReturnTypeAsUsed(node) {
function markFunctionOptionsAsUsed(node) {
if (node.typeParameters && node.typeParameters.params) {
node.typeParameters.params.forEach(markTypeAnnotationAsUsed);
}
if (node.returnType) {

@@ -250,3 +270,3 @@ markTypeAnnotationAsUsed(node.returnType);

/**
* Checks the given class and marks super classes, interfaces and decoratores as used.
* Checks the given class and marks super classes, interfaces, type parameter constraints and decorators as used.
* @param {ASTNode} node the relevant AST node.

@@ -289,14 +309,14 @@ * @returns {void}

FunctionDeclaration: markFunctionReturnTypeAsUsed,
FunctionExpression: markFunctionReturnTypeAsUsed,
ArrowFunctionExpression: markFunctionReturnTypeAsUsed,
CallExpression(node) {
if (node.typeParameters && node.typeParameters.params) {
node.typeParameters.params.forEach(
markTypeAnnotationAsUsed
);
}
TSParameterProperty(node) {
// just assume parameter properties are used
markVariableAsUsed(context, node.parameter.name);
},
FunctionDeclaration: markFunctionOptionsAsUsed,
FunctionExpression: markFunctionOptionsAsUsed,
ArrowFunctionExpression: markFunctionOptionsAsUsed,
CallExpression: markExpressionAsUsed,
NewExpression: markExpressionAsUsed,
Decorator: markDecoratorAsUsed,

@@ -303,0 +323,0 @@ TSInterfaceHeritage: markExtendedInterfaceAsUsed,

@@ -43,2 +43,10 @@ /**

/**
* @param {Scope} scope - a scope to check
* @returns {boolean} `true` if the scope is toplevel
*/
function isTopLevelScope(scope) {
return scope.type === "module" || scope.type === "global";
}
/**
* Checks whether or not a given variable is a function declaration.

@@ -61,6 +69,14 @@ *

function isOuterClass(variable, reference) {
return (
variable.defs[0].type === "ClassName" &&
variable.scope.variableScope !== reference.from.variableScope
);
if (variable.defs[0].type !== "ClassName") {
return false;
}
if (variable.scope.variableScope === reference.from.variableScope) {
// allow the same scope only if it's the top level global/module scope
if (!isTopLevelScope(variable.scope.variableScope)) {
return false;
}
}
return true;
}

@@ -75,6 +91,14 @@

function isOuterVariable(variable, reference) {
return (
variable.defs[0].type === "Variable" &&
variable.scope.variableScope !== reference.from.variableScope
);
if (variable.defs[0].type !== "Variable") {
return false;
}
if (variable.scope.variableScope === reference.from.variableScope) {
// allow the same scope only if it's the top level global/module scope
if (!isTopLevelScope(variable.scope.variableScope)) {
return false;
}
}
return true;
}

@@ -81,0 +105,0 @@

{
"name": "eslint-plugin-typescript",
"version": "0.13.0",
"version": "0.14.0-rc.1",
"description": "TypeScript plugin for ESLint",

@@ -20,3 +20,5 @@ "keywords": [

"mocha": "mocha tests --recursive --reporter=dot",
"test": "npm run lint && npm run mocha && npm run docs:check",
"pretest": "npm run lint",
"test": "mocha tests --recursive --reporter=dot",
"posttest": "npm run docs:check",
"precommit": "npm test && lint-staged"

@@ -38,4 +40,4 @@ },

"prettier": "^1.11.1",
"typescript": "~2.8.1",
"typescript-eslint-parser": "^15.0.0"
"typescript": "~2.9",
"typescript-eslint-parser": "^17.0.1"
},

@@ -42,0 +44,0 @@ "lint-staged": {

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