Skip to content

Commit

Permalink
Rename no-string-ref to jsx-no-string-ref (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
adidahiya authored Jun 16, 2016
1 parent d0c1364 commit f847547
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Sample configuration where `tslint.json` lives adjacent to your `node_modules` f
- `jsx-no-lambda`
- Creating new anonymous functions (with either the `function` syntax or ES2015 arrow syntax) inside the `render` call stack works against _pure component rendering_. When doing an equality check between two lambdas, React will always consider them unequal values and force the component to re-render more often than necessary.
- Rule options: _none_
- `no-string-ref`
- `jsx-no-string-ref`
- Passing strings to the `ref` prop of React elements is considered a legacy feature and will soon be deprecated.
Instead, [use a callback](https://facebook.github.io/react/docs/more-about-refs.html#the-ref-callback-attribute).
- Rule options: _none_
Expand Down
10 changes: 5 additions & 5 deletions src/rules/noStringRefRule.ts → src/rules/jsxNoStringRefRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ export class Rule extends Lint.Rules.AbstractRule {
public static FAILURE_STRING = "Pass a callback to ref prop instead of a string literal";

public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
const noStringRefWalker = new NoStringRefWalker(sourceFile, this.getOptions());
return this.applyWithWalker(noStringRefWalker);
const walker = new JsxNoStringRefWalker(sourceFile, this.getOptions());
return this.applyWithWalker(walker);
}
}

class NoStringRefWalker extends Lint.RuleWalker {
class JsxNoStringRefWalker extends Lint.RuleWalker {
protected visitNode(node: ts.Node) {
if (nodeIsKind<ts.JsxAttribute>(node, ts.SyntaxKind.JsxAttribute)) {
const {name, initializer} = node;
const { name, initializer } = node;
const isRefAttribute = name != null && name.text === "ref";
if (isRefAttribute && initializer != null) {
const hasStringInitializer = initializer.kind === ts.SyntaxKind.StringLiteral;
const hasStringExpressionInitializer =
nodeIsKind<ts.JsxExpression>(initializer, ts.SyntaxKind.JsxExpression)
&& (initializer.expression.kind === ts.SyntaxKind.StringLiteral
|| initializer.expression.kind === ts.SyntaxKind.TemplateExpression);
|| initializer.expression.kind === ts.SyntaxKind.TemplateExpression);

if (hasStringInitializer || hasStringExpressionInitializer) {
this.addFailure(this.createFailure(
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions test/rules/jsx-no-string-ref/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"jsx-no-string-ref": true
}
}
5 changes: 0 additions & 5 deletions test/rules/no-string-ref/tslint.json

This file was deleted.

0 comments on commit f847547

Please sign in to comment.