forked from cwoolum/ionicV4-tslint
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(getSlidingPercent rule): * fix(rules): remove leftover console log
- Loading branch information
1 parent
a71d8bc
commit 2617d26
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import * as Lint from 'tslint'; | ||
import * as ts from 'typescript'; | ||
export const ruleName = 'ion-item-option-method-get-sliding-percent-renamed'; | ||
export const ruleMessage = '"getSlidingPercent" has been renamed to "getSlidingRatio"'; | ||
|
||
class GetSlidingPercentRenamedWalker extends Lint.RuleWalker { | ||
visitCallExpression(node: ts.CallExpression) { | ||
const expression = node.expression as any; | ||
if (expression.name && expression.name.text === 'getSlidingPercent') { | ||
const replacement = new Lint.Replacement(expression.name.getStart(), expression.name.getWidth(), 'getSlidingRatio'); | ||
this.addFailure(this.createFailure(expression.name.getStart(), expression.name.getWidth(), ruleMessage, replacement)); | ||
} | ||
} | ||
} | ||
|
||
export class Rule extends Lint.Rules.AbstractRule { | ||
public static metadata: Lint.IRuleMetadata = { | ||
ruleName: ruleName, | ||
type: 'functionality', | ||
description: 'getSlidingPercent is now called getSlidingRatio.', | ||
options: null, | ||
optionsDescription: 'Not configurable.', | ||
typescriptOnly: true, | ||
hasFix: true | ||
}; | ||
|
||
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { | ||
return this.applyWithWalker(new GetSlidingPercentRenamedWalker(sourceFile, this.getOptions())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { expect } from 'chai'; | ||
import { ruleName, ruleMessage } from '../src/ionItemOptionMethodGetSlidingPercentRenamedRule'; | ||
import { assertAnnotated, assertSuccess } from './testHelper'; | ||
|
||
describe(ruleName, () => { | ||
describe('success', () => { | ||
it('should work with new method name', () => { | ||
let source = ` | ||
class DoSomething{ | ||
constructor(){} | ||
getRatio(item: ItemSliding){ | ||
return item.getSlidingRatio(); | ||
} | ||
} | ||
`; | ||
assertSuccess(ruleName, source); | ||
}); | ||
}); | ||
|
||
describe('failure', () => { | ||
it('should fail when using getSlidingPercent', () => { | ||
let source = ` | ||
class DoSomething{ | ||
constructor(){} | ||
getRatio(item: ItemSliding){ | ||
return item.getSlidingPercent(); | ||
~~~~~~~~~~~~~~~~~ | ||
} | ||
} | ||
`; | ||
assertAnnotated({ | ||
ruleName, | ||
message: ruleMessage, | ||
source | ||
}); | ||
}); | ||
}); | ||
}); |