diff --git a/lib/rules/match-regex.js b/lib/rules/match-regex.js index ebdf326..7cfd5b7 100644 --- a/lib/rules/match-regex.js +++ b/lib/rules/match-regex.js @@ -16,8 +16,10 @@ var path = require("path"), module.exports = function(context) { var defaultRegexp = /^([a-z0-9]+)([A-Z][a-z0-9]+)*$/g, + defaultErrorMessage = "Filename '{{name}}' does not match the naming convention.", conventionRegexp = context.options[0] ? new RegExp(context.options[0]) : defaultRegexp, - ignoreExporting = context.options[1] ? context.options[1] : false; + ignoreExporting = context.options[1] ? context.options[1] : false, + errorMessage = context.options[2] || defaultErrorMessage; return { "Program": function(node) { @@ -31,7 +33,7 @@ module.exports = function(context) { if (shouldIgnore) return; if (ignoreExporting && isExporting) return; if (!matchesRegex) { - context.report(node, "Filename '{{name}}' does not match the naming convention.", { + context.report(node, errorMessage, { name: parsed.base }); } diff --git a/test/rules/match-regex.js b/test/rules/match-regex.js index 74bdad7..f9b5bea 100644 --- a/test/rules/match-regex.js +++ b/test/rules/match-regex.js @@ -88,6 +88,14 @@ ruleTester.run("lib/rules/match-regex", regexRule, { errors: [ { message: "Filename 'fooBar.js' does not match the naming convention.", column: 1, line: 1 } ] + }, + { + code: testCode, + filename: "fooBar.js", + options: [ "^[a-z_]$", false, "Custom error message." ], + errors: [ + { message: "Custom error message.", column: 1, line: 1 } + ] } ] });