eslint-plugin-openlayers-internal
Advanced tools
Comparing version 2.0.1 to 2.1.0
{ | ||
"name": "eslint-plugin-openlayers-internal", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "Custom ESLint rules for the OpenLayers project", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -6,3 +6,15 @@ 'use strict'; | ||
const sourceRoot = path.join(__dirname, '..', 'src'); | ||
function longestCommonPrefix(path1, path2) { | ||
const parts1 = path.resolve(path1).split(path.sep); | ||
const parts2 = path.resolve(path2).split(path.sep); | ||
const common = []; | ||
for (let i = 0, ii = parts1.length; i < ii; ++i) { | ||
if (parts1[i] === parts2[i]) { | ||
common.push(parts1[i]); | ||
} else { | ||
break; | ||
} | ||
} | ||
return common.join(path.sep); | ||
} | ||
@@ -43,5 +55,7 @@ exports.rule = { | ||
const filePath = path.relative(sourceRoot, context.getFilename()); | ||
const filePath = context.getFilename(); | ||
const sourceRoot = path.join(longestCommonPrefix(__dirname, filePath), 'src'); | ||
const requirePath = path.relative(sourceRoot, filePath); | ||
let ext; | ||
if (path.basename(filePath) === 'index.js') { | ||
if (path.basename(requirePath) === 'index.js') { | ||
ext = path.sep + 'index.js'; | ||
@@ -53,4 +67,4 @@ } else { | ||
const expectedPath = name.split('.').join(path.sep) + ext; | ||
if (expectedPath.toLowerCase() !== filePath.toLowerCase()) { | ||
return context.report(expression, `Expected goog.provide('${name}') to be like ${filePath}`); | ||
if (expectedPath.toLowerCase() !== requirePath.toLowerCase()) { | ||
return context.report(expression, `Expected goog.provide('${name}') to be like ${requirePath}`); | ||
} | ||
@@ -57,0 +71,0 @@ } |
13667
393