Skip to content

Commit

Permalink
Implemented fix for quotemark rule (palantir#1790)
Browse files Browse the repository at this point in the history
  • Loading branch information
devoto13 authored and nchen63 committed Nov 27, 2016
1 parent 5c7cf4a commit d46f74f
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/rules/quotemarkRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ class QuotemarkWalker extends Lint.RuleWalker {
? Rule.SINGLE_QUOTE_FAILURE
: Rule.DOUBLE_QUOTE_FAILURE;

this.addFailure(this.createFailure(position, width, failureMessage));
const newText = expectedQuoteMark
+ text.slice(1, -1).replace(new RegExp(expectedQuoteMark, "g"), `\\${expectedQuoteMark}`)
+ expectedQuoteMark;

const fix = new Lint.Fix(Rule.metadata.ruleName, [ new Lint.Replacement(position, width, newText) ]);
this.addFailure(this.createFailure(position, width, failureMessage, fix));
}
}

Expand Down
4 changes: 4 additions & 0 deletions test/rules/quotemark/double-avoid-escape/test.ts.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var single = "single";
var doublee = "married";
var singleWithinDouble = "'singleWithinDouble'";
var doubleWithinSingle = '"doubleWithinSingle"';
4 changes: 4 additions & 0 deletions test/rules/quotemark/double/test.ts.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var single = "single";
var doublee = "married";
var singleWithinDouble = "'singleWithinDouble'";
var doubleWithinSingle = "\"doubleWithinSingle\"";
4 changes: 4 additions & 0 deletions test/rules/quotemark/jsx-double/test.tsx.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as React from 'react';

export const a = (
<div className="class" id="id" data-a={'a' + 'b'}></div>
4 changes: 4 additions & 0 deletions test/rules/quotemark/jsx-single/test.tsx.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as React from "react";

export const a = (
<div className='class' id='id' data-a={"a" + "b"}></div>
4 changes: 4 additions & 0 deletions test/rules/quotemark/single-avoid-escape/test.ts.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var single = 'single';
var doublee = 'married';
var singleWithinDouble = "'singleWithinDouble'";
var doubleWithinSingle = '"doubleWithinSingle"';
4 changes: 4 additions & 0 deletions test/rules/quotemark/single/test.ts.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var single = 'single';
var doublee = 'married';
var singleWithinDouble = '\'singleWithinDouble\'';
var doubleWithinSingle = '"doubleWithinSingle"';

0 comments on commit d46f74f

Please sign in to comment.