Skip to content

Commit

Permalink
Introduce replace property
Browse files Browse the repository at this point in the history
  • Loading branch information
gberaudo committed Nov 24, 2017
1 parent dbd656a commit e719969
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion valid-provide-and-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ exports.rule = {
create: function(context) {
const entryPoints = context.options[0].entryPoints || ['ol'];
const relativeSourceRoot = context.options[0].root || 'src';
let replace = context.options[0].replace;
if (replace) {
replace = replace.split('|');
}
let gotFirst = false;
return {
CallExpression: function(expression) {
Expand Down Expand Up @@ -46,14 +50,17 @@ exports.rule = {

const filePath = context.getFilename();
const sourceRoot = path.join(pkgDir.sync(filePath), relativeSourceRoot);
const requirePath = path.relative(sourceRoot, filePath);
let requirePath = path.relative(sourceRoot, filePath);
const ext = '.js';
let name = arg.value;
// special case for main entry point
if (entryPoints.indexOf(name) !== -1) {
name += '.index';
}
const expectedPath = name.split('.').join(path.sep) + ext;
if (replace) {
requirePath = requirePath.replace(replace[0], replace[1]);
}
if (expectedPath.toLowerCase() !== requirePath.toLowerCase()) {
return context.report(expression, `Expected goog.${type}('${name}') to be at ${expectedPath.toLowerCase()} instead of ${requirePath.toLowerCase()}`);
}
Expand Down

0 comments on commit e719969

Please sign in to comment.