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

Commit

Permalink
Merge branch 'master' into greenkeeper/initial
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender committed May 11, 2017
2 parents 7d1e733 + b8ecca6 commit 225c8ef
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 376 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Change Log
===

v3.0.0
---
* **BREAKING CHANGES**
* [enhancement] Upgraded to tslint@5

v2.1.0
---
* [new-fixer] `jasmine-no-lambda-expression-callbacks`
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "custom-tslint-rules",
"version": "2.1.0",
"version": "3.0.0",
"description": "Custom rules for tslint",
"main": "tslint.json",
"scripts": {
Expand Down Expand Up @@ -36,9 +36,9 @@
"lodash": "^4.17.3"
},
"devDependencies": {
"@types/lodash": "^4.14.54",
"@types/node": "^7.0.5",
"coveralls": "^2.11.16",
"@types/lodash": "^4.14.64",
"@types/node": "^7.0.18",
"coveralls": "^2.13.1",
"glob": "^7.1.1",
"istanbul": "^0.4.5",
"rimraf": "^2.6.1",
Expand All @@ -48,7 +48,7 @@
"yargs": "^8.0.1"
},
"peerDependencies": {
"tslint": "^4.0.0"
"tslint": "^5.0.0"
},
"engines": {
"node": ">=4"
Expand Down
21 changes: 10 additions & 11 deletions src/importBarrelsRule.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as fs from 'fs';
import * as path from 'path';
import { Fix, IOptions, IRuleMetadata, Replacement, RuleFailure, Rules, RuleWalker, Utils } from 'tslint/lib';
import { Expression, ImportDeclaration, SourceFile, StringLiteral, SyntaxKind } from 'typescript';
import { CachedStat } from './utils/cachedStat';
import {Fix, IOptions, IRuleMetadata, Replacement, RuleFailure, Rules, RuleWalker, Utils} from 'tslint/lib';
import {Expression, ImportDeclaration, SourceFile, StringLiteral, SyntaxKind} from 'typescript';
import {CachedStat} from './utils/cachedStat';

export class Rule extends Rules.AbstractRule {
public static readonly metadata:IRuleMetadata = {
Expand All @@ -12,11 +12,11 @@ export class Rule extends Rules.AbstractRule {
rationale: Utils.dedent`
Allows directories that contain multiple modules to be handled as a single module with a single public interface
and opaque inner structure.
This rule works only for ES2015 module syntax \`import\` statements and checks only **relative** module paths.`,
optionsDescription: Utils.dedent`
An argument object may be optionally provided, with the following properties:
* \`noExplicitBarrels = false\`: disallows usage of explicitly named barrels in import statements (\`import foo from './foo/index'\`)
* \`fileExtensions = ['ts', 'js']\`: uses the provided file extensions for module and barrel file lookup
* \`fixWithExplicitBarrelImport\`: uses the provided string to replace non-barrel imports in \`--fix\` mode
Expand Down Expand Up @@ -111,7 +111,7 @@ class ImportBarrelsWalker extends RuleWalker {
return CheckResult.OK;
}

const sourceFileRelative = this.getSourceFile().path;
const sourceFileRelative = this.getSourceFile().fileName;
const sourceFileDirAbsolute = path.resolve(path.dirname(sourceFileRelative));
const moduleAbsolute = path.normalize(path.resolve(sourceFileDirAbsolute, modulePathText));
const moduleDirAbsolute = path.dirname(moduleAbsolute);
Expand Down Expand Up @@ -141,10 +141,10 @@ class ImportBarrelsWalker extends RuleWalker {
return dirHasBarrelFile ? CheckResult.NonBarrelImport : CheckResult.OK;
}

private getModuleStats(modulePath:string):fs.Stats|null {
private getModuleStats(modulePath:string):fs.Stats | null {
const modulePathCandidates = [modulePath, ...this.ruleOptions.fileExtensions.map(suffix => `${modulePath}.${suffix}`)];

let stats:fs.Stats|null = null;
let stats:fs.Stats | null = null;
modulePathCandidates.some(modulePathCandidate => {
stats = this.cachedStat.statSync(modulePathCandidate);
return stats !== null;
Expand All @@ -160,8 +160,7 @@ class ImportBarrelsWalker extends RuleWalker {
replacement += `/${this.ruleOptions.fixWithExplicitBarrelImport}`;
}

return new Fix(Rule.metadata.ruleName, [
// account for quotes
new Replacement(moduleSpecifier.getStart() + 1, moduleSpecifier.getWidth() - `''`.length, replacement)]);
// account for quotes
return new Replacement(moduleSpecifier.getStart() + 1, moduleSpecifier.getWidth() - `''`.length, replacement);
}
}
14 changes: 7 additions & 7 deletions src/jasmineNoLambdaExpressionCallbacksRule.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Fix, IRuleMetadata, Replacement, RuleFailure, Rules, RuleWalker, Utils } from 'tslint/lib';
import { ArrowFunction, CallExpression, Expression, SourceFile, SyntaxKind } from 'typescript';
import { isJasmineDescribe, isJasmineIt, isJasmineSetupTeardown, isJasmineTest } from './utils/jasmineUtils';
import {Fix, IRuleMetadata, Replacement, RuleFailure, Rules, RuleWalker, Utils} from 'tslint/lib';
import {ArrowFunction, CallExpression, Expression, SourceFile, SyntaxKind} from 'typescript';
import {isJasmineDescribe, isJasmineIt, isJasmineSetupTeardown, isJasmineTest} from './utils/jasmineUtils';
import find = require('lodash/find');

export class Rule extends Rules.AbstractRule {
Expand All @@ -20,7 +20,7 @@ export class Rule extends Rules.AbstractRule {
beforeEach(async(() => {
...
}));
it('something', inject([Service], (service) => {
...
}))
Expand Down Expand Up @@ -56,7 +56,7 @@ class JasmineNoLambdaExpressionCallbacksWalker extends RuleWalker {
super.visitCallExpression(node);
}

private getInvalidLambdaExpression(node:CallExpression):ArrowFunction|false {
private getInvalidLambdaExpression(node:CallExpression):ArrowFunction | false {
if (node.expression.kind !== SyntaxKind.Identifier) {
return false;
}
Expand All @@ -73,7 +73,7 @@ class JasmineNoLambdaExpressionCallbacksWalker extends RuleWalker {
return false;
}

private getLambdaExpressionFromArg(apiArg:Expression):ArrowFunction|null {
private getLambdaExpressionFromArg(apiArg:Expression):ArrowFunction | null {
if (apiArg.kind === SyntaxKind.ArrowFunction) {
return <ArrowFunction>apiArg;
} else if (apiArg.kind === SyntaxKind.CallExpression) {
Expand All @@ -97,6 +97,6 @@ class JasmineNoLambdaExpressionCallbacksWalker extends RuleWalker {
);
}

return new Fix(Rule.metadata.ruleName, replacements);
return replacements;
}
}
4 changes: 2 additions & 2 deletions src/tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@
"no-switch-case-fall-through": true,
"no-unsafe-finally": true,
"no-unused-expression": true,
"no-unused-new": true,
"no-use-before-declare": true,
// "no-use-before-declare" requires type info
"no-use-before-declare": false,
"no-var-keyword": true,
// "no-void-expression" requires type info
"no-void-expression": false,
Expand Down
Loading

0 comments on commit 225c8ef

Please sign in to comment.