description and source-codematch-exported = function (context) {
return {
"Program": function (node) {
var transforms = getTransformsFromOptions(context.options[0]),
replacePattern = context.options[1] ? new RegExp(context.options[1]) : null,
filename = context.getFilename(),
absoluteFilename = path.resolve(filename),
parsed = parseFilename(absoluteFilename),
shouldIgnore = isIgnoredFilename(filename),
exportedName = getExportedName(node),
isExporting = Boolean(exportedName),
expectedExport = getStringToCheckAgainstExport(parsed, replacePattern),
transformedNames = transform(exportedName, transforms),
everythingIsIndex = exportedName === 'index' && parsed.name === 'index',
matchesExported = anyMatch(expectedExport, transformedNames) || everythingIsIndex,
reportIf = function (condition, messageForNormalFile, messageForIndexFile) {
var message = (!messageForIndexFile || !isIndexFile(parsed)) ? messageForNormalFile : messageForIndexFile;
if (condition) {
context.report(node, message, {
name: parsed.base,
expectedExport: expectedExport,
exportName: transformedNames.join("', '"),
extension: parsed.ext,
whatToMatch: getWhatToMatchMessage(transforms)
});
}
};
if (shouldIgnore) return;
reportIf(
isExporting && !matchesExported,
"Filename '{{expectedExport}}' must match {{whatToMatch}} '{{exportName}}'.",
"The directory '{{expectedExport}}' must be named '{{exportName}}', after the exported value of its index file."
);
}
}
}