eslint-plugin-typescript
Advanced tools
Comparing version
@@ -1,2 +0,2 @@ | ||
# Enforces member overloads to be consecutive. | ||
# Require that member overloads be consecutive (adjacent-overload-signatures) | ||
@@ -3,0 +3,0 @@ Grouping overloaded members together can improve readability of the code. |
@@ -1,2 +0,2 @@ | ||
# Enforces PascalCased class and interface names. (class-name-casing) | ||
# Require PascalCased class and interface names (class-name-casing) | ||
@@ -3,0 +3,0 @@ This rule enforces PascalCased names for classes and interfaces. |
@@ -1,2 +0,2 @@ | ||
# Enforces accessibility modifiers on class properties and methods (explicit-member-accessibility) | ||
# Require explicit accessibility modifiers on class properties and methods (explicit-member-accessibility) | ||
@@ -3,0 +3,0 @@ Leaving off accessibility modifier and making everything public can make |
@@ -1,2 +0,2 @@ | ||
# Enforces interface names are prefixed | ||
# Require that interface names be prefixed with `I` (interface-name-prefix) | ||
@@ -3,0 +3,0 @@ It can be hard to differentiate between classes and interfaces. |
@@ -1,2 +0,2 @@ | ||
# Enforces a member delimiter style in interfaces and type literals. | ||
# Require a specific member delimiter style for interfaces and type literals (member-delimiter-style) | ||
@@ -3,0 +3,0 @@ Enforces a consistent member delimiter style in interfaces and type literals. There are three member delimiter styles primarily used in TypeScript: |
@@ -1,2 +0,2 @@ | ||
# Enforces a standard member declaration order. | ||
# Require a consistent member declaration order (member-ordering) | ||
@@ -3,0 +3,0 @@ A consistent ordering of fields, methods and constructors can make interfaces, type literals, classes and class |
@@ -1,2 +0,2 @@ | ||
# Enforces the use of `as Type` assertions instead of `<Type>` assertions. | ||
# Enforces the use of `as Type` assertions instead of `<Type>` assertions (no-angle-bracket-type-assertion) | ||
@@ -3,0 +3,0 @@ TypeScript disallows the use of `<Type>` assertions in `.tsx` because of the similarity with |
@@ -1,2 +0,2 @@ | ||
# Disallows the declaration of empty interfaces. | ||
# Disallow the declaration of empty interfaces (no-empty-interface) | ||
@@ -3,0 +3,0 @@ An empty interface is equivalent to its supertype. If the interface does not implement a supertype, then |
@@ -1,2 +0,2 @@ | ||
# Enforces the any type is not used (no-explicit-any) | ||
# Disallow usage of the `any` type (no-explicit-any) | ||
@@ -3,0 +3,0 @@ Using the `any` type defeats the purpose of using TypeScript. |
@@ -1,2 +0,2 @@ | ||
# Disallows the use of `custom TypeScript modules` and `namespaces`. | ||
# Disallow the use of custom TypeScript modules and namespaces (no-namespace) | ||
@@ -3,0 +3,0 @@ Custom TypeScript modules (`module foo {}`) and namespaces (`namespace foo {}`) are considered outdated |
@@ -1,2 +0,2 @@ | ||
# Disallows parameter properties in class constructors. | ||
# Disallow the use of parameter properties in class constructors. (no-parameter-properties) | ||
@@ -3,0 +3,0 @@ Parameter properties can be confusing to those new to TypeScript as they are less explicit than other ways |
@@ -1,2 +0,2 @@ | ||
# Enforces reference comments are not used (no-triple-slash-reference) | ||
# Disallow `/// <reference path="" />` comments (no-triple-slash-reference) | ||
@@ -3,0 +3,0 @@ Triple-slash reference directive comments should not be used anymore. Use `import` instead. |
@@ -1,2 +0,2 @@ | ||
# Disallows the use of type aliases. | ||
# Disallow the use of type aliases (no-type-alias) | ||
@@ -3,0 +3,0 @@ In TypeScript, type aliases serve three purposes: |
@@ -1,2 +0,2 @@ | ||
# Disallow Early Use (no-use-before-define) | ||
# Disallow the use of variables before they are defined (no-use-before-define) | ||
@@ -3,0 +3,0 @@ In JavaScript, prior to ES6, variable and function declarations are hoisted to the top of a scope, so it's possible to use identifiers before their formal declarations in code. This can be confusing and some believe it is best to always declare variables and functions before using them. |
@@ -1,2 +0,2 @@ | ||
# Enforces the use of the keyword `namespace` over `module` to declare custom TypeScript modules. | ||
# Require the use of the `namespace` keyword instead of the `module` keyword to declare custom TypeScript modules. (prefer-namespace-keyword) | ||
@@ -3,0 +3,0 @@ In an effort to prevent further confusion between custom TypeScript modules and the new ES2015 modules, starting |
@@ -1,2 +0,2 @@ | ||
# Enforces spacing around type annotations (type-annotation-spacing) | ||
# Require consistent spacing around type annotations (type-annotation-spacing) | ||
@@ -3,0 +3,0 @@ Spacing around type annotations improves readability of the code. Although the most commonly used style guideline for type annotations in TypeScript prescribes adding a space after the colon, but not before it, it is subjective to the preferences of a project. For example: |
@@ -14,3 +14,3 @@ /** | ||
docs: { | ||
description: "Enforces member overloads to be consecutive", | ||
description: "Require that member overloads be consecutive", | ||
category: "TypeScript" | ||
@@ -17,0 +17,0 @@ }, |
@@ -7,2 +7,4 @@ /** | ||
const util = require("../util"); | ||
//------------------------------------------------------------------------------ | ||
@@ -15,3 +17,4 @@ // Rule Definition | ||
docs: { | ||
description: "Enforces PascalCased class and interface names.", | ||
description: "Require PascalCased class and interface names", | ||
extraDescription: [util.tslintRule("class-name")], | ||
category: "Best Practices", | ||
@@ -18,0 +21,0 @@ recommended: true |
@@ -7,2 +7,4 @@ /** | ||
const util = require("../util"); | ||
//------------------------------------------------------------------------------ | ||
@@ -16,3 +18,4 @@ // Rule Definition | ||
description: | ||
"Enforces explicity accessibility modifiers for class members", | ||
"Require explicit accessibility modifiers on class properties and methods", | ||
extraDescription: [util.tslintRule("member-access")], | ||
category: "TypeScript" | ||
@@ -19,0 +22,0 @@ }, |
@@ -7,2 +7,4 @@ /** | ||
const util = require("../util"); | ||
//------------------------------------------------------------------------------ | ||
@@ -15,3 +17,4 @@ // Rule Definition | ||
docs: { | ||
description: 'Enforces interface names are prefixed with "I".', | ||
description: "Require that interface names be prefixed with `I`", | ||
extraDescription: [util.tslintRule("interface-name")], | ||
category: "TypeScript" | ||
@@ -18,0 +21,0 @@ }, |
@@ -25,3 +25,3 @@ /** | ||
description: | ||
"Enforces a member delimiter style for interfaces and type literals.", | ||
"Require a specific member delimiter style for interfaces and type literals", | ||
category: "TypeScript" | ||
@@ -28,0 +28,0 @@ }, |
@@ -7,2 +7,4 @@ /** | ||
const util = require("../util"); | ||
//------------------------------------------------------------------------------ | ||
@@ -37,3 +39,4 @@ // Rule Definition | ||
docs: { | ||
description: "Enforces a standard member declaration order.", | ||
description: "Require a consistent member declaration order", | ||
extraDescription: [util.tslintRule("member-ordering")], | ||
category: "TypeScript" | ||
@@ -40,0 +43,0 @@ }, |
@@ -7,2 +7,4 @@ /** | ||
const util = require("../util"); | ||
//------------------------------------------------------------------------------ | ||
@@ -16,3 +18,6 @@ // Rule Definition | ||
description: | ||
"Enforces the use of as Type assertions instead of <Type> assertions.", | ||
"Enforces the use of `as Type` assertions instead of `<Type>` assertions", | ||
extraDescription: [ | ||
util.tslintRule("no-angle-bracket-type-assertion") | ||
], | ||
category: "Style" | ||
@@ -19,0 +24,0 @@ }, |
@@ -7,2 +7,4 @@ /** | ||
const util = require("../util"); | ||
//------------------------------------------------------------------------------ | ||
@@ -15,3 +17,4 @@ // Rule Definition | ||
docs: { | ||
description: "Disallows the declaration of empty interfaces.", | ||
description: "Disallow the declaration of empty interfaces", | ||
extraDescription: [util.tslintRule("no-empty-interface")], | ||
category: "TypeScript" | ||
@@ -18,0 +21,0 @@ }, |
@@ -8,2 +8,4 @@ /** | ||
const util = require("../util"); | ||
//------------------------------------------------------------------------------ | ||
@@ -16,3 +18,4 @@ // Rule Definition | ||
docs: { | ||
description: "Enforces the any type is not used.", | ||
description: "Disallow usage of the `any` type", | ||
extraDescription: [util.tslintRule("no-any")], | ||
category: "TypeScript" | ||
@@ -19,0 +22,0 @@ }, |
@@ -15,3 +15,3 @@ /** | ||
description: | ||
"Disallows the use of custom TypeScript modules and namespaces.", | ||
"Disallow the use of custom TypeScript modules and namespaces", | ||
category: "TypeScript" | ||
@@ -18,0 +18,0 @@ }, |
@@ -7,2 +7,4 @@ /** | ||
const util = require("../util"); | ||
//------------------------------------------------------------------------------ | ||
@@ -16,3 +18,4 @@ // Rule Definition | ||
description: | ||
"Disallows parameter properties in class constructors.", | ||
"Disallow the use of parameter properties in class constructors.", | ||
extraDescription: [util.tslintRule("no-parameter-properties")], | ||
category: "TypeScript" | ||
@@ -19,0 +22,0 @@ }, |
@@ -7,2 +7,4 @@ /** | ||
const util = require("../util"); | ||
//------------------------------------------------------------------------------ | ||
@@ -15,3 +17,4 @@ // Rule Definition | ||
docs: { | ||
description: "Enforces triple slash references are not used.", | ||
description: 'Disallow `/// <reference path="" />` comments', | ||
extraDescription: [util.tslintRule("no-reference")], | ||
category: "TypeScript" | ||
@@ -18,0 +21,0 @@ }, |
@@ -7,2 +7,4 @@ /** | ||
const util = require("../util"); | ||
//------------------------------------------------------------------------------ | ||
@@ -15,3 +17,4 @@ // Rule Definition | ||
docs: { | ||
description: "Disallows the use of type aliases.", | ||
description: "Disallow the use of type aliases", | ||
extraDescription: [util.tslintRule("interface-over-type-literal")], | ||
category: "TypeScript" | ||
@@ -18,0 +21,0 @@ }, |
@@ -50,3 +50,3 @@ /** | ||
description: | ||
"Prevent TypeScript-specific variables being falsely marked as unused.", | ||
"Prevent TypeScript-specific constructs from being erroneously flagged as unused", | ||
category: "TypeScript", | ||
@@ -73,2 +73,6 @@ recommended: true | ||
switch (annotation.type) { | ||
case "TSArrayType": { | ||
markTypeAnnotationAsUsed(annotation.elementType); | ||
break; | ||
} | ||
case "TSTypeReference": { | ||
@@ -75,0 +79,0 @@ if (annotation.typeName.type === "TSArrayType") { |
@@ -159,3 +159,3 @@ /** | ||
description: | ||
"disallow the use of variables before they are defined", | ||
"Disallow the use of variables before they are defined", | ||
category: "Variables", | ||
@@ -162,0 +162,0 @@ recommended: false |
@@ -7,2 +7,4 @@ /** | ||
const util = require("../util"); | ||
//------------------------------------------------------------------------------ | ||
@@ -16,3 +18,4 @@ // Rule Definition | ||
description: | ||
"Enforces the use of the keyword namespace over module to declare custom TypeScript modules.", | ||
"Require the use of the `namespace` keyword instead of the `module` keyword to declare custom TypeScript modules.", | ||
extraDescription: [util.tslintRule("no-internal-module")], | ||
category: "TypeScript" | ||
@@ -75,3 +78,3 @@ }, | ||
message: | ||
"Use namespace instead of module to declare custom TypeScript modules", | ||
"Use 'namespace' instead of 'module' to declare custom TypeScript modules", | ||
fix(fixer) { | ||
@@ -78,0 +81,0 @@ const start = getStartIndex(node); |
@@ -24,3 +24,3 @@ /** | ||
docs: { | ||
description: "Enforces spacing around type annotations.", | ||
description: "Require consistent spacing around type annotations", | ||
category: "TypeScript" | ||
@@ -79,3 +79,3 @@ }, | ||
function checkTypeAnnotationSpacing(typeAnnotation) { | ||
const nextToken = typeAnnotation.typeAnnotation || typeAnnotation; | ||
const nextToken = typeAnnotation; | ||
const punctuatorToken = sourceCode.getTokenBefore(nextToken); | ||
@@ -145,3 +145,5 @@ const previousToken = sourceCode.getTokenBefore(punctuatorToken); | ||
if (node.returnType) { | ||
checkTypeAnnotationSpacing(node.returnType); | ||
checkTypeAnnotationSpacing( | ||
node.returnType.typeAnnotation || node.returnType | ||
); | ||
} | ||
@@ -156,16 +158,13 @@ } | ||
if (node.typeAnnotation) { | ||
checkTypeAnnotationSpacing(node.typeAnnotation); | ||
checkTypeAnnotationSpacing( | ||
node.typeAnnotation.typeAnnotation || | ||
node.typeAnnotation | ||
); | ||
} | ||
}, | ||
TypeAnnotation(node) { | ||
if ( | ||
node.typeAnnotation && | ||
node.typeAnnotation.type !== "TSFunctionType" && | ||
node.parent.type !== "TSAsExpression" | ||
) { | ||
if (node.parent.type !== "TSAsExpression") { | ||
checkTypeAnnotationSpacing(node.typeAnnotation); | ||
} | ||
}, | ||
FunctionDeclaration: checkFunctionReturnTypeSpacing, | ||
@@ -172,0 +171,0 @@ FunctionExpression: checkFunctionReturnTypeSpacing, |
{ | ||
"name": "eslint-plugin-typescript", | ||
"version": "0.7.0", | ||
"version": "0.8.0", | ||
"description": "TypeScript plugin for ESLint", | ||
@@ -16,4 +16,6 @@ "keywords": [ | ||
"lint:fix": "eslint lib/ tests/ --fix", | ||
"mocha": "mocha tests --recursive", | ||
"test": "npm run lint && npm run mocha", | ||
"docs": "eslint-docs", | ||
"docs:check": "eslint-docs check", | ||
"mocha": "mocha tests --recursive --reporter=dot", | ||
"test": "npm run lint && npm run mocha && npm run docs:check", | ||
"precommit": "npm test && lint-staged" | ||
@@ -25,13 +27,14 @@ }, | ||
"devDependencies": { | ||
"eslint": "^4.5.0", | ||
"eslint": "^4.6.1", | ||
"eslint-config-eslint": "^4.0.0", | ||
"eslint-config-prettier": "^2.3.0", | ||
"eslint-config-prettier": "^2.4.0", | ||
"eslint-docs": "^0.1.1", | ||
"eslint-plugin-node": "^5.1.1", | ||
"eslint-plugin-prettier": "^2.2.0", | ||
"husky": "^0.14.3", | ||
"lint-staged": "^4.0.3", | ||
"mocha": "^3.5.0", | ||
"prettier": "^1.5.3", | ||
"typescript": "~2.4.2", | ||
"typescript-eslint-parser": "^7.0.0" | ||
"lint-staged": "^4.1.3", | ||
"mocha": "^3.5.3", | ||
"prettier": "^1.6.1", | ||
"typescript": "~2.5.1", | ||
"typescript-eslint-parser": "^8.0.0" | ||
}, | ||
@@ -38,0 +41,0 @@ "lint-staged": { |
@@ -52,18 +52,23 @@ # eslint-plugin-typescript | ||
* [`typescript/type-annotation-spacing`](./docs/rules/type-annotation-spacing.md) — enforces one space after the colon and zero spaces before the colon of a type annotation. | ||
* [`typescript/explicit-member-accessibility`](./docs/rules/explicit-member-accessibility.md) — enforces accessibility modifiers on class properties and methods. (`member-access` from TSLint) | ||
* [`typescript/interface-name-prefix`](./docs/rules/interface-name-prefix.md) — enforces interface names are prefixed. (`interface-name` from TSLint) | ||
* [`typescript/no-triple-slash-reference`](./docs/rules/no-triple-slash-reference.md) — enforces `/// <reference />` is not used. (`no-reference` from TSLint) | ||
* [`typescript/no-explicit-any`](./docs/rules/no-explicit-any.md) — enforces the `any` type is not used. (`no-any` from TSLint) | ||
* [`typescript/no-angle-bracket-type-assertion`](./docs/rules/no-angle-bracket-type-assertion.md) — enforces the use of `as Type` assertions instead of `<Type>` assertions. (`no-angle-bracket-type-assertion` from TSLint) | ||
* [`typescript/no-namespace`](./docs/rules/no-namespace.md) — disallows the use of custom TypeScript modules and namespaces. | ||
* [`typescript/no-use-before-define`](./docs/rules/no-use-before-define.md) — disallows the use of variables before they are defined. | ||
* [`typescript/prefer-namespace-keyword`](./docs/rules/prefer-namespace-keyword.md) — enforces the use of the keyword `namespace` over `module` to declare custom TypeScript modules. (`no-internal-module` from TSLint) | ||
* [`typescript/no-type-alias`](./docs/rules/no-type-alias.md) — disallows the use of type aliases. (`interface-over-type-literal` from TSLint) | ||
* [`typescript/member-ordering`](./docs/rules/member-ordering.md) — enforces a standard member declaration order. (`member-ordering` from TSLint) | ||
* [`typescript/no-unused-vars`](./docs/rules/no-unused-vars.md) — prevents TypeScript-specific constructs from being erroneously flagged as unused | ||
* [`typescript/adjacent-overload-signatures`](./docs/rules/adjacent-overload-signatures.md) — enforces member overloads to be consecutive. | ||
* [`typescript/no-parameter-properties`](./docs/rules/no-parameter-properties.md) - disallows parameter properties in class constructors. (`no-parameter-properties` from TSLint) | ||
* [`typescript/class-name-casing`](./docs/rules/adjacent-overload-signatures.md) - enforces PascalCased class and interface names. (`class-name` from TSLint) | ||
* [`typescript/member-delimiter-style`](./docs/rules/member-delimiter-style.md) - enforces a member delimiter style in interfaces and type literals. | ||
* [`typescript/no-empty-interface`](./docs/rules/no-empty-interface.md) - disallows the declaration of empty interfaces. (`no-empty-interface` from TSLint) | ||
<!-- Please run `npm run docs` to update this section --> | ||
<!-- begin rule list --> | ||
* [`typescript/adjacent-overload-signatures`](./docs/rules/adjacent-overload-signatures.md) — Require that member overloads be consecutive | ||
* [`typescript/class-name-casing`](./docs/rules/class-name-casing.md) — Require PascalCased class and interface names (`class-name` from TSLint) | ||
* [`typescript/explicit-member-accessibility`](./docs/rules/explicit-member-accessibility.md) — Require explicit accessibility modifiers on class properties and methods (`member-access` from TSLint) | ||
* [`typescript/interface-name-prefix`](./docs/rules/interface-name-prefix.md) — Require that interface names be prefixed with `I` (`interface-name` from TSLint) | ||
* [`typescript/member-delimiter-style`](./docs/rules/member-delimiter-style.md) — Require a specific member delimiter style for interfaces and type literals | ||
* [`typescript/member-naming`](./docs/rules/member-naming.md) — Enforces naming conventions for class members by visibility. | ||
* [`typescript/member-ordering`](./docs/rules/member-ordering.md) — Require a consistent member declaration order (`member-ordering` from TSLint) | ||
* [`typescript/no-angle-bracket-type-assertion`](./docs/rules/no-angle-bracket-type-assertion.md) — Enforces the use of `as Type` assertions instead of `<Type>` assertions (`no-angle-bracket-type-assertion` from TSLint) | ||
* [`typescript/no-array-constructor`](./docs/rules/no-array-constructor.md) — Disallow generic `Array` constructors | ||
* [`typescript/no-empty-interface`](./docs/rules/no-empty-interface.md) — Disallow the declaration of empty interfaces (`no-empty-interface` from TSLint) | ||
* [`typescript/no-explicit-any`](./docs/rules/no-explicit-any.md) — Disallow usage of the `any` type (`no-any` from TSLint) | ||
* [`typescript/no-namespace`](./docs/rules/no-namespace.md) — Disallow the use of custom TypeScript modules and namespaces | ||
* [`typescript/no-parameter-properties`](./docs/rules/no-parameter-properties.md) — Disallow the use of parameter properties in class constructors. (`no-parameter-properties` from TSLint) | ||
* [`typescript/no-triple-slash-reference`](./docs/rules/no-triple-slash-reference.md) — Disallow `/// <reference path="" />` comments (`no-reference` from TSLint) | ||
* [`typescript/no-type-alias`](./docs/rules/no-type-alias.md) — Disallow the use of type aliases (`interface-over-type-literal` from TSLint) | ||
* [`typescript/no-unused-vars`](./docs/rules/no-unused-vars.md) — Prevent TypeScript-specific constructs from being erroneously flagged as unused | ||
* [`typescript/no-use-before-define`](./docs/rules/no-use-before-define.md) — Disallow the use of variables before they are defined | ||
* [`typescript/prefer-namespace-keyword`](./docs/rules/prefer-namespace-keyword.md) — Require the use of the `namespace` keyword instead of the `module` keyword to declare custom TypeScript modules. (`no-internal-module` from TSLint) | ||
* [`typescript/type-annotation-spacing`](./docs/rules/type-annotation-spacing.md) — Require consistent spacing around type annotations | ||
<!-- end rule list --> |
@@ -249,2 +249,10 @@ /** | ||
"import { Nullable } from 'nullable'", | ||
"const a: Nullable[] = 'hello'", | ||
"console.log(a)" | ||
].join("\n"), | ||
parser | ||
}, | ||
{ | ||
code: [ | ||
"import { Nullable } from 'nullable'", | ||
"const a: Array<Nullable[]> = 'hello'", | ||
@@ -251,0 +259,0 @@ "console.log(a)" |
@@ -42,3 +42,3 @@ /** | ||
message: | ||
"Use namespace instead of module to declare custom TypeScript modules", | ||
"Use 'namespace' instead of 'module' to declare custom TypeScript modules", | ||
output: "namespace foo { }", | ||
@@ -56,3 +56,3 @@ row: 1, | ||
message: | ||
"Use namespace instead of module to declare custom TypeScript modules", | ||
"Use 'namespace' instead of 'module' to declare custom TypeScript modules", | ||
output: "declare namespace foo { }", | ||
@@ -74,3 +74,3 @@ row: 1, | ||
message: | ||
"Use namespace instead of module to declare custom TypeScript modules", | ||
"Use 'namespace' instead of 'module' to declare custom TypeScript modules", | ||
output: "declare namespace foo { }", | ||
@@ -82,3 +82,3 @@ row: 2, | ||
message: | ||
"Use namespace instead of module to declare custom TypeScript modules", | ||
"Use 'namespace' instead of 'module' to declare custom TypeScript modules", | ||
output: ` | ||
@@ -85,0 +85,0 @@ declare namespace foo { |
Sorry, the diff of this file is too big to display
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
618987
3.93%67
11.67%19353
3.66%74
7.25%12
9.09%2
100%