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.5.0 to 0.6.0

.editorconfig

22

docs/rules/adjacent-overload-signatures.md
# Enforces member overloads to be consecutive.
Grouping overloaded members (methods and functions) together can improve readability of the code.
Grouping overloaded members together can improve readability of the code.

@@ -39,2 +39,7 @@ ## Rule Details

}
export function foo(s: string): void;
export function foo(n: number): void;
export function bar(): void;
export function foo(sn: string | number): void;
```

@@ -49,3 +54,3 @@

export function foo(sn: string | number): void;
export function bar(): void;
export function bar(): void;
}

@@ -55,3 +60,3 @@

foo(s: string): void;
foo(n: number): void;
foo(n: number): void;
foo(sn: string | number): void;

@@ -63,3 +68,3 @@ bar(): void;

foo(s: string): void;
foo(n: number): void;
foo(n: number): void;
foo(sn: string | number): void;

@@ -71,6 +76,11 @@ bar(): void;

foo(s: string): void;
foo(n: number): void;
foo(n: number): void;
foo(sn: string | number): void {}
bar(): void {}
}
export function bar(): void;
export function foo(s: string): void;
export function foo(n: number): void;
export function foo(sn: string | number): void;
```

@@ -84,2 +94,2 @@

* TSLint: [adjacent-overload-signatures](https://palantir.github.io/tslint/rules/adjacent-overload-signatures/)
* TSLint: [adjacent-overload-signatures](https://palantir.github.io/tslint/rules/adjacent-overload-signatures/)

@@ -6,6 +6,9 @@ # Enforces spacing around type annotations (type-annotation-spacing)

```ts
// with space after, but not before
// with space after, but not before (default if no option is specified)
let foo: string = "bar";
// with space before and after
// with no spaces
let foo:string = "bar";
// with space before and after
let foo : string = "bar";

@@ -15,2 +18,14 @@

let foo :string = "bar";
// with spaces before and after the fat arrow (default if no option is specified)
type Foo = (string: name) => string;
// with no spaces between the fat arrow
type Foo = (string: name)=>string;
// with space after, but not before the fat arrow
type Foo = (string: name)=> string;
// with space before, but not after the fat arrow
type Foo = (string: name) =>string;
```

@@ -20,14 +35,54 @@

This rule aims to enforce specific spacing patterns around type annotations.
This rule aims to enforce specific spacing patterns around type annotations and function types in type literals.
## Options
## Options
This rule has an object option:
- `"before": false` (default) disallows spaces before the colon.
- `"before": true` requires a space before the colon.
- `"after": true` (default) requires a space after the colon.
- `"after": false` disallows spaces after the colon.
- `"before": false`, (default for colon) disallows spaces before the colon/arrow.
- `"before": true`, (default for arrow) requires a space before the colon/arrow.
- `"after": true`, (default) requires a space after the colon/arrow.
- `"after": false`, disallows spaces after the colon/arrow.
- `"overrides"`, overrides the default options for type annotations with `colon` (e.g. `const foo: string`) and function types with `arrow` (e.g. `type Foo = () => {}`).
### defaults
Examples of **incorrect** code for this rule with no options at all:
```ts
let foo:string = "bar";
let foo :string = "bar";
let foo : string = "bar";
function foo():string {}
function foo() :string {}
function foo() : string {}
class Foo {
name:string;
}
class Foo {
name :string;
}
class Foo {
name : string;
}
type Foo = ()=> {};
```
Examples of **correct** code for this rule with no options at all:
```ts
let foo: string = "bar";
function foo(): string {}
class Foo {
name: string;
}
type Foo = () => {};
```
### after
Examples of **incorrect** code for this rule with the default `{ "before": false, "after": true }` options:
Examples of **incorrect** code for this rule with `{ "before": false, "after": true }`:
```ts

@@ -53,5 +108,7 @@ let foo:string = "bar";

}
type Foo = () => {};
```
Examples of **correct** code for this rule with the default `{ "before": false, "after": true }` options:
Examples of **correct** code for this rule with `{ "before": false, "after": true }`:
```ts

@@ -65,2 +122,4 @@ let foo: string = "bar";

}
type Foo = ()=> {};
```

@@ -103,2 +162,96 @@

### overrides - colon
Examples of **incorrect** code for this rule with `{ "before": false, "after": false, overrides: { colon: { before: true, after: true }} }` options:
```ts
let foo: string = "bar";
let foo:string = "bar";
let foo :string = "bar";
function foo(): string {}
function foo():string {}
function foo() :string {}
class Foo {
name: string;
}
class Foo {
name:string;
}
class Foo {
name :string;
}
type Foo = {
name: (name:string) => string;
}
```
Examples of **correct** code for this rule with `{ "before": true, "after": true, overrides: { colon: { before: true, after: true }} }` options:
```ts
let foo : string = "bar";
function foo() : string {}
class Foo {
name : string;
}
type Foo = {
name: (name : string)=>string;
}
```
### overrides - arrow
Examples of **incorrect** code for this rule with `{ "before": false, "after": false, overrides: { arrow: { before: true, after: true }} }` options:
```ts
let foo: string = "bar";
let foo : string = "bar";
let foo :string = "bar";
function foo(): string {}
function foo():string {}
function foo() :string {}
class Foo {
name: string;
}
class Foo {
name : string;
}
class Foo {
name :string;
}
type Foo = {
name: (name : string)=>string;
}
type Foo = {
name: (name : string) =>string;
}
type Foo = {
name: (name : string)=> string;
}
```
Examples of **correct** code for this rule with `{ "before": false, "after": false, overrides: { arrow: { before: true, after: true }} }` options:
```ts
let foo:string = "bar";
function foo():string {}
class Foo {
name:string;
}
type Foo = {
name: (name:string) => string;
}
```
## When Not To Use It

@@ -105,0 +258,0 @@

@@ -18,7 +18,3 @@ /**

// import all rules in lib/rules
module.exports.rules = requireIndex(path.join(__dirname, "rules"));

@@ -21,3 +21,2 @@ /**

create(context) {
//----------------------------------------------------------------------

@@ -35,4 +34,5 @@ // Helpers

switch (member.type) {
case "ExportDefaultDeclaration":
case "ExportNamedDeclaration": {
return member.declaration.id.name;
return getMemberName(member.declaration);
}

@@ -45,4 +45,6 @@ case "DeclareFunction":

case "TSMethodSignature": {
return member.key && (member.key.name || member.key.value) ||
member.name && (member.name.name || member.name.value);
return (
(member.key && (member.key.name || member.key.value)) ||
(member.name && (member.name.name || member.name.value))
);
}

@@ -52,2 +54,5 @@ case "TSCallSignature": {

}
case "TSConstructSignature": {
return "new";
}
case "MethodDefinition": {

@@ -72,7 +77,10 @@ return member.key.name || member.key.value;

if (members) {
let name;
let index;
let lastName;
const seen = [];
let index, name, lastName;
members.forEach(member => {
name = getMemberName(member);
index = seen.indexOf(name);

@@ -79,0 +87,0 @@ if (index > -1 && lastName !== name) {

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

docs: {
description: "Enforces explicity accessibility modifiers for class members",
description:
"Enforces explicity accessibility modifiers for class members",
category: "TypeScript"

@@ -22,3 +23,2 @@ },

create(context) {
//----------------------------------------------------------------------

@@ -38,3 +38,4 @@ // Helpers

node: methodDefinition,
message: `Missing accessibility modifier on method definition ${methodDefinition.key.name}.`
message: `Missing accessibility modifier on method definition ${methodDefinition
.key.name}.`
});

@@ -54,3 +55,4 @@ }

node: classProperty,
message: `Missing accessibility modifier on class property ${classProperty.key.name}.`
message: `Missing accessibility modifier on class property ${classProperty
.key.name}.`
});

@@ -57,0 +59,0 @@ }

@@ -14,3 +14,3 @@ /**

docs: {
description: "Enforces interface names are prefixed with \"I\".",
description: 'Enforces interface names are prefixed with "I".',
category: "TypeScript"

@@ -68,3 +68,3 @@ },

node: interfaceNode.id,
message: "Interface name must not be prefixed with \"I\""
message: 'Interface name must not be prefixed with "I"'
});

@@ -76,3 +76,3 @@ }

node: interfaceNode.id,
message: "Interface name must be prefixed with \"I\""
message: 'Interface name must be prefixed with "I"'
});

@@ -79,0 +79,0 @@ }

@@ -11,3 +11,7 @@ /**

const schemaOptions = ["field", "method", "constructor"].reduce((options, type) => {
const schemaOptions = [
"field",
"method",
"constructor"
].reduce((options, type) => {
options.push(type);

@@ -112,5 +116,8 @@

create(context) {
const options = context.options[0] || {};
const functionExpressions = [
"FunctionExpression",
"ArrowFunctionExpression"
];
const defaultOrder = [

@@ -159,2 +166,29 @@ "public-static-field",

/**
* Determines if `node` should be processed as a method instead of a field.
* @param {ASTNode} node the node to be inspected.
* @returns {boolean} `true` if node should be processed as a method; `false` for fields.
* @private
*/
function shouldBeProcessedAsMethod(node) {
// check for bound methods in ClassProperty nodes.
if (
node.value &&
functionExpressions.indexOf(node.value.type) > -1
) {
return true;
}
// check for bound methods in TSPropertySignature nodes.
if (
node.typeAnnotation &&
node.typeAnnotation.typeAnnotation &&
node.typeAnnotation.typeAnnotation.type === "TSFunctionType"
) {
return true;
}
return false;
}
/**
* Gets the node type.

@@ -175,3 +209,3 @@ * @param {ASTNode} node the node to be evaluated.

case "TSPropertySignature":
return "field";
return shouldBeProcessedAsMethod(node) ? "method" : "field";
default:

@@ -307,6 +341,11 @@ return null;

node: member,
message: "Member {{name}} should be declared before all {{rank}} definitions.",
message:
"Member {{name}} should be declared before all {{rank}} definitions.",
data: {
name: getMemberName(member),
rank: getLowestRank(previousRanks, rank, order)
rank: getLowestRank(
previousRanks,
rank,
order
)
}

@@ -327,12 +366,28 @@ });

ClassDeclaration(node) {
validateMembers(node.body.body, options.classes || options.default || defaultOrder, true);
validateMembers(
node.body.body,
options.classes || options.default || defaultOrder,
true
);
},
ClassExpression(node) {
validateMembers(node.body.body, options.classExpressions || options.default || defaultOrder, true);
validateMembers(
node.body.body,
options.classExpressions || options.default || defaultOrder,
true
);
},
TSInterfaceDeclaration(node) {
validateMembers(node.body.body, options.interfaces || options.default || defaultOrder, false);
validateMembers(
node.body.body,
options.interfaces || options.default || defaultOrder,
false
);
},
TSTypeLiteral(node) {
validateMembers(node.members, options.typeLiterals || options.default || defaultOrder, false);
validateMembers(
node.members,
options.typeLiterals || options.default || defaultOrder,
false
);
}

@@ -339,0 +394,0 @@ };

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

docs: {
description: "Enforces the use of as Type assertions instead of <Type> assertions.",
description:
"Enforces the use of as Type assertions instead of <Type> assertions.",
category: "Style"

@@ -22,3 +23,2 @@ },

create(context) {
const sourceCode = context.getSourceCode();

@@ -33,5 +33,8 @@

node,
message: "Prefer 'as {{cast}}' instead of '<{{cast}}>' when doing type assertions",
message:
"Prefer 'as {{cast}}' instead of '<{{cast}}>' when doing type assertions",
data: {
cast: sourceCode.getText(node.typeAnnotation.typeAnnotation)
cast: sourceCode.getText(
node.typeAnnotation.typeAnnotation
)
}

@@ -38,0 +41,0 @@ });

@@ -22,3 +22,2 @@ /**

create(context) {
//----------------------------------------------------------------------

@@ -42,10 +41,19 @@ // Helpers

checkGenericNodeForAnnotation(node.elementType);
} else if (node.type === "TSUnionType" || node.type === "TSIntersectionType") {
} else if (
node.type === "TSUnionType" ||
node.type === "TSIntersectionType"
) {
node.types.forEach(type => {
checkGenericNodeForAnnotation(type);
});
} else if (node.type === "TSTypeReference" && node.typeParameters) {
node.typeParameters.params.forEach(param => {
checkGenericNodeForAnnotation(param);
});
} else if (node.type === "TSTypeReference") {
if (node.typeParameters) {
// handles generics
node.typeParameters.params.forEach(param => {
checkGenericNodeForAnnotation(param);
});
} else if (node.typeName) {
// handles non generics
checkGenericNodeForAnnotation(node.typeName);
}
} else if (node.type === "GenericTypeAnnotation") {

@@ -80,3 +88,5 @@ if (node.typeParameters) {

if (node.typeAnnotation) {
checkGenericNodeForAnnotation(node.typeAnnotation.typeAnnotation);
checkGenericNodeForAnnotation(
node.typeAnnotation.typeAnnotation
);
}

@@ -83,0 +93,0 @@ },

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

docs: {
description: "Disallows the use of custom TypeScript modules and namespaces.",
description:
"Disallows the use of custom TypeScript modules and namespaces.",
category: "TypeScript"

@@ -35,6 +36,9 @@ },

create(context) {
const allowDeclarations = context.options[0]
? context.options[0].allowDeclarations
: false;
const allowDefinitionFiles = context.options[0]
? context.options[0].allowDefinitionFiles
: false;
const allowDeclarations = context.options[0] ? context.options[0].allowDeclarations : false;
const allowDefinitionFiles = context.options[0] ? context.options[0].allowDefinitionFiles : false;
//----------------------------------------------------------------------

@@ -61,3 +65,5 @@ // Helpers

function isDeclaration(node) {
const hasDeclareModifier = (node.modifiers || []).filter(m => m.type === "TSDeclareKeyword").length > 0;
const hasDeclareModifier =
(node.modifiers || [])
.filter(m => m.type === "TSDeclareKeyword").length > 0;

@@ -75,3 +81,5 @@ return hasDeclareModifier && !isTypeScriptModuleDeclaration(node);

return filename ? filename.slice(-5).toLowerCase() === ".d.ts" : false;
return filename
? filename.slice(-5).toLowerCase() === ".d.ts"
: false;
}

@@ -84,5 +92,7 @@

TSModuleDeclaration(node) {
if (isTypeScriptModuleDeclaration(node) ||
if (
isTypeScriptModuleDeclaration(node) ||
(allowDefinitionFiles && isDefinitionFile()) ||
(allowDeclarations && isDeclaration(node))) {
(allowDeclarations && isDeclaration(node))
) {
return;

@@ -93,3 +103,4 @@ }

node,
message: "ES2015 module syntax is preferred over custom TypeScript modules and namespaces"
message:
"ES2015 module syntax is preferred over custom TypeScript modules and namespaces"
});

@@ -96,0 +107,0 @@ }

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

allowCallbacks: {
enum: [
true,
false,
"always",
"never"
]
enum: [true, false, "always", "never"]
},

@@ -72,10 +67,25 @@ allowLiterals: {

const allowAliases = options && options.allowAliases || "never";
const allowCallbacks = options && options.allowCallbacks || "never";
const allowLiterals = options && options.allowLiterals || "never";
const allowMappedTypes = options && options.allowMappedTypes || "never";
const allowAliases = (options && options.allowAliases) || "never";
const allowCallbacks = (options && options.allowCallbacks) || "never";
const allowLiterals = (options && options.allowLiterals) || "never";
const allowMappedTypes =
(options && options.allowMappedTypes) || "never";
const unions = [true, "always", "in-unions", "in-unions-and-intersections"];
const intersections = [true, "always", "in-intersections", "in-unions-and-intersections"];
const compositions = ["in-unions", "in-intersections", "in-unions-and-intersections"];
const unions = [
true,
"always",
"in-unions",
"in-unions-and-intersections"
];
const intersections = [
true,
"always",
"in-intersections",
"in-unions-and-intersections"
];
const compositions = [
"in-unions",
"in-intersections",
"in-unions-and-intersections"
];
const aliasTypes = ["TSLastTypeNode", "TSArrayType", "TSTypeReference"];

@@ -94,3 +104,7 @@

function isComposition(node) {
return node && (node.type === "TSUnionType" || node.type === "TSIntersectionType");
return (
node &&
(node.type === "TSUnionType" ||
node.type === "TSIntersectionType")
);
}

@@ -107,6 +121,10 @@

function isSupportedComposition(isTopLevel, compositionType, allowed) {
return compositions.indexOf(allowed) === -1 || (!isTopLevel && (
(compositionType === "TSUnionType" && unions.indexOf(allowed) > -1) ||
(compositionType === "TSIntersectionType" && intersections.indexOf(allowed) > -1)
));
return (
compositions.indexOf(allowed) === -1 ||
(!isTopLevel &&
((compositionType === "TSUnionType" &&
unions.indexOf(allowed) > -1) ||
(compositionType === "TSIntersectionType" &&
intersections.indexOf(allowed) > -1)))
);
}

@@ -121,3 +139,7 @@

function isAlias(node) {
return node && (/Keyword$/.test(node.type) || aliasTypes.indexOf(node.type) > -1);
return (
node &&
(/Keyword$/.test(node.type) ||
aliasTypes.indexOf(node.type) > -1)
);
}

@@ -166,8 +188,14 @@

if (isRoot) {
return type ? `Type ${type} are not allowed` : "Type aliases are not allowed";
return type
? `Type ${type} are not allowed`
: "Type aliases are not allowed";
}
return compositionType === "TSUnionType"
? `${type[0].toUpperCase()}${type.substring(1)} in union types are not allowed`
: `${type[0].toUpperCase()}${type.substring(1)} in intersection types are not allowed`;
? `${type[0].toUpperCase()}${type.substring(
1
)} in union types are not allowed`
: `${type[0].toUpperCase()}${type.substring(
1
)} in intersection types are not allowed`;
}

@@ -186,6 +214,17 @@

if (isAlias(node)) {
if (allowAliases === "never" || (!isSupportedComposition(isTopLevel, compositionType, allowAliases))) {
if (
allowAliases === "never" ||
!isSupportedComposition(
isTopLevel,
compositionType,
allowAliases
)
) {
context.report({
node,
message: getMessage(compositionType, isTopLevel, "aliases")
message: getMessage(
compositionType,
isTopLevel,
"aliases"
)
});

@@ -197,17 +236,43 @@ }

node,
message: getMessage(compositionType, isTopLevel, "callbacks")
message: getMessage(
compositionType,
isTopLevel,
"callbacks"
)
});
}
} else if (isLiteral(node)) {
if (allowLiterals === "never" || (!isSupportedComposition(isTopLevel, compositionType, allowLiterals))) {
if (
allowLiterals === "never" ||
!isSupportedComposition(
isTopLevel,
compositionType,
allowLiterals
)
) {
context.report({
node,
message: getMessage(compositionType, isTopLevel, "literals")
message: getMessage(
compositionType,
isTopLevel,
"literals"
)
});
}
} else if (isMappedType(node)) {
if (allowMappedTypes === "never" || (!isSupportedComposition(isTopLevel, compositionType, allowMappedTypes))) {
if (
allowMappedTypes === "never" ||
!isSupportedComposition(
isTopLevel,
compositionType,
allowMappedTypes
)
) {
context.report({
node,
message: getMessage(compositionType, isTopLevel, "mapped types")
message: getMessage(
compositionType,
isTopLevel,
"mapped types"
)
});

@@ -214,0 +279,0 @@ }

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

docs: {
description: "Prevent TypeScript-specific variables being falsely marked as unused.",
description:
"Prevent TypeScript-specific variables being falsely marked as unused.",
category: "TypeScript",

@@ -58,3 +59,2 @@ recommended: true

create(context) {
//----------------------------------------------------------------------

@@ -75,3 +75,2 @@ // Helpers

node.decorators.forEach(decorator => {
/**

@@ -97,6 +96,12 @@ * Decorator

if (decorator.expression && decorator.expression.callee && decorator.expression.callee.name) {
markVariableAsUsed(context, decorator.expression.callee.name);
if (
decorator.expression &&
decorator.expression.callee &&
decorator.expression.callee.name
) {
markVariableAsUsed(
context,
decorator.expression.callee.name
);
}
});

@@ -116,3 +121,7 @@ }

node.implements.forEach(implementedInterface => {
if (!implementedInterface || !implementedInterface.id || !implementedInterface.id.name) {
if (
!implementedInterface ||
!implementedInterface.id ||
!implementedInterface.id.name
) {
return;

@@ -134,3 +143,2 @@ }

MethodDefinition(node) {
/**

@@ -143,3 +151,7 @@ * Decorators are only supported on class methods, so exit early

if (!tAnc || !anc[tAnc - 1] || anc[tAnc - 1].type !== "ClassBody") {
if (
!tAnc ||
!anc[tAnc - 1] ||
anc[tAnc - 1].type !== "ClassBody"
) {
return;

@@ -156,3 +168,7 @@ }

*/
if (!node.value || !node.value.params || !node.value.params.length) {
if (
!node.value ||
!node.value.params ||
!node.value.params.length
) {
return;

@@ -163,4 +179,3 @@ }

};
}
};

