Skip to content

Commit

Permalink
Fix: Rule message placeholders can be inside braces (fixes #6988)
Browse files Browse the repository at this point in the history
  • Loading branch information
platinumazure committed Sep 2, 2016
1 parent 3f13325 commit 6150b6b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/eslint.js
Expand Up @@ -974,7 +974,7 @@ module.exports = (function() {
}

if (opts) {
message = message.replace(/\{\{\s*(.+?)\s*\}\}/g, function(fullMatch, term) {
message = message.replace(/\{\{\s*([^{}]+?)\s*\}\}/g, function(fullMatch, term) {
if (term in opts) {
return opts[term];
}
Expand Down
19 changes: 19 additions & 0 deletions tests/lib/eslint.js
Expand Up @@ -937,6 +937,25 @@ describe("eslint", function() {
assert.equal(messages[0].message, "message yay!");
});

it("should allow template parameter wrapped in braces", function() {
eslint.reset();
eslint.defineRule("test-rule", function(context) {
return {
Literal(node) {
context.report(node, "message {{{param}}}", {
param: "yay!"
});
}
};
});

config.rules["test-rule"] = 1;

const messages = eslint.verify("0", config);

assert.equal(messages[0].message, "message {yay!}");
});

it("should ignore template parameter with no specified value", function() {
eslint.reset();
eslint.defineRule("test-rule", function(context) {
Expand Down

0 comments on commit 6150b6b

Please sign in to comment.