Skip to content

Commit

Permalink
Cleanup, adhere to own ruleset and easier setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Remy Rylan committed Apr 30, 2018
1 parent 8262ccf commit 44eb868
Show file tree
Hide file tree
Showing 22 changed files with 216 additions and 426 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ npm install --save-dev vrsource-tslint-rules

Configure tslint to use the vrsource-tslint-rules folder:

Add the following path to the `rulesDirectory` setting in your `tslint.json` file:
Add `"vrsource-tslint-rules"` to the `extends` array of your `tslint.json` file:

```
{
"rulesDirectory": ["node_modules/vrsource-tslint-rules/rules"]
"rules": {
...
}
"extends": ["vrsource-tslint-rules"]
}
```

Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,20 @@
"license": "MIT",
"peerDependencies": {
"tslint": "~5.8.0",
"typescript": "~2.5.3",
"typescript": "~2.5.3"
},
"devDependencies": {
"chokidar-cli": "~1.2.0"
"@types/node": "^10.0.0",
"chokidar-cli": "~1.2.0",
"tslint": "~5.8.0",
"typescript": "~2.5.3"
},
"watch": {
"test": "rules/*.ts"
},
"scripts": {
"build": "tsc -p .",
"lint": "tslint rules/*.ts",
"lint": "tslint rules/*.ts --project .",
"test:once": "./run_tests.sh",
"test": "npm run lint && npm run build && npm run test:once",
"watch": "chokidar 'rules/*.ts' 'test/**/*' -c 'npm run test'"
Expand Down
42 changes: 24 additions & 18 deletions rules/conditionalExpressionParensRule.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions rules/conditionalExpressionParensRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ const allowedClauseKinds = [
ts.SyntaxKind.ObjectLiteralExpression,
];

export class Rule extends Lint.Rules.AbstractRule {
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
return this.applyWithWalker(new PreferLiteralWalker(sourceFile, this.getOptions()));
}
}

class PreferLiteralWalker extends Lint.RuleWalker {
protected visitConditionalExpression(node: ts.ConditionalExpression) {
let clauses = [node.condition, node.whenFalse, node.whenTrue];
Expand All @@ -43,3 +37,8 @@ class PreferLiteralWalker extends Lint.RuleWalker {
}
}

export class Rule extends Lint.Rules.AbstractRule {
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
return this.applyWithWalker(new PreferLiteralWalker(sourceFile, this.getOptions()));
}
}
62 changes: 0 additions & 62 deletions rules/dotNotationRule.js

This file was deleted.

42 changes: 24 additions & 18 deletions rules/extVariableNameRule.js

Large diffs are not rendered by default.

16 changes: 7 additions & 9 deletions rules/extVariableNameRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,6 @@ const BANNED_KEYWORDS = ["any", "Number", "number", "String", "string",
"Boolean", "boolean", "Undefined", "undefined"];


export class Rule extends Lint.Rules.AbstractRule {
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
const variableNameWalker = new VariableNameWalker(sourceFile, this.getOptions());
return this.applyWithWalker(variableNameWalker);
}
}

/**
* Configured with details needed to check a specific variable type.
*/
Expand Down Expand Up @@ -302,7 +295,7 @@ class VariableNameWalker extends Lint.RuleWalker {
super.visitFunctionDeclaration(node);
}

protected checkName(node: ts.Declaration, tag: string) {
protected checkName(node: ts.NamedDeclaration, tag: string) {
if (node.name && node.name.kind === ts.SyntaxKind.Identifier) {
const matching_checker = this.getMatchingChecker(this.getNodeTags(node, tag));
if (matching_checker !== null) {
Expand Down Expand Up @@ -355,7 +348,6 @@ class VariableNameWalker extends Lint.RuleWalker {
}
}


function nearestBody(node: ts.Node): {isSourceFile: boolean, containingBody: ts.Node | undefined} {
const VALID_PARENT_TYPES = [
ts.SyntaxKind.SourceFile,
Expand Down Expand Up @@ -423,6 +415,12 @@ function contains(arr: any[], value: any): boolean {
return arr.indexOf(value) !== -1;
}

export class Rule extends Lint.Rules.AbstractRule {
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
const variableNameWalker = new VariableNameWalker(sourceFile, this.getOptions());
return this.applyWithWalker(variableNameWalker);
}
}

/**
* Original version based upon variable-name rule:
Expand Down
Loading

0 comments on commit 44eb868

Please sign in to comment.