Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* New: Add context.report({ messageId }) (fixes #6740) * Chore: Extract out loop variables in rule-tester.js * New: RuleTester checks the messageId of expected errors * Chore: Extract the {{ }} substitutions into a separate file * Chore: Test interpolate() * Docs: document messageIds * Fix: Node 4 compatibility * Docs: Specify `node` in messageIds example * Update: Throw if a rule uses a messageId, but doesn’t have meta.messages * Fix: Don’t mutate the descriptor * Chore: Use hOP instead of Object.keys().indexOf * Docs: Add explanation for messageIds * Chore: Fix lint errors * Docs: Show how to use placeholders in messages
- Loading branch information
1 parent
fc7f404
commit 6ab04b5
Showing
7 changed files
with
236 additions
and
41 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
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
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
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
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,24 @@ | ||
/** | ||
* @fileoverview Interpolate keys from an object into a string with {{ }} markers. | ||
* @author Jed Fox | ||
*/ | ||
|
||
"use strict"; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Public Interface | ||
//------------------------------------------------------------------------------ | ||
|
||
module.exports = (text, data) => { | ||
if (!data) { | ||
return text; | ||
} | ||
return text.replace(/\{\{\s*([^{}]+?)\s*\}\}/g, (fullMatch, term) => { | ||
if (term in data) { | ||
return data[term]; | ||
} | ||
|
||
// Preserve old behavior: If parameter name not provided, don't replace it. | ||
return fullMatch; | ||
}); | ||
}; |
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
Oops, something went wrong.