eslint-plugin-typescript
Advanced tools
Comparing version 0.1.0 to 0.3.0
@@ -6,3 +6,3 @@ # Enforces spacing around type annotations (type-annotation-spacing) | ||
```ts | ||
var foo: string = "bar"; | ||
let foo: string = "bar"; | ||
@@ -23,3 +23,3 @@ function foo(a: string): string { | ||
```ts | ||
var foo:string = "bar"; | ||
let foo:string = "bar"; | ||
@@ -34,3 +34,3 @@ function foo(a : string):string { | ||
```js | ||
var foo: string = "bar"; | ||
let foo: string = "bar"; | ||
@@ -37,0 +37,0 @@ function foo(a: string): string { |
@@ -11,4 +11,4 @@ /** | ||
var requireIndex = require("requireindex"), | ||
path = require("path"); | ||
const requireIndex = require("requireindex"); | ||
const path = require("path"); | ||
@@ -15,0 +15,0 @@ //------------------------------------------------------------------------------ |
@@ -20,3 +20,3 @@ /** | ||
create: function(context) { | ||
create(context) { | ||
@@ -37,3 +37,3 @@ //---------------------------------------------------------------------- | ||
node: methodDefinition, | ||
message: "Missing accessibility modifier on method definition " + methodDefinition.key.name + "." | ||
message: `Missing accessibility modifier on method definition ${methodDefinition.key.name}.` | ||
}); | ||
@@ -53,3 +53,3 @@ } | ||
node: classProperty, | ||
message: "Missing accessibility modifier on class property " + classProperty.key.name + "." | ||
message: `Missing accessibility modifier on class property ${classProperty.key.name}.` | ||
}); | ||
@@ -56,0 +56,0 @@ } |
@@ -21,3 +21,3 @@ /** | ||
create: function(context) { | ||
create(context) { | ||
@@ -38,13 +38,28 @@ const sourceCode = context.getSourceCode(); | ||
function checkTypeAnnotationSpacing(typeAnnotation) { | ||
const colonToken = sourceCode.getTokenBefore(typeAnnotation), | ||
let colonToken = typeAnnotation, | ||
previousToken = sourceCode.getTokenBefore(typeAnnotation); | ||
if (previousToken.type === "Punctuator") { | ||
colonToken = previousToken; | ||
previousToken = sourceCode.getTokenBefore(colonToken); | ||
if (typeAnnotation.range[0] - colonToken.range[1] === 0) { | ||
context.report({ | ||
node: typeAnnotation, | ||
message: "Expected a space after the colon.", | ||
fix(fixer) { | ||
return fixer.insertTextAfter(colonToken, " "); | ||
} | ||
}); | ||
if (typeAnnotation.range[0] - colonToken.range[1] === 0) { | ||
context.report({ | ||
node: typeAnnotation, | ||
message: "Expected a space after the colon.", | ||
fix(fixer) { | ||
return fixer.insertTextAfter(colonToken, " "); | ||
} | ||
}); | ||
} | ||
} else { | ||
if (typeAnnotation.typeAnnotation.range[0] - typeAnnotation.range[0] === 1) { | ||
context.report({ | ||
node: typeAnnotation, | ||
message: "Expected a space after the colon.", | ||
fix(fixer) { | ||
return fixer.insertTextAfterRange([typeAnnotation.range[0], typeAnnotation.typeAnnotation.range[0]], " "); | ||
} | ||
}); | ||
} | ||
} | ||
@@ -51,0 +66,0 @@ |
{ | ||
"name": "eslint-plugin-typescript", | ||
"version": "0.1.0", | ||
"version": "0.3.0", | ||
"description": "TypeScript plugin for ESLint", | ||
@@ -15,3 +15,5 @@ "keywords": [ | ||
"lint": "eslint lib/", | ||
"test": "npm run lint && mocha tests --recursive" | ||
"lint:fix": "eslint --fix lib/", | ||
"mocha": "mocha tests --recursive", | ||
"test": "npm run lint && npm run mocha" | ||
}, | ||
@@ -22,6 +24,8 @@ "dependencies": { | ||
"devDependencies": { | ||
"eslint": "~3.0.0", | ||
"eslint-config-eslint": "^3.0.0", | ||
"mocha": "^2.4.5", | ||
"typescript-eslint-parser": "^0.4.0" | ||
"eslint": "^4.1.1", | ||
"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" | ||
}, | ||
@@ -28,0 +32,0 @@ "engines": { |
@@ -54,1 +54,7 @@ # eslint-plugin-typescript | ||
* `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/prefer-namespace-keyword` - enforces the use of the keyword `namespace` over `module` to declare custom TypeScript modules. |
@@ -11,3 +11,3 @@ /** | ||
var rule = require("../../../lib/rules/explicit-member-accessibility"), | ||
let rule = require("../../../lib/rules/explicit-member-accessibility"), | ||
RuleTester = require("eslint").RuleTester; | ||
@@ -20,3 +20,3 @@ | ||
var ruleTester = new RuleTester(); | ||
let ruleTester = new RuleTester(); | ||
ruleTester.run("explicit-member-accessibility", rule, { | ||
@@ -23,0 +23,0 @@ |
@@ -11,3 +11,3 @@ /** | ||
var rule = require("../../../lib/rules/type-annotation-spacing"), | ||
let rule = require("../../../lib/rules/type-annotation-spacing"), | ||
RuleTester = require("eslint").RuleTester; | ||
@@ -20,3 +20,3 @@ | ||
var ruleTester = new RuleTester(); | ||
let ruleTester = new RuleTester(); | ||
ruleTester.run("type-annotation-spacing", rule, { | ||
@@ -26,3 +26,3 @@ | ||
{ | ||
code: "var foo: string;", | ||
code: "let foo: string;", | ||
parser: "typescript-eslint-parser" | ||
@@ -35,3 +35,3 @@ }, | ||
{ | ||
code: "function foo(a:string) {}", | ||
code: "function foo(a: string) {}", | ||
parser: "typescript-eslint-parser" | ||
@@ -43,5 +43,5 @@ } | ||
{ | ||
code: "var foo : string;", | ||
code: "let foo : string;", | ||
parser: "typescript-eslint-parser", | ||
output: "var foo: string;", | ||
output: "let foo: string;", | ||
errors: [{ | ||
@@ -54,5 +54,5 @@ message: "Unexpected space before the colon.", | ||
{ | ||
code: "var foo:string;", | ||
code: "let foo:string;", | ||
parser: "typescript-eslint-parser", | ||
output: "var foo: string;", | ||
output: "let foo: string;", | ||
errors: [{ | ||
@@ -75,5 +75,5 @@ message: "Expected a space after the colon.", | ||
{ | ||
code: "var foo = function():string {}", | ||
code: "let foo = function():string {}", | ||
parser: "typescript-eslint-parser", | ||
output: "var foo = function(): string {}", | ||
output: "let foo = function(): string {}", | ||
errors: [{ | ||
@@ -86,5 +86,5 @@ message: "Expected a space after the colon.", | ||
{ | ||
code: "var foo = ():string => {}", | ||
code: "let foo = ():string => {}", | ||
parser: "typescript-eslint-parser", | ||
output: "var foo = (): string => {}", | ||
output: "let foo = (): string => {}", | ||
errors: [{ | ||
@@ -91,0 +91,0 @@ message: "Expected a space after the colon.", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
68269
34
1616
59
6
2