Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Chore: Upgrade deps to eslint 4 and typescript-parser 4 #31

Merged
merged 1 commit into from
Jul 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
extends: eslint
env:
es6: true
node: true
root: true

plugins:
- node
extends:
- "eslint"
- "plugin:node/recommended"
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock = false
6 changes: 3 additions & 3 deletions docs/rules/type-annotation-spacing.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Type annotations in TypeScript tend to have a very specific format, where the colon appears directly after the identifier or function, followed by a space, followed by the type. For example:

```ts
var foo: string = "bar";
let foo: string = "bar";

function foo(a: string): string {
// code
Expand All @@ -19,7 +19,7 @@ This rule aims to enforce specific spacing patterns around type annotations. As
The following patterns are considered warnings:

```ts
var foo:string = "bar";
let foo:string = "bar";

function foo(a : string):string {
// code
Expand All @@ -29,7 +29,7 @@ function foo(a : string):string {
The following patterns are not warnings:

```js
var foo: string = "bar";
let foo: string = "bar";

function foo(a: string): string {
// code
Expand Down
4 changes: 2 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
// Requirements
//------------------------------------------------------------------------------

var requireIndex = require("requireindex"),
path = require("path");
const requireIndex = require("requireindex");
const path = require("path");

//------------------------------------------------------------------------------
// Plugin Definition
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/explicit-member-accessibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = {
schema: []
},

create: function(context) {
create(context) {

//----------------------------------------------------------------------
// Helpers
Expand All @@ -33,7 +33,7 @@ module.exports = {
if (!methodDefinition.accessibility) {
context.report({
node: methodDefinition,
message: "Missing accessibility modifier on method definition " + methodDefinition.key.name + "."
message: `Missing accessibility modifier on method definition ${methodDefinition.key.name}.`
});
}
}
Expand All @@ -48,7 +48,7 @@ module.exports = {
if (!classProperty.accessibility) {
context.report({
node: classProperty,
message: "Missing accessibility modifier on class property " + classProperty.key.name + "."
message: `Missing accessibility modifier on class property ${classProperty.key.name}.`
});
}
}
Expand Down
18 changes: 10 additions & 8 deletions lib/rules/interface-name-prefix.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ module.exports = {
]
},

create: function(context) {
var never = context.options[0] !== "always";
create(context) {
const never = context.options[0] !== "always";

//----------------------------------------------------------------------
// Helpers
//----------------------------------------------------------------------
Expand All @@ -40,8 +41,9 @@ module.exports = {
if (name.length === 0) {
return false;
}
var first = name.charAt(0);
var second = name.charAt(1);
const first = name.charAt(0);
const second = name.charAt(1);

if (second === "") {
return false;
}
Expand All @@ -59,16 +61,16 @@ module.exports = {
*/
function checkInterfacePrefix(interfaceNode) {
if (never) {
if (isPrefixedWithI(interfaceNode.name.name)) {
if (isPrefixedWithI(interfaceNode.id.name)) {
context.report({
node: interfaceNode.name,
node: interfaceNode.id,
message: "Interface name must not be prefixed with \"I\""
});
}
} else {
if (!isPrefixedWithI(interfaceNode.name.name)) {
if (!isPrefixedWithI(interfaceNode.id.name)) {
context.report({
node: interfaceNode.name,
node: interfaceNode.id,
message: "Interface name must be prefixed with \"I\""
});
}
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/no-angle-bracket-type-assertion.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ module.exports = {
schema: []
},

create: function(context) {
create(context) {

var sourceCode = context.getSourceCode();
const sourceCode = context.getSourceCode();

//----------------------------------------------------------------------
// Public
//----------------------------------------------------------------------
return {
TSTypeAssertionExpression: function(node) {
TSTypeAssertionExpression(node) {
context.report({
node,
message: "Prefer 'as {{cast}}' instead of '<{{cast}}>' when doing type assertions",
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-explicit-any.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = {
schema: []
},

create: function(context) {
create(context) {

//----------------------------------------------------------------------
// Helpers
Expand Down
14 changes: 8 additions & 6 deletions lib/rules/no-namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ module.exports = {
]
},

create: function(context) {
create(context) {

var allowDeclarations = context.options[0] ? context.options[0].allowDeclarations : false;
var 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;

//----------------------------------------------------------------------
// Helpers
Expand All @@ -56,7 +56,8 @@ module.exports = {
* @private
*/
function isDeclaration(node) {
var hasDeclareModifier = (node.modifiers || []).filter(m => m.type === "TSDeclareKeyword").length > 0;
const hasDeclareModifier = (node.modifiers || []).filter(m => m.type === "TSDeclareKeyword").length > 0;

return hasDeclareModifier && !isTypeScriptModuleDeclaration(node);
}

Expand All @@ -66,15 +67,16 @@ module.exports = {
* @private
*/
function isDefinitionFile() {
var filename = context.getFilename();
const filename = context.getFilename();

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

//----------------------------------------------------------------------
// Public
//----------------------------------------------------------------------
return {
TSModuleDeclaration: function(node) {
TSModuleDeclaration(node) {
if (isTypeScriptModuleDeclaration(node) ||
(allowDefinitionFiles && isDefinitionFile()) ||
(allowDeclarations && isDeclaration(node))) {
Expand Down
11 changes: 6 additions & 5 deletions lib/rules/no-triple-slash-reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ module.exports = {
schema: []
},

create: function(context) {
var referenceRegExp = /^\/\s*<reference/;
var sourceCode = context.getSourceCode();
create(context) {
const referenceRegExp = /^\/\s*<reference/;
const sourceCode = context.getSourceCode();

//----------------------------------------------------------------------
// Helpers
Expand All @@ -32,8 +32,9 @@ module.exports = {
* @private
*/
function checkTripleSlashReference(program) {
var leading = sourceCode.getComments(program).leading;
leading.forEach(function(comment) {
const leading = sourceCode.getComments(program).leading;

leading.forEach(comment => {
if (comment.type !== "Line") {
return;
}
Expand Down
43 changes: 29 additions & 14 deletions lib/rules/no-unused-vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
* Record that a particular variable has been used in code
*
* @param {Object} context The current rule context.
* @param {String} name The name of the variable to mark as used.
* @returns {Boolean} True if the variable was found and marked as used, false if not.
* @param {string} name The name of the variable to mark as used.
* @returns {boolean} True if the variable was found and marked as used, false if not.
*/
function markVariableAsUsed(context, name) {
var scope = context.getScope();
var variables;
var i;
var len;
var found = false;
let scope = context.getScope();
let variables;
let i;
let len;
let found = false;

// Special Node.js scope means we need to start one level deeper
if (scope.type === "global") {
Expand Down Expand Up @@ -53,7 +53,7 @@ module.exports = {
schema: []
},

create: function(context) {
create(context) {

//----------------------------------------------------------------------
// Helpers
Expand All @@ -69,21 +69,32 @@ module.exports = {
if (!node.decorators || !node.decorators.length) {
return;
}
node.decorators.forEach(function(decorator) {
node.decorators.forEach(decorator => {

/**
* Decorator
*/
if (decorator.name) {
markVariableAsUsed(context, decorator.name);
return;
}

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

/**
* Decorator Factory
*/
if (decorator.callee && decorator.callee.name) {
markVariableAsUsed(context, decorator.callee.name);
return;
}

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

});
}

Expand All @@ -97,7 +108,7 @@ module.exports = {
if (!node.implements || !node.implements.length) {
return;
}
node.implements.forEach(function(implementedInterface) {
node.implements.forEach(implementedInterface => {
if (!implementedInterface || !implementedInterface.id || !implementedInterface.id.name) {
return;
}
Expand All @@ -110,32 +121,36 @@ module.exports = {
//----------------------------------------------------------------------
return {
ClassProperty: markDecoratorsAsUsed,
ClassDeclaration: function(node) {
ClassDeclaration(node) {
markDecoratorsAsUsed(node);
markImplementedInterfacesAsUsed(node);
},
MethodDefinition: function(node) {
MethodDefinition(node) {

/**
* Decorators are only supported on class methods, so exit early
* if the parent is not a ClassBody
*/
const anc = context.getAncestors();
const tAnc = anc.length;

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

/**
* Mark any of the method's own decorators as used
*/
markDecoratorsAsUsed(node);

/**
* Mark any parameter decorators as used
*/
if (!node.value || !node.value.params || !node.value.params.length) {
return;
}
node.value.params.forEach(markDecoratorsAsUsed);
},
}
};

}
Expand Down
12 changes: 7 additions & 5 deletions lib/rules/prefer-namespace-keyword.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ module.exports = {
schema: []
},

create: function(context) {
create(context) {

var sourceCode = context.getSourceCode();
const sourceCode = context.getSourceCode();

//----------------------------------------------------------------------
// Helpers
Expand Down Expand Up @@ -53,8 +53,9 @@ module.exports = {
// Public
//----------------------------------------------------------------------
return {
TSModuleDeclaration: function(node) {
var declaration = sourceCode.getText(node);
TSModuleDeclaration(node) {
const declaration = sourceCode.getText(node);

if (isTypeScriptModuleDeclaration(node) || /\bnamespace\b/.test(declaration)) {
return;
}
Expand All @@ -63,7 +64,8 @@ module.exports = {
node,
message: "Use namespace instead of module to declare custom TypeScript modules",
fix(fixer) {
var start = getStartIndex(node);
const start = getStartIndex(node);

return fixer.replaceTextRange([start, start + "module".length], "namespace");
}
});
Expand Down
Loading