Skip to content

Commit

Permalink
🏗 Format forbidden term report message (#33504)
Browse files Browse the repository at this point in the history
- Remove newline
- Add period to message only if needed
- Add color to term
  • Loading branch information
alanorozco committed Mar 25, 2021
1 parent f1e45f5 commit 73a5ba1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion build-system/eslint-rules/no-forbidden-terms.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

const {cyan} = require('kleur/colors');
const {getForbiddenTerms} = require('../test-configs/forbidden-terms');
const {relative} = require('path');

Expand All @@ -23,6 +24,8 @@ const {relative} = require('path');
* See test-configs/forbidden-terms.js
*/

const addPeriod = (str) => (/.\s*$/.test(str) ? str : `${str}.`);

module.exports = function (context) {
return {
Program() {
Expand All @@ -31,9 +34,12 @@ module.exports = function (context) {

for (const report of getForbiddenTerms(filename, sourceCode.text)) {
const {match, message, loc} = report;
const formattedMatch = cyan(`"${match}"`);
context.report({
loc,
message: `Forbidden: "${match}".${message ? `\n${message}.` : ''}`,
message:
`Forbidden: ${formattedMatch}.` +
(message ? ` ${addPeriod(message)}` : ''),
});
}
},
Expand Down

0 comments on commit 73a5ba1

Please sign in to comment.