Skip to content
This repository has been archived by the owner on Feb 21, 2022. It is now read-only.

Commit

Permalink
[enhancement] turned on noImplicitAny rule
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Lopez committed May 20, 2017
1 parent 2146e9a commit 5177312
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 35 deletions.
14 changes: 7 additions & 7 deletions src/readme/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ function compareToESLint() {
return new Promise((fulfill) => {
requestFromGithub('/repos/eslint/eslint/contents/lib/rules', (data) => {
const rules = data
.filter(obj => obj.name.endsWith('.js'))
.map(obj => obj.name.substring(0, obj.name.length - 3));
.filter((obj: any) => obj.name.endsWith('.js'))
.map((obj: any) => obj.name.substring(0, obj.name.length - 3));

const esRules = Object.keys(ruleESMap);
const missing = arrayDiff(rules.map(x => toCamelCase(x)), esRules);
const deprecated = arrayDiff(esRules, rules.map(x => toCamelCase(x)));
const missing = arrayDiff(rules.map((x: string) => toCamelCase(x)), esRules);
const deprecated = arrayDiff(esRules, rules.map((x: string) => toCamelCase(x)));
const buffer: string[] = [];

if (missing.length) {
Expand Down Expand Up @@ -74,11 +74,11 @@ function compareToTSLint() {
return new Promise((fulfill) => {
requestFromGithub('/repos/palantir/tslint/contents/src/rules', (data) => {
const rules = data
.filter(obj => obj.name.endsWith('.ts'))
.map(obj => obj.name.substring(0, obj.name.length - 7));
.filter((obj: any) => obj.name.endsWith('.ts'))
.map((obj: any) => obj.name.substring(0, obj.name.length - 7));

const notInUse = require('../../src/readme/unusedTSLintRules.json');
notInUse.forEach((name) => {
notInUse.forEach((name: string) => {
const camel = toCamelCase(name);
const index = rules.indexOf(camel);
if (index > -1) {
Expand Down
4 changes: 2 additions & 2 deletions src/readme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as fs from 'fs';
import * as path from 'path';
import { IRule, categories, rules, ruleTSMap, toCamelCase } from './rules';

function formatUsage(usage) {
function formatUsage(usage: string): string {
return usage.replace(/~~~/g, '```').replace(/(^[ \t]*\n)/gm, '\n').replace(/^ /mg, '');
}

Expand Down Expand Up @@ -77,7 +77,7 @@ function createRuleContent(rule: IRule) {
console.warn(` ${metaData.description} !== ${rule.description}`);
}
const examples = metaData.optionExamples.map(
x => ['```json', x, '```'].join('')
(x: string) => ['```json', x, '```'].join('')
).join('\n\n');
const schema = [
'```json',
Expand Down
2 changes: 1 addition & 1 deletion src/readme/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3101,7 +3101,7 @@ const rules: IRule[] = [
}
];

function toCamelCase(str) {
function toCamelCase(str: string): string {
const words = str.split('-').map(word => word.charAt(0).toUpperCase() + word.slice(1));
words[0] = words[0].toLowerCase();
return words.join('');
Expand Down
12 changes: 6 additions & 6 deletions src/rules/noMultiSpacesRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ class NoMultiSpacesWalker extends Lint.RuleWalker {
this.lastNode = sourceFile.getLastToken();
}

private inRange(x, range) {
private inRange(x: number, range: [number, number]): boolean {
return x >= range[0] && x <= range[1];
}

private warn(value, pos, node) {
private warn(value: string, pos: number, node: ts.Node): void {
const msg = `Multiple spaces found before '${value}'.`;
const exceptionName = this.EXCEPTION_MAP[node.parent.kind];
const exceptionName = this.EXCEPTION_MAP[node.parent!.kind];

let report = true;
const start: number = node.getFullStart() - 1;
Expand All @@ -84,9 +84,9 @@ class NoMultiSpacesWalker extends Lint.RuleWalker {
// Sneaky property assignments may have many nested children. Lets check if one of
// the parents is one of those.
if (previousChar === ':') {
let crt = node.parent;
let crt = node.parent!;
while (crt.kind !== ts.SyntaxKind.SourceFile) {
crt = crt.parent;
crt = crt.parent!;
if (crt.kind === ts.SyntaxKind.PropertyAssignment) {
if (this.exceptions['PropertyAssignment']) {
report = false;
Expand All @@ -102,7 +102,7 @@ class NoMultiSpacesWalker extends Lint.RuleWalker {
}

protected walkChildren(node: ts.Node): void {
const range = [node.getStart(), node.getEnd()];
const range: [number, number] = [node.getStart(), node.getEnd()];
for (let i = this.targetIndex, len = this.targets.length, target; i < len; i++) {
target = this.targets[i];
if (this.inRange(target, range)) {
Expand Down
6 changes: 6 additions & 0 deletions src/rules/sortImportsRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ class RuleWalker extends Lint.RuleWalker {
memberSyntaxType: MemberSyntaxType.All,
sortValue: allMatch[1]
};
} else {
// TODO: Made up value, are we guaranteed to always hit one of the if statements?
result = {
memberSyntaxType: MemberSyntaxType.None,
sortValue: ''
};
}

return result;
Expand Down
2 changes: 1 addition & 1 deletion src/rules/terFuncCallSpacingRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class RuleWalker extends Lint.AbstractWalker<WalkerOptions> {
}

public walk(sourceFile: ts.SourceFile) {
const cb = (node: ts.Node) => {
const cb = (node: ts.Node): void => {
if (node.kind === ts.SyntaxKind.NewExpression) {
this.visitNewExpression(node as ts.NewExpression);
}
Expand Down
19 changes: 10 additions & 9 deletions src/rules/terIndentRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ class IndentWalker extends Lint.RuleWalker {
/**
* Check indentation for blocks
*/
private blockIndentationCheck(node: ts.BlockLike): void {
private blockIndentationCheck(node: ts.BlockLike | ts.IterationStatement): void {
if (this.isSingleLineNode(node)) {
return;
}
Expand All @@ -477,7 +477,8 @@ class IndentWalker extends Lint.RuleWalker {
'ArrowFunction'
];
if (node.parent && isOneOf(node.parent, functionLike)) {
this.checkIndentInFunctionBlock(node);
// TODO: nope, can't figure this last check, shutting it down for now.
this.checkIndentInFunctionBlock(node as any);
return;
}

Expand Down Expand Up @@ -799,7 +800,7 @@ class IndentWalker extends Lint.RuleWalker {
return;
}

let elements = isKind(node, 'ObjectLiteralExpression') ? node['properties'] : node['elements'];
let elements: ts.Node[] = isKind(node, 'ObjectLiteralExpression') ? node['properties'] : node['elements'];

// filter out empty elements, an example would be [ , 2]
elements = elements.filter(elem => elem.getText() !== '');
Expand Down Expand Up @@ -897,20 +898,20 @@ class IndentWalker extends Lint.RuleWalker {
* @param {ASTNode} varNode variable declaration node to check against
* @returns {boolean} True if all the above condition satisfy
*/
protected isNodeInVarOnTop(node: ts.Node, varNode) {
protected isNodeInVarOnTop(node: ts.Node, varNode: ts.VariableDeclaration) {
const nodeLine = this.getLine(node);
const parentLine = this.getLine(varNode.parent);
const parentLine = this.getLine(varNode.parent!);
return varNode &&
parentLine === nodeLine &&
varNode.parent.declarations.length > 1;
(varNode.parent! as ts.VariableDeclarationList).declarations.length > 1;
}

/**
* Check and decide whether to check for indentation for blockless nodes
* Scenarios are for or while statements without braces around them
*/
private blockLessNodes(node) {
if (!isKind(node.statement, 'Block')) {
private blockLessNodes(node: ts.IterationStatement): void {
if (!isKind<ts.Block>(node.statement, 'Block')) {
this.blockIndentationCheck(node);
}
}
Expand Down Expand Up @@ -939,7 +940,7 @@ class IndentWalker extends Lint.RuleWalker {
* This function for more complicated return statement case, where closing parenthesis may be
* followed by ';'
*/
private checkLastReturnStatementLineIndent(node: ts.ReturnStatement, firstLineIndent) {
private checkLastReturnStatementLineIndent(node: ts.ReturnStatement, firstLineIndent: number): void {
if (!node.expression) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/rules/terMaxLenRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function stripTrailingComment(line: string, comment: INode) {
/**
* A reducer to group an AST node by line number, both start and end.
*/
function groupByLineNumber(acc, node: INode) {
function groupByLineNumber(acc: INode[][], node: INode) {
const startLoc = node.start;
const endLoc = node.end;

Expand Down
14 changes: 10 additions & 4 deletions src/rules/validJsdocRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ declare interface IReturnPresent {
returnPresent: boolean;
}

interface IJSComment {
comments?: string;
start?: number;
width?: number;
}

class ValidJsdocWalker extends Lint.RuleWalker {
private fns: Array<IReturnPresent> = [];

Expand Down Expand Up @@ -245,7 +251,7 @@ class ValidJsdocWalker extends Lint.RuleWalker {
return tag.type && (tag.type.name === 'void' || tag.type.type === 'UndefinedLiteral');
}

private getJSDocComment(node: ts.Node) {
private getJSDocComment(node: ts.Node): IJSComment {
const ALLOWED_PARENTS = [
ts.SyntaxKind.BinaryExpression,
ts.SyntaxKind.VariableDeclaration,
Expand All @@ -257,7 +263,7 @@ class ValidJsdocWalker extends Lint.RuleWalker {
if (node.parent && ALLOWED_PARENTS.indexOf(node.parent.kind) !== -1) {
return this.getJSDocComment(node.parent);
}
return {};
return { comments: undefined, start: undefined, width: undefined };
}

let comments = node.getFullText();
Expand All @@ -268,7 +274,7 @@ class ValidJsdocWalker extends Lint.RuleWalker {
let width = comments.length;

if (!/^\/\*\*/.test(comments) || !/\*\/$/.test(comments)) {
return {};
return { comments: undefined, start: undefined, width: undefined };
}

return { comments, start, width };
Expand All @@ -277,7 +283,7 @@ class ValidJsdocWalker extends Lint.RuleWalker {
private checkJSDoc(node: ts.Node) {
const { comments, start, width } = this.getJSDocComment(node);

if (!comments)
if (!comments || start === undefined || width === undefined)
return;

let jsdoc: doctrine.IJSDocComment;
Expand Down
4 changes: 2 additions & 2 deletions src/test/rules/sortImportsRuleTests.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Failure, Position, RuleTester, dedent } from './ruleTester';

const ALPHA_ORDER_ERROR = (x, y) => `All imports of the same type must be sorted alphabetically. "${x}" must come before "${y}"`;
const TYPE_ORDER_ERROR = (x, y) => `All imports of type "${x}" must occur before all imports of type "${y}"`;
const ALPHA_ORDER_ERROR = (x: string, y: string) => `All imports of the same type must be sorted alphabetically. "${x}" must come before "${y}"`;
const TYPE_ORDER_ERROR = (x: string, y: string) => `All imports of type "${x}" must occur before all imports of type "${y}"`;
const MEMBER_SORT_ERROR = 'Member imports must be sorted alphabetically.';

function expecting(errors: [string, number, number, number][]): Failure[] {
Expand Down
2 changes: 1 addition & 1 deletion src/test/rules/spaceInParensRuleTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const ruleTester = new RuleTester('space-in-parens', true);
const MISSING_SPACE_ERROR = 'there must be a space inside this paren.';
const REJECTED_SPACE_ERROR = 'there should be no spaces inside this paren.';

function expecting(errors): Failure[] {
function expecting(errors: { message: string; line: number; column: number }[]): Failure[] {
return errors.map((err) => {
if (err.message && err.column) {
return {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"noUnusedParameters": true,
"noUnusedLocals": true,
"strictNullChecks": true,
"noImplicitAny": false,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"noImplicitReturns": true,
"noImplicitThis": true,
Expand Down

0 comments on commit 5177312

Please sign in to comment.