@@ -31,3 +31,3 @@ /**

if (typeof options === "string") {
functions = (options !== "nofunc");
functions = options !== "nofunc";
} else if (typeof options === "object" && options !== null) {

@@ -131,3 +131,4 @@ functions = options.functions !== false;

}
if (FOR_IN_OF_TYPE.test(node.parent.parent.type) &&
if (
FOR_IN_OF_TYPE.test(node.parent.parent.type) &&
isInRange(node.parent.parent.right, location)

@@ -159,3 +160,4 @@ ) {

docs: {
description: "disallow the use of variables before they are defined",
description:
"disallow the use of variables before they are defined",
category: "Variables",

@@ -227,6 +229,9 @@ recommended: false

// - allowed by options.
if (reference.init ||
if (
reference.init ||
!variable ||
variable.identifiers.length === 0 ||
(variable.identifiers[0].range[1] < reference.identifier.range[1] && !isInInitializer(variable, reference)) ||
(variable.identifiers[0].range[1] <
reference.identifier.range[1] &&
!isInInitializer(variable, reference)) ||
!isForbidden(variable, reference)

@@ -273,4 +278,4 @@ ) {

if (context.parserOptions.ecmaVersion >= 6) {
ruleDefinition["BlockStatement:exit"] =
ruleDefinition["SwitchStatement:exit"] = findVariables;
ruleDefinition["BlockStatement:exit"] = findVariables;
ruleDefinition["SwitchStatement:exit"] = findVariables;

@@ -283,5 +288,5 @@ ruleDefinition["ArrowFunctionExpression:exit"] = function(node) {

} else {
ruleDefinition["FunctionExpression:exit"] =
ruleDefinition["FunctionDeclaration:exit"] =
ruleDefinition["ArrowFunctionExpression:exit"] = findVariables;
ruleDefinition["FunctionExpression:exit"] = findVariables;
ruleDefinition["FunctionDeclaration:exit"] = findVariables;
ruleDefinition["ArrowFunctionExpression:exit"] = findVariables;
}

@@ -288,0 +293,0 @@

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

docs: {
description: "Enforces the use of the keyword namespace over module to declare custom TypeScript modules.",
description:
"Enforces the use of the keyword namespace over module to declare custom TypeScript modules.",
category: "TypeScript"

@@ -23,3 +24,2 @@ },

create(context) {
const sourceCode = context.getSourceCode();

@@ -48,3 +48,7 @@

function getStartIndex(node) {
if (node.modifiers && node.modifiers.length > 0 && node.modifiers[0].type === "TSDeclareKeyword") {
if (
node.modifiers &&
node.modifiers.length > 0 &&
node.modifiers[0].type === "TSDeclareKeyword"
) {
return node.range[0] + "declare".length + 1;

@@ -62,3 +66,6 @@ }

if (isTypeScriptModuleDeclaration(node) || /\bnamespace\b/.test(declaration)) {
if (
isTypeScriptModuleDeclaration(node) ||
/\bnamespace\b/.test(declaration)
) {
return;

@@ -69,7 +76,11 @@ }

node,
message: "Use namespace instead of module to declare custom TypeScript modules",
message:
"Use namespace instead of module to declare custom TypeScript modules",
fix(fixer) {
const start = getStartIndex(node);
return fixer.replaceTextRange([start, start + "module".length], "namespace");
return fixer.replaceTextRange(
[start, start + "module".length],
"namespace"
);
}

@@ -76,0 +87,0 @@ });

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

const definition = {
type: "object",
properties: {
before: { type: "boolean" },
after: { type: "boolean" }
},
additionalProperties: false
};
module.exports = {

@@ -25,5 +34,12 @@ meta: {

before: { type: "boolean" },
after: { type: "boolean" }
},
additionalProperties: false
after: { type: "boolean" },
overrides: {
type: "object",
properties: {
colon: definition,
arrow: definition
},
additionalProperties: false
}
}
}

@@ -34,9 +50,20 @@ ]

create(context) {
const sourceCode = context.getSourceCode();
const options = context.options[0] || {};
const before = typeof options.before === "boolean" ? options.before : false;
const after = typeof options.after === "boolean" ? options.after : true;
const overrides = options.overrides || {};
const colonOptions = Object.assign(
{},
{ before: false, after: true },
options,
overrides.colon
);
const arrowOptions = Object.assign(
{},
{ before: true, after: true },
options,
overrides.arrow
);
//----------------------------------------------------------------------

@@ -55,14 +82,21 @@ // Helpers

const nextToken = typeAnnotation.typeAnnotation || typeAnnotation;
const colonToken = sourceCode.getTokenBefore(nextToken);
const previousToken = sourceCode.getTokenBefore(colonToken);
const punctuatorToken = sourceCode.getTokenBefore(nextToken);
const previousToken = sourceCode.getTokenBefore(punctuatorToken);
const previousDelta = colonToken.range[0] - previousToken.range[1];
const nextDelta = nextToken.range[0] - colonToken.range[1];
const previousDelta =
punctuatorToken.range[0] - previousToken.range[1];
const nextDelta = nextToken.range[0] - punctuatorToken.range[1];
const type = punctuatorToken.value;
const before =
type === ":" ? colonOptions.before : arrowOptions.before;
const after =
type === ":" ? colonOptions.after : arrowOptions.after;
if (after && nextDelta === 0) {
context.report({
node: colonToken,
message: "Expected a space after the colon.",
node: punctuatorToken,
message: `Expected a space after the '${type}'`,
fix(fixer) {
return fixer.insertTextAfter(colonToken, " ");
return fixer.insertTextAfter(punctuatorToken, " ");
}

@@ -72,6 +106,9 @@ });

context.report({
node: colonToken,
message: "Unexpected space after the colon.",
node: punctuatorToken,
message: `Unexpected space after the '${type}'`,
fix(fixer) {
return fixer.removeRange([colonToken.range[1], nextToken.range[0]]);
return fixer.removeRange([
punctuatorToken.range[1],
nextToken.range[0]
]);
}

@@ -83,14 +120,4 @@ });

context.report({
node: colonToken,
loc: {
start: {
line: colonToken.loc.start.line,
column: colonToken.loc.start.column - 1
},
end: {
line: colonToken.loc.start.line,
column: colonToken.loc.start.column
}
},
message: "Expected a space before the colon.",
node: punctuatorToken,
message: `Expected a space before the '${type}'`,
fix(fixer) {

@@ -102,16 +129,9 @@ return fixer.insertTextAfter(previousToken, " ");

context.report({
node: colonToken,
loc: {
start: {
line: colonToken.loc.start.line,
column: colonToken.loc.start.column - 1
},
end: {
line: colonToken.loc.start.line,
column: colonToken.loc.start.column
}
},
message: "Unexpected space before the colon.",
node: punctuatorToken,
message: `Unexpected space before the '${type}'`,
fix(fixer) {
return fixer.removeRange([previousToken.range[1], colonToken.range[0]]);
return fixer.removeRange([
previousToken.range[1],
punctuatorToken.range[0]
]);
}

@@ -138,3 +158,2 @@ });

return {
Identifier(node) {

@@ -147,3 +166,7 @@ if (node.typeAnnotation) {

TypeAnnotation(node) {
if (node.typeAnnotation) {
if (
node.typeAnnotation &&
node.typeAnnotation.type !== "TSFunctionType" &&
node.parent.type !== "TSAsExpression"
) {
checkTypeAnnotationSpacing(node.typeAnnotation);

@@ -150,0 +173,0 @@ }

{
"name": "eslint-plugin-typescript",
"version": "0.5.0",
"version": "0.6.0",
"description": "TypeScript plugin for ESLint",

@@ -15,5 +15,6 @@ "keywords": [

"lint": "eslint lib/ tests/",
"lint:fix": "eslint lib/ test/ --fix",
"lint:fix": "eslint lib/ tests/ --fix",
"mocha": "mocha tests --recursive",
"test": "npm run lint && npm run mocha"
"test": "npm run lint && npm run mocha",
"precommit": "npm test && lint-staged"
},

@@ -24,9 +25,20 @@ "dependencies": {

"devDependencies": {
"eslint": "^4.1.1",
"eslint": "^4.5.0",
"eslint-config-eslint": "^4.0.0",
"eslint-plugin-node": "^5.1.0",
"mocha": "^3.4.2",
"typescript": "~2.3.0",
"typescript-eslint-parser": "^4.0.0"
"eslint-config-prettier": "^2.3.0",
"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": "^6.0.1"
},
"lint-staged": {
"*.js": [
"prettier --write",
"git add"
]
},
"engines": {

@@ -33,0 +45,0 @@ "node": ">=4"

@@ -52,14 +52,18 @@ # eslint-plugin-typescript

* `typescript/type-annotation-spacing` - enforces one space after the colon and zero spaces before the colon of a type annotation.
* `typescript/explicit-member-accessibility` - enforces accessibility modifiers on class properties and methods.
* `typescript/interface-name-prefix` - enforces interface names are prefixed.
* `typescript/no-triple-slash-reference` - enforces `/// <reference />` is not used.
* `typescript/no-explicit-any` - enforces the any type is not used.
* `typescript/no-angle-bracket-type-assertion` - enforces the use of `as Type` assertions instead of `<Type>` assertions.
* `typescript/no-namespace` - disallows the use of custom TypeScript modules and namespaces.
* `typescript/no-use-before-define` - disallows the use of variables before they are defined
* `typescript/prefer-namespace-keyword` - enforces the use of the keyword `namespace` over `module` to declare custom TypeScript modules.
* `typescript/no-type-literal` - disallows the use of type aliases.
* `typescript/member-ordering` - enforces a standard member declaration order.
* `typescript/no-unused-vars` - prevents TypeScript-specific constructs from being erroneously flagged as unused
* `typescript/adjacent-overload-signatures` - enforces member overloads to be consecutive.
* [`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)

@@ -14,3 +14,2 @@ /**

//------------------------------------------------------------------------------

@@ -26,4 +25,65 @@ // Tests

code: `
function foo(s: string) {}
function foo(n: number) {}
export const foo = "a", bar = "b";
export interface Foo {}
export class Foo {}
`,
parser: "typescript-eslint-parser"
},
{
code: `
export interface Foo {}
export const foo = "a", bar = "b";
export class Foo {}
`,
parser: "typescript-eslint-parser"
},
{
code: `
const foo = "a", bar = "b";
interface Foo {}
class Foo {}
`,
parser: "typescript-eslint-parser"
},
{
code: `
interface Foo {}
const foo = "a", bar = "b";
class Foo {}
`,
parser: "typescript-eslint-parser"
},
{
code: `
export class Foo {}
export class Bar {}
export type FooBar = Foo | Bar;
`,
parser: "typescript-eslint-parser"
},
{
code: `
export interface Foo {}
export class Foo {}
export class Bar {}
export type FooBar = Foo | Bar;
`,
parser: "typescript-eslint-parser"
},
{
code: `
export function foo(s: string);
export function foo(n: number);
export function foo(sn: string | number) {}
export function bar(): void {}
export function baz(): void {}
`,
parser: "typescript-eslint-parser"
},
{
code: `
function foo(s: string);
function foo(n: number);
function foo(sn: string | number) {}

@@ -145,2 +205,13 @@ function bar(): void {}

code: `
interface Foo {
new(s: string);
new(n: number);
new(sn: string | number);
foo(): void;
}
`,
parser: "typescript-eslint-parser"
},
{
code: `
class Foo {

@@ -197,4 +268,38 @@ constructor(s: string);

code: `
function foo(s: string) {}
function foo(n: number) {}
export function foo(s: string);
export function foo(n: number);
export function bar(): void {}
export function baz(): void {}
export function foo(sn: string | number) {}
`,
parser: "typescript-eslint-parser",
errors: [
{
message: "All 'foo' signatures should be adjacent",
line: 6,
column: 1
}
]
},
{
code: `
export function foo(s: string);
export function foo(n: number);
export type bar = number;
export type baz = number | string;
export function foo(sn: string | number) {}
`,
parser: "typescript-eslint-parser",
errors: [
{
message: "All 'foo' signatures should be adjacent",
line: 6,
column: 1
}
]
},
{
code: `
function foo(s: string);
function foo(n: number);
function bar(): void {}

@@ -215,2 +320,19 @@ function baz(): void {}

code: `
function foo(s: string);
function foo(n: number);
type bar = number;
type baz = number | string;
function foo(sn: string | number) {}
`,
parser: "typescript-eslint-parser",
errors: [
{
message: "All 'foo' signatures should be adjacent",
line: 6,
column: 1
}
]
},
{
code: `
function foo(s: string) {}

@@ -233,2 +355,39 @@ function foo(n: number) {}

code: `
function foo(s: string) {}
function foo(n: number) {}
class Bar {}
function foo(sn: string | number) {}
`,
parser: "typescript-eslint-parser",
errors: [
{
message: "All 'foo' signatures should be adjacent",
line: 5,
column: 1
}
]
},
{
code: `
function foo(s: string) {}
function foo(n: number) {}
function foo(sn: string | number) {}
class Bar {
foo(s: string);
foo(n: number);
name: string;
foo(sn: string | number) { }
}
`,
parser: "typescript-eslint-parser",
errors: [
{
message: "All 'foo' signatures should be adjacent",
line: 9,
column: 5
}
]
},
{
code: `
declare function foo(s: string);

@@ -272,3 +431,3 @@ declare function foo(n: number);

export function bar(): void;
export function baz(): void;
export function baz(): void;
export function foo(sn: string | number): void;

@@ -310,3 +469,3 @@ }

declare namespace Foo {
export function foo(s: string): void;
export function foo(s: string): void;
export function foo(n: number): void;

@@ -526,2 +685,45 @@ export function bar(): void;

code: `
interface Foo {
new(s: string);
new(n: number);
foo(): void;
bar(): void;
new(sn: string | number);
}
`,
parser: "typescript-eslint-parser",
errors: [
{
message: "All 'new' signatures should be adjacent",
line: 7,
column: 5
}
]
},
{
code: `
interface Foo {
new(s: string);
foo(): void;
new(n: number);
bar(): void;
new(sn: string | number);
}
`,
parser: "typescript-eslint-parser",
errors: [
{
message: "All 'new' signatures should be adjacent",
line: 5,
column: 5
},
{
message: "All 'new' signatures should be adjacent",
line: 7,
column: 5
}
]
},
{
code: `
class Foo {

@@ -528,0 +730,0 @@ constructor(s: string);

@@ -14,3 +14,2 @@ /**

//------------------------------------------------------------------------------

@@ -23,3 +22,2 @@ // Tests

ruleTester.run("explicit-member-accessibility", rule, {
valid: [

@@ -50,7 +48,10 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Missing accessibility modifier on class property x.",
line: 3,
column: 3
}]
errors: [
{
message:
"Missing accessibility modifier on class property x.",
line: 3,
column: 3
}
]
},

@@ -67,9 +68,12 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Missing accessibility modifier on method definition getX.",
line: 4,
column: 3
}]
errors: [
{
message:
"Missing accessibility modifier on method definition getX.",
line: 4,
column: 3
}
]
}
]
});

@@ -14,3 +14,2 @@ /**

//------------------------------------------------------------------------------

@@ -23,3 +22,2 @@ // Tests

ruleTester.run("interface-name-prefix", rule, {
valid: [

@@ -79,7 +77,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Interface name must not be prefixed with \"I\"",
line: 2,
column: 11
}]
errors: [
{
message: 'Interface name must not be prefixed with "I"',
line: 2,
column: 11
}
]
},

@@ -94,7 +94,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Interface name must be prefixed with \"I\"",
line: 2,
column: 11
}]
errors: [
{
message: 'Interface name must be prefixed with "I"',
line: 2,
column: 11
}
]
},

@@ -109,7 +111,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Interface name must be prefixed with \"I\"",
line: 2,
column: 11
}]
errors: [
{
message: 'Interface name must be prefixed with "I"',
line: 2,
column: 11
}
]
},

@@ -124,7 +128,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Interface name must not be prefixed with \"I\"",
line: 2,
column: 11
}]
errors: [
{
message: 'Interface name must not be prefixed with "I"',
line: 2,
column: 11
}
]
},

@@ -139,9 +145,11 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Interface name must not be prefixed with \"I\"",
line: 2,
column: 11
}]
errors: [
{
message: 'Interface name must not be prefixed with "I"',
line: 2,
column: 11
}
]
}
]
});

@@ -14,3 +14,2 @@ /**

//------------------------------------------------------------------------------

@@ -23,3 +22,2 @@ // Tests

ruleTester.run("no-angle-bracket-type-assertion", rule, {
valid: [

@@ -53,3 +51,4 @@ {

{
message: "Prefer 'as number' instead of '<number>' when doing type assertions",
message:
"Prefer 'as number' instead of '<number>' when doing type assertions",
row: 1,

@@ -68,3 +67,4 @@ column: 20

{
message: "Prefer 'as number' instead of '<number>' when doing type assertions",
message:
"Prefer 'as number' instead of '<number>' when doing type assertions",
row: 3,

@@ -80,3 +80,4 @@ column: 20

{
message: "Prefer 'as Array<number>' instead of '<Array<number>>' when doing type assertions",
message:
"Prefer 'as Array<number>' instead of '<Array<number>>' when doing type assertions",
row: 1,

@@ -128,3 +129,4 @@ column: 27

{
message: "Prefer 'as Foo' instead of '<Foo>' when doing type assertions",
message:
"Prefer 'as Foo' instead of '<Foo>' when doing type assertions",
row: 8,

@@ -134,3 +136,4 @@ column: 13

{
message: "Prefer 'as Foo' instead of '<Foo>' when doing type assertions",
message:
"Prefer 'as Foo' instead of '<Foo>' when doing type assertions",
row: 9,

@@ -146,3 +149,4 @@ column: 13

{
message: "Prefer 'as number' instead of '<number>' when doing type assertions",
message:
"Prefer 'as number' instead of '<number>' when doing type assertions",
row: 1,

@@ -161,3 +165,4 @@ column: 20

{
message: "Prefer 'as number' instead of '<number>' when doing type assertions",
message:
"Prefer 'as number' instead of '<number>' when doing type assertions",
row: 3,

@@ -173,3 +178,4 @@ column: 20

{
message: "Prefer 'as Array<number>' instead of '<Array<number>>' when doing type assertions",
message:
"Prefer 'as Array<number>' instead of '<Array<number>>' when doing type assertions",
row: 1,

@@ -191,3 +197,4 @@ column: 27

{
message: "Prefer 'as A' instead of '<A>' when doing type assertions",
message:
"Prefer 'as A' instead of '<A>' when doing type assertions",
row: 6,

@@ -213,3 +220,4 @@ column: 15

{
message: "Prefer 'as A' instead of '<A>' when doing type assertions",
message:
"Prefer 'as A' instead of '<A>' when doing type assertions",
row: 9,

@@ -216,0 +224,0 @@ column: 14

@@ -21,3 +21,2 @@ /**

ruleTester.run("no-explicit-any", rule, {
valid: [

@@ -241,7 +240,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 1,
column: 15
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 1,
column: 15
}
]
},

@@ -251,7 +252,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 1,
column: 21
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 1,
column: 21
}
]
},

@@ -261,7 +264,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 1,
column: 27
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 1,
column: 27
}
]
},

@@ -271,7 +276,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 1,
column: 21
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 1,
column: 21
}
]
},

@@ -281,7 +288,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 1,
column: 31
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 1,
column: 31
}
]
},

@@ -291,7 +300,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 1,
column: 25
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 1,
column: 25
}
]
},

@@ -317,7 +328,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 1,
column: 33
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 1,
column: 33
}
]
},

@@ -327,7 +340,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 1,
column: 27
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 1,
column: 27
}
]
},

@@ -341,7 +356,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 30
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 30
}
]
},

@@ -355,7 +372,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 14
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 14
}
]
},

@@ -369,7 +388,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 20
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 20
}
]
},

@@ -383,7 +404,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 14
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 14
}
]
},

@@ -397,7 +420,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 26
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 26
}
]
},

@@ -411,7 +436,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 20
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 20
}
]
},

@@ -425,7 +452,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 14
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 14
}
]
},

@@ -439,7 +468,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 20
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 20
}
]
},

@@ -453,7 +484,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 14
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 14
}
]
},

@@ -467,7 +500,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 26
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 26
}
]
},

@@ -481,7 +516,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 20
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 20
}
]
},

@@ -495,7 +532,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 14
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 14
}
]
},

@@ -509,7 +548,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 20
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 20
}
]
},

@@ -523,7 +564,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 14
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 14
}
]
},

@@ -537,7 +580,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 26
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 26
}
]
},

@@ -551,7 +596,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 20
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 20
}
]
},

@@ -565,7 +612,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 23
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 23
}
]
},

@@ -579,7 +628,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 29
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 29
}
]
},

@@ -593,7 +644,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 23
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 23
}
]
},

@@ -607,7 +660,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 35
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 35
}
]
},

@@ -621,7 +676,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 29
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 29
}
]
},

@@ -635,7 +692,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 23
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 23
}
]
},

@@ -649,7 +708,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 29
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 29
}
]
},

@@ -663,7 +724,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 23
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 23
}
]
},

@@ -677,7 +740,9 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 35
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 35
}
]
},

@@ -691,9 +756,11 @@ {

parser: "typescript-eslint-parser",
errors: [{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 29
}]
errors: [
{
message: "Unexpected any. Specify a different type.",
line: 3,
column: 29
}
]
}
]
});

@@ -14,3 +14,2 @@ /**

//------------------------------------------------------------------------------

@@ -45,3 +44,4 @@ // Tests

{
message: "ES2015 module syntax is preferred over custom TypeScript modules and namespaces",
message:
"ES2015 module syntax is preferred over custom TypeScript modules and namespaces",
row: 1,

@@ -57,3 +57,4 @@ column: 1

{
message: "ES2015 module syntax is preferred over custom TypeScript modules and namespaces",
message:
"ES2015 module syntax is preferred over custom TypeScript modules and namespaces",
row: 1,

@@ -70,3 +71,4 @@ column: 1

{
message: "ES2015 module syntax is preferred over custom TypeScript modules and namespaces",
message:
"ES2015 module syntax is preferred over custom TypeScript modules and namespaces",
row: 1,

@@ -83,3 +85,4 @@ column: 1

{
message: "ES2015 module syntax is preferred over custom TypeScript modules and namespaces",
message:
"ES2015 module syntax is preferred over custom TypeScript modules and namespaces",
row: 1,

@@ -95,3 +98,4 @@ column: 1

{
message: "ES2015 module syntax is preferred over custom TypeScript modules and namespaces",
message:
"ES2015 module syntax is preferred over custom TypeScript modules and namespaces",
row: 1,

@@ -107,3 +111,4 @@ column: 1

{
message: "ES2015 module syntax is preferred over custom TypeScript modules and namespaces",
message:
"ES2015 module syntax is preferred over custom TypeScript modules and namespaces",
row: 1,

@@ -120,3 +125,4 @@ column: 1

{
message: "ES2015 module syntax is preferred over custom TypeScript modules and namespaces",
message:
"ES2015 module syntax is preferred over custom TypeScript modules and namespaces",
row: 1,

@@ -133,3 +139,4 @@ column: 1

{
message: "ES2015 module syntax is preferred over custom TypeScript modules and namespaces",
message:
"ES2015 module syntax is preferred over custom TypeScript modules and namespaces",
row: 1,

@@ -136,0 +143,0 @@ column: 1

@@ -14,3 +14,2 @@ /**

//------------------------------------------------------------------------------

@@ -23,3 +22,2 @@ // Tests

ruleTester.run("no-triple-slash-reference", rule, {
valid: [

@@ -31,3 +29,3 @@ {

{
code: "// <reference path=\"Animal\" />",
code: '// <reference path="Animal" />',
parser: "typescript-eslint-parser"

@@ -38,11 +36,13 @@ }

{
code: "/// <reference path=\"Animal\" />",
code: '/// <reference path="Animal" />',
parser: "typescript-eslint-parser",
errors: [{
message: "Do not use a triple slash reference",
line: 1,
column: 1
}]
errors: [
{
message: "Do not use a triple slash reference",
line: 1,
column: 1
}
]
}
]
});

@@ -35,3 +35,2 @@ /**

ruleTester.run("no-unused-vars", ruleNoUnusedVars, {
valid: [

@@ -190,9 +189,12 @@ {

parser,
errors: [{
message: "'ClassDecoratorFactory' is defined but never used.",
line: 1,
column: 10
}]
errors: [
{
message:
"'ClassDecoratorFactory' is defined but never used.",
line: 1,
column: 10
}
]
}
]
});

@@ -28,4 +28,10 @@ /**

"function a() { alert(arguments);}",
{ code: "a(); function a() { alert(arguments); }", options: ["nofunc"] },
{ code: "(() => { var a = 42; alert(a); })();", parserOptions: { ecmaVersion: 6 } },
{
code: "a(); function a() { alert(arguments); }",
options: ["nofunc"]
},
{
code: "(() => { var a = 42; alert(a); })();",
parserOptions: { ecmaVersion: 6 }
},
{ code: "a(); try { throw new Error() } catch (a) {}" },

@@ -42,11 +48,35 @@ { code: "class A {} new A();", parserOptions: { ecmaVersion: 6 } },

// Block-level bindings
{ code: "\"use strict\"; a(); { function a() {} }", parserOptions: { ecmaVersion: 6 } },
{ code: "\"use strict\"; { a(); function a() {} }", options: ["nofunc"], parserOptions: { ecmaVersion: 6 } },
{ code: "switch (foo) { case 1: { a(); } default: { let a; }}", parserOptions: { ecmaVersion: 6 } },
{ code: "a(); { let a = function () {}; }", parserOptions: { ecmaVersion: 6 } },
{
code: '"use strict"; a(); { function a() {} }',
parserOptions: { ecmaVersion: 6 }
},
{
code: '"use strict"; { a(); function a() {} }',
options: ["nofunc"],
parserOptions: { ecmaVersion: 6 }
},
{
code: "switch (foo) { case 1: { a(); } default: { let a; }}",
parserOptions: { ecmaVersion: 6 }
},
{
code: "a(); { let a = function () {}; }",
parserOptions: { ecmaVersion: 6 }
},
// object style options
{ code: "a(); function a() { alert(arguments); }", options: [{ functions: false }] },
{ code: "\"use strict\"; { a(); function a() {} }", options: [{ functions: false }], parserOptions: { ecmaVersion: 6 } },
{ code: "function foo() { new A(); } class A {};", options: [{ classes: false }], parserOptions: { ecmaVersion: 6 } },
{
code: "a(); function a() { alert(arguments); }",
options: [{ functions: false }]
},
{
code: '"use strict"; { a(); function a() {} }',
options: [{ functions: false }],
parserOptions: { ecmaVersion: 6 }
},
{
code: "function foo() { new A(); } class A {};",
options: [{ classes: false }],
parserOptions: { ecmaVersion: 6 }
},

@@ -72,45 +102,377 @@ // "variables" option

invalid: [
{ code: "a++; var a=19;", parserOptions: { sourceType: "module" }, errors: [{ message: "'a' was used before it was defined.", type: "Identifier" }] },
{ code: "a++; var a=19;", parserOptions: { parserOptions: { ecmaVersion: 6 } }, errors: [{ message: "'a' was used before it was defined.", type: "Identifier" }] },
{ code: "a++; var a=19;", errors: [{ message: "'a' was used before it was defined.", type: "Identifier" }] },
{ code: "a(); var a=function() {};", errors: [{ message: "'a' was used before it was defined.", type: "Identifier" }] },
{ code: "alert(a[1]); var a=[1,3];", errors: [{ message: "'a' was used before it was defined.", type: "Identifier" }] },
{ code: "a(); function a() { alert(b); var b=10; a(); }", errors: [{ message: "'a' was used before it was defined.", type: "Identifier" }, { message: "'b' was used before it was defined.", type: "Identifier" }] },
{ code: "a(); var a=function() {};", options: ["nofunc"], errors: [{ message: "'a' was used before it was defined.", type: "Identifier" }] },
{ code: "(() => { alert(a); var a = 42; })();", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "'a' was used before it was defined.", type: "Identifier" }] },
{ code: "(() => a())(); function a() { }", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "'a' was used before it was defined.", type: "Identifier" }] },
{ code: "\"use strict\"; a(); { function a() {} }", errors: [{ message: "'a' was used before it was defined.", type: "Identifier" }] },
{ code: "a(); try { throw new Error() } catch (foo) {var a;}", errors: [{ message: "'a' was used before it was defined.", type: "Identifier" }] },
{ code: "var f = () => a; var a;", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "'a' was used before it was defined.", type: "Identifier" }] },
{ code: "new A(); class A {};", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "'A' was used before it was defined.", type: "Identifier" }] },
{ code: "function foo() { new A(); } class A {};", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "'A' was used before it was defined.", type: "Identifier" }] },
{ code: "new A(); var A = class {};", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "'A' was used before it was defined.", type: "Identifier" }] },
{ code: "function foo() { new A(); } var A = class {};", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "'A' was used before it was defined.", type: "Identifier" }] },
{
code: "a++; var a=19;",
parserOptions: { sourceType: "module" },
errors: [
{
message: "'a' was used before it was defined.",
type: "Identifier"
}
]
},
{
code: "a++; var a=19;",
parserOptions: { parserOptions: { ecmaVersion: 6 } },
errors: [
{
message: "'a' was used before it was defined.",
type: "Identifier"
}
]
},
{
code: "a++; var a=19;",
errors: [
{
message: "'a' was used before it was defined.",
type: "Identifier"
}
]
},
{
code: "a(); var a=function() {};",
errors: [
{
message: "'a' was used before it was defined.",
type: "Identifier"
}
]
},
{
code: "alert(a[1]); var a=[1,3];",
errors: [
{
message: "'a' was used before it was defined.",
type: "Identifier"
}
]
},
{
code: "a(); function a() { alert(b); var b=10; a(); }",
errors: [
{
message: "'a' was used before it was defined.",
type: "Identifier"
},
{
message: "'b' was used before it was defined.",
type: "Identifier"
}
]
},
{
code: "a(); var a=function() {};",
options: ["nofunc"],
errors: [
{
message: "'a' was used before it was defined.",
type: "Identifier"
}
]
},
{
code: "(() => { alert(a); var a = 42; })();",
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "'a' was used before it was defined.",
type: "Identifier"
}
]
},
{
code: "(() => a())(); function a() { }",
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "'a' was used before it was defined.",
type: "Identifier"
}
]
},
{
code: '"use strict"; a(); { function a() {} }',
errors: [
{
message: "'a' was used before it was defined.",
type: "Identifier"
}
]
},
{
code: "a(); try { throw new Error() } catch (foo) {var a;}",
errors: [
{
message: "'a' was used before it was defined.",
type: "Identifier"
}
]
},
{
code: "var f = () => a; var a;",
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "'a' was used before it was defined.",
type: "Identifier"
}
]
},
{
code: "new A(); class A {};",
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "'A' was used before it was defined.",
type: "Identifier"
}
]
},
{
code: "function foo() { new A(); } class A {};",
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "'A' was used before it was defined.",
type: "Identifier"
}
]
},
{
code: "new A(); var A = class {};",
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "'A' was used before it was defined.",
type: "Identifier"
}
]
},
{
code: "function foo() { new A(); } var A = class {};",
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "'A' was used before it was defined.",
type: "Identifier"
}
]
},
// Block-level bindings
{ code: "a++; { var a; }", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "'a' was used before it was defined.", type: "Identifier" }] },
{ code: "\"use strict\"; { a(); function a() {} }", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "'a' was used before it was defined.", type: "Identifier" }] },
{ code: "{a; let a = 1}", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "'a' was used before it was defined.", type: "Identifier" }] },
{ code: "switch (foo) { case 1: a();\n default: \n let a;}", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "'a' was used before it was defined.", type: "Identifier" }] },
{ code: "if (true) { function foo() { a; } let a;}", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "'a' was used before it was defined.", type: "Identifier" }] },
{
code: "a++; { var a; }",
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "'a' was used before it was defined.",
type: "Identifier"
}
]
},
{
code: '"use strict"; { a(); function a() {} }',
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "'a' was used before it was defined.",
type: "Identifier"
}
]
},
{
code: "{a; let a = 1}",
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "'a' was used before it was defined.",
type: "Identifier"
}
]
},
{
code: "switch (foo) { case 1: a();\n default: \n let a;}",
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "'a' was used before it was defined.",
type: "Identifier"
}
]
},
{
code: "if (true) { function foo() { a; } let a;}",
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "'a' was used before it was defined.",
type: "Identifier"
}
]
},
// object style options
{ code: "a(); var a=function() {};", options: [{ functions: false, classes: false }], errors: [{ message: "'a' was used before it was defined.", type: "Identifier" }] },
{ code: "new A(); class A {};", options: [{ functions: false, classes: false }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "'A' was used before it was defined.", type: "Identifier" }] },
{ code: "new A(); var A = class {};", options: [{ classes: false }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "'A' was used before it was defined.", type: "Identifier" }] },
{ code: "function foo() { new A(); } var A = class {};", options: [{ classes: false }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "'A' was used before it was defined.", type: "Identifier" }] },
{
code: "a(); var a=function() {};",
options: [{ functions: false, classes: false }],
errors: [
{
message: "'a' was used before it was defined.",
type: "Identifier"
}
]
},
{
code: "new A(); class A {};",
options: [{ functions: false, classes: false }],
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "'A' was used before it was defined.",
type: "Identifier"
}
]
},
{
code: "new A(); var A = class {};",
options: [{ classes: false }],
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "'A' was used before it was defined.",
type: "Identifier"
}
]
},
{
code: "function foo() { new A(); } var A = class {};",
options: [{ classes: false }],
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "'A' was used before it was defined.",
type: "Identifier"
}
]
},
// invalid initializers
{ code: "var a = a;", errors: [{ message: "'a' was used before it was defined.", type: "Identifier" }] },
{ code: "let a = a + b;", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "'a' was used before it was defined.", type: "Identifier" }] },
{ code: "const a = foo(a);", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "'a' was used before it was defined.", type: "Identifier" }] },
{ code: "function foo(a = a) {}", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "'a' was used before it was defined.", type: "Identifier" }] },
{ code: "var {a = a} = [];", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "'a' was used before it was defined.", type: "Identifier" }] },
{ code: "var [a = a] = [];", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "'a' was used before it was defined.", type: "Identifier" }] },
{ code: "var {b = a, a} = {};", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "'a' was used before it was defined.", type: "Identifier" }] },
{ code: "var [b = a, a] = {};", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "'a' was used before it was defined.", type: "Identifier" }] },
{ code: "var {a = 0} = a;", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "'a' was used before it was defined.", type: "Identifier" }] },
{ code: "var [a = 0] = a;", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "'a' was used before it was defined.", type: "Identifier" }] },
{ code: "for (var a in a) {}", errors: [{ message: "'a' was used before it was defined.", type: "Identifier" }] },
{ code: "for (var a of a) {}", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "'a' was used before it was defined.", type: "Identifier" }] },
{
code: "var a = a;",
errors: [
{
message: "'a' was used before it was defined.",
type: "Identifier"
}
]
},
{
code: "let a = a + b;",
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "'a' was used before it was defined.",
type: "Identifier"
}
]
},
{
code: "const a = foo(a);",
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "'a' was used before it was defined.",
type: "Identifier"
}
]
},
{
code: "function foo(a = a) {}",
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "'a' was used before it was defined.",
type: "Identifier"
}
]
},
{
code: "var {a = a} = [];",
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "'a' was used before it was defined.",
type: "Identifier"
}
]
},
{
code: "var [a = a] = [];",
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "'a' was used before it was defined.",
type: "Identifier"
}
]
},
{
code: "var {b = a, a} = {};",
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "'a' was used before it was defined.",
type: "Identifier"
}
]
},
{
code: "var [b = a, a] = {};",
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "'a' was used before it was defined.",
type: "Identifier"
}
]
},
{
code: "var {a = 0} = a;",
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "'a' was used before it was defined.",
type: "Identifier"
}
]
},
{
code: "var [a = 0] = a;",
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "'a' was used before it was defined.",
type: "Identifier"
}
]
},
{
code: "for (var a in a) {}",
errors: [
{
message: "'a' was used before it was defined.",
type: "Identifier"
}
]
},
{
code: "for (var a of a) {}",
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "'a' was used before it was defined.",
type: "Identifier"
}
]
},

@@ -122,3 +484,8 @@ // "variables" option

options: [{ variables: false }],
errors: [{ message: "'bar' was used before it was defined.", type: "Identifier" }]
errors: [
{
message: "'bar' was used before it was defined.",
type: "Identifier"
}
]
},

@@ -128,5 +495,10 @@ {

options: [{ variables: false }],
errors: [{ message: "'foo' was used before it was defined.", type: "Identifier" }]
errors: [
{
message: "'foo' was used before it was defined.",
type: "Identifier"
}
]
}
]
});

@@ -14,3 +14,2 @@ /**

//------------------------------------------------------------------------------

@@ -43,3 +42,4 @@ // Tests

{
message: "Use namespace instead of module to declare custom TypeScript modules",
message:
"Use namespace instead of module to declare custom TypeScript modules",
output: "namespace foo { }",

@@ -56,3 +56,4 @@ row: 1,

{
message: "Use namespace instead of module to declare custom TypeScript modules",
message:
"Use namespace instead of module to declare custom TypeScript modules",
output: "declare namespace foo { }",

@@ -73,3 +74,4 @@ row: 1,

{
message: "Use namespace instead of module to declare custom TypeScript modules",
message:
"Use namespace instead of module to declare custom TypeScript modules",
output: "declare namespace foo { }",

@@ -80,3 +82,4 @@ row: 2,

{
message: "Use namespace instead of module to declare custom TypeScript modules",
message:
"Use namespace instead of module to declare custom TypeScript modules",
output: `

@@ -83,0 +86,0 @@ declare namespace foo {

Sorry, the diff of this file is not supported yet

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

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

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