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.12.0 to 0.13.0

.gitattributes

6

lib/rules/adjacent-overload-signatures.js

@@ -47,4 +47,6 @@ /**

case "FunctionDeclaration":
case "TSNamespaceFunctionDeclaration": {
return member.id.name;
case "TSNamespaceFunctionDeclaration":
case "TSEmptyBodyFunctionDeclaration":
case "TSEmptyBodyDeclareFunction": {
return member.id && member.id.name;
}

@@ -51,0 +53,0 @@ case "TSMethodSignature": {

@@ -46,15 +46,4 @@ /**

}
if (name.length === 0) {
return false;
}
const first = name.charAt(0);
const second = name.charAt(1);
if (second === "") {
return false;
}
if (first !== "I" || second !== second.toUpperCase()) {
return false;
}
return true;
return /^I[A-Z]/.test(name);
}

@@ -61,0 +50,0 @@

@@ -125,2 +125,11 @@ /**

case "TSTypeParameter": {
markTypeAnnotationAsUsed(annotation.constraint);
break;
}
case "TSMappedType": {
markTypeAnnotationAsUsed(annotation.typeAnnotation);
markTypeAnnotationAsUsed(annotation.typeParameter);
break;
}
default:

@@ -251,2 +260,5 @@ break;

}
if (node.typeParameters && node.typeParameters.params) {
node.typeParameters.params.forEach(markTypeAnnotationAsUsed);
}
}

@@ -253,0 +265,0 @@

@@ -31,33 +31,2 @@ /**

//----------------------------------------------------------------------
// Helpers
//----------------------------------------------------------------------
/**
* Determines if node is a TypeScript module declaration (instead of a namespace/module).
* @param {ASTNode} node the node to be evaluated.
* @returns {boolean} true when node is an external declaration.
* @private
*/
function isTypeScriptModuleDeclaration(node) {
return node.id && node.id.type === "Literal";
}
/**
* Gets the start index of the keyword `module`.
* @param {TSNode} node the node to be evaluated.
* @returns {number} the start index.
* @private
*/
function getStartIndex(node) {
if (
node.modifiers &&
node.modifiers.length > 0 &&
node.modifiers[0].type === "TSDeclareKeyword"
) {
return node.range[0] + "declare".length + 1;
}
return node.range[0];
}
//----------------------------------------------------------------------
// Public

@@ -67,8 +36,23 @@ //----------------------------------------------------------------------

TSModuleDeclaration(node) {
const declaration = sourceCode.getText(node);
// Get tokens of the declaration header.
const firstToken = sourceCode.getFirstToken(node);
const tokens = [firstToken].concat(
sourceCode.getTokensBetween(
firstToken,
sourceCode.getFirstToken(node.body)
)
);
if (
isTypeScriptModuleDeclaration(node) ||
/\bnamespace\b/.test(declaration)
) {
// Get 'module' token and the next one.
const moduleKeywordIndex = tokens.findIndex(
t => t.type === "Identifier" && t.value === "module"
);
const moduleKeywordToken =
moduleKeywordIndex === -1
? null
: tokens[moduleKeywordIndex];
const moduleNameToken = tokens[moduleKeywordIndex + 1];
// Do nothing if the 'module' token was not found or the module name is a string.
if (!moduleKeywordToken || moduleNameToken.type === "String") {
return;

@@ -82,6 +66,4 @@ }

fix(fixer) {
const start = getStartIndex(node);
return fixer.replaceTextRange(
[start, start + "module".length],
return fixer.replaceText(
moduleKeywordToken,
"namespace"

@@ -88,0 +70,0 @@ );

@@ -101,2 +101,12 @@ /**

previousToken = sourceCode.getTokenBefore(previousToken);
// handle the +/- modifiers for optional modification operators
if (
previousToken.value === "+" ||
previousToken.value === "-"
) {
type = `${previousToken.value}?:`;
punctuatorTokenStart = previousToken;
previousToken = sourceCode.getTokenBefore(previousToken);
}
}

@@ -103,0 +113,0 @@

{
"name": "eslint-plugin-typescript",
"version": "0.12.0",
"version": "0.13.0",
"description": "TypeScript plugin for ESLint",

@@ -18,2 +18,3 @@ "keywords": [

"docs:check": "eslint-docs check",
"format": "prettier --write --tab-width 4 lib/**/*.js tests/**/*.js",
"mocha": "mocha tests --recursive --reporter=dot",

@@ -37,4 +38,4 @@ "test": "npm run lint && npm run mocha && npm run docs:check",

"prettier": "^1.11.1",
"typescript": "~2.6.1",
"typescript-eslint-parser": "^10.0.0"
"typescript": "~2.8.1",
"typescript-eslint-parser": "^15.0.0"
},

@@ -48,5 +49,5 @@ "lint-staged": {

"engines": {
"node": ">=4"
"node": ">=6"
},
"license": "MIT"
}

@@ -58,2 +58,3 @@ # eslint-plugin-typescript

* [`typescript/explicit-member-accessibility`](./docs/rules/explicit-member-accessibility.md) — Require explicit accessibility modifiers on class properties and methods (`member-access` from TSLint)
* [`typescript/generic-type-naming`](./docs/rules/generic-type-naming.md) — Enforces naming of generic type variables
* [`typescript/interface-name-prefix`](./docs/rules/interface-name-prefix.md) — Require that interface names be prefixed with `I` (`interface-name` from TSLint)

@@ -60,0 +61,0 @@ * [`typescript/member-delimiter-style`](./docs/rules/member-delimiter-style.md) — Require a specific member delimiter style for interfaces and type literals

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

options: ["never"]
},
{
code: `
interface I18n {
name: string;
}
`,
options: ["never"]
}

@@ -62,0 +70,0 @@ ],

@@ -319,3 +319,27 @@ /**

}
`,
`
import { Foo } from './types';
class Bar<T extends Foo> {}
new Bar<number>()
`,
`
import { Foo, Bar } from './types';
class Baz<T extends Foo & Bar> {}
new Baz<any>()
`,
`
type Foo = "a" | "b" | "c"
type Bar = number
export const map: { [name in Foo]: Bar } = {
a: 1,
b: 2,
c: 3
}
`
],

@@ -322,0 +346,0 @@

@@ -26,3 +26,4 @@ /**

"namespace foo { }",
"declare namespace foo { }"
"declare namespace foo { }",
"declare global { }"
],

@@ -29,0 +30,0 @@ invalid: [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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