eslint-plugin-openlayers-internal
Advanced tools
Comparing version 3.0.0-beta.1 to 3.0.0
@@ -8,3 +8,3 @@ 'use strict'; | ||
docs: { | ||
description: 'disallow duplicate ol.require() calls' | ||
description: 'disallow duplicate goog.require() calls' | ||
}, | ||
@@ -32,3 +32,3 @@ fixable: 'code' | ||
node: statement, | ||
message: `Duplicate ol.require('${name}')`, | ||
message: `Duplicate goog.require('${name}')`, | ||
fix: function(fixer) { | ||
@@ -35,0 +35,0 @@ const afterToken = source.getTokenAfter(statement); |
@@ -23,3 +23,3 @@ 'use strict'; | ||
docs: { | ||
description: 'ensure there are ol.require() calls for all used symbols' | ||
description: 'ensure there are goog.require() calls for all used symbols' | ||
}, | ||
@@ -49,3 +49,3 @@ fixable: 'code' | ||
const name = util.getName(expression); | ||
if (name && name.startsWith('ol.') && name !== 'ol.provide' && name !== 'ol.require') { | ||
if (name && name.startsWith('ol.')) { | ||
// check if the name looks like a const | ||
@@ -55,3 +55,3 @@ let match = name.match(CONST_RE); | ||
if (!defined[match[1]]) { | ||
context.report(expression, `Missing ol.require('${match[1]}')`); | ||
context.report(expression, `Missing goog.require('${match[1]}')`); | ||
} | ||
@@ -72,3 +72,3 @@ return; | ||
if (!defined[className] && !defined[objectName]) { | ||
context.report(expression, `Missing ol.require('${className}') or ol.require('${objectName}')`); | ||
context.report(expression, `Missing goog.require('${className}') or goog.require('${objectName}')`); | ||
} | ||
@@ -78,3 +78,3 @@ return; | ||
if (!defined[className]) { | ||
context.report(expression, `Missing ol.require('${className}')`); | ||
context.report(expression, `Missing goog.require('${className}')`); | ||
} | ||
@@ -91,3 +91,3 @@ return; | ||
if (!defined[objectName]) { | ||
context.report(expression, `Missing ol.require('${objectName}')`); | ||
context.report(expression, `Missing goog.require('${objectName}')`); | ||
} | ||
@@ -94,0 +94,0 @@ } |
@@ -8,3 +8,3 @@ 'use strict'; | ||
docs: { | ||
description: 'disallow unused ol.require() calls' | ||
description: 'disallow unused goog.require() calls' | ||
}, | ||
@@ -16,6 +16,6 @@ fixable: 'code' | ||
// a lookup of ol.require() nodes by argument | ||
// a lookup of goog.require() nodes by argument | ||
const requireStatements = {}; | ||
// used names from member expressions that match the ol.require() arg | ||
// used names from member expressions that match the goog.require() arg | ||
const usedNames = {}; | ||
@@ -22,0 +22,0 @@ |
@@ -8,3 +8,3 @@ 'use strict'; | ||
docs: { | ||
description: 'disallow multiple ol.provide() calls' | ||
description: 'disallow multiple goog.provide() calls' | ||
} | ||
@@ -21,3 +21,3 @@ }, | ||
const name = statement.expression.arguments[0].value; | ||
context.report(statement, `Extra ol.provide('${name}')`); | ||
context.report(statement, `Extra goog.provide('${name}')`); | ||
} else { | ||
@@ -24,0 +24,0 @@ hasProvide = true; |
{ | ||
"name": "eslint-plugin-openlayers-internal", | ||
"version": "3.0.0-beta.1", | ||
"version": "3.0.0", | ||
"description": "Custom ESLint rules for the OpenLayers project", | ||
@@ -8,5 +8,18 @@ "main": "index.js", | ||
"type": "git", | ||
"url": "git://github.com/openlayers/ol3.git" | ||
"url": "git://github.com/openlayers/eslint-plugin-openlayers-internal.git" | ||
}, | ||
"license": "BSD-2-Clause" | ||
"license": "BSD-2-Clause", | ||
"scripts": { | ||
"test": "eslint ." | ||
}, | ||
"eslintConfig": { | ||
"extends": "openlayers", | ||
"env": { | ||
"es6": true | ||
} | ||
}, | ||
"devDependencies": { | ||
"eslint": "^3.12.2", | ||
"eslint-config-openlayers": "^6.0.0" | ||
} | ||
} |
@@ -8,3 +8,3 @@ 'use strict'; | ||
docs: { | ||
description: 'require that all ol.require() precede other statements (except ol.provide())' | ||
description: 'require that all goog.require() precede other statements (except goog.provide())' | ||
} | ||
@@ -21,3 +21,3 @@ }, | ||
if (otherSeen) { | ||
return context.report(statement, 'Expected ol.require() to precede other statements'); | ||
return context.report(statement, 'Expected goog.require() to precede other statements'); | ||
} | ||
@@ -24,0 +24,0 @@ } else if (!util.isProvideStatement(statement)) { |
16
util.js
'use strict'; | ||
function isOLCallExpression(node, name) { | ||
function isGoogCallExpression(node, name) { | ||
const callee = node.callee; | ||
return callee && callee.type === 'MemberExpression' && | ||
callee.object.type === 'Identifier' && callee.object.name === 'ol' && | ||
callee.object.type === 'Identifier' && callee.object.name === 'goog' && | ||
callee.property.type === 'Identifier' && !callee.property.computed && | ||
@@ -11,21 +11,21 @@ callee.property.name === name; | ||
function isOLStatement(node, name) { | ||
function isGoogStatement(node, name) { | ||
return node.expression && node.expression.type === 'CallExpression' && | ||
isOLCallExpression(node.expression, name); | ||
isGoogCallExpression(node.expression, name); | ||
} | ||
exports.isProvideExpression = function(node) { | ||
return isOLCallExpression(node, 'provide'); | ||
return isGoogCallExpression(node, 'provide'); | ||
}; | ||
exports.isProvideStatement = function(node) { | ||
return isOLStatement(node, 'provide'); | ||
return isGoogStatement(node, 'provide'); | ||
}; | ||
exports.isRequireExpression = function(node) { | ||
return isOLCallExpression(node, 'require'); | ||
return isGoogCallExpression(node, 'require'); | ||
}; | ||
exports.isRequireStatement = function(node) { | ||
return isOLStatement(node, 'require'); | ||
return isGoogStatement(node, 'require'); | ||
}; | ||
@@ -32,0 +32,0 @@ |
@@ -6,20 +6,6 @@ 'use strict'; | ||
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); | ||
} | ||
exports.rule = { | ||
meta: { | ||
docs: { | ||
description: 'require the first ol.provide() has an arg named like the file path' | ||
description: 'require the first goog.provide() has an arg named like the file path' | ||
} | ||
@@ -39,11 +25,11 @@ }, | ||
if (parent.type !== 'ExpressionStatement') { | ||
return context.report(expression, 'Expected ol.provide() to in an expression statement'); | ||
return context.report(expression, 'Expected goog.provide() to in an expression statement'); | ||
} | ||
if (parent.parent.type !== 'Program') { | ||
return context.report(expression, 'Expected ol.provide() to be at the top level'); | ||
return context.report(expression, 'Expected goog.provide() to be at the top level'); | ||
} | ||
if (expression.arguments.length !== 1) { | ||
return context.report(expression, 'Expected one argument for ol.require()'); | ||
return context.report(expression, 'Expected one argument for goog.require()'); | ||
} | ||
@@ -53,18 +39,17 @@ | ||
if (arg.type !== 'Literal' || !arg.value || typeof arg.value !== 'string') { | ||
return context.report(expression, 'Expected ol.require() to be called with a string'); | ||
return context.report(expression, 'Expected goog.require() to be called with a string'); | ||
} | ||
const filePath = context.getFilename(); | ||
const sourceRoot = path.join(longestCommonPrefix(__dirname, filePath), 'src'); | ||
const sourceRoot = path.join(process.cwd(), 'src'); | ||
const requirePath = path.relative(sourceRoot, filePath); | ||
let ext; | ||
if (path.basename(requirePath) === 'index.js') { | ||
ext = path.sep + 'index.js'; | ||
} else { | ||
ext = '.js'; | ||
const ext = '.js'; | ||
let name = arg.value; | ||
// special case for main entry point | ||
if (name === 'ol') { | ||
name += '.index'; | ||
} | ||
const name = arg.value; | ||
const expectedPath = name.split('.').join(path.sep) + ext; | ||
if (expectedPath.toLowerCase() !== requirePath.toLowerCase()) { | ||
return context.report(expression, `Expected ol.provide('${name}') to be like ${requirePath}`); | ||
return context.report(expression, `Expected goog.provide('${name}') to be like ${requirePath}`); | ||
} | ||
@@ -71,0 +56,0 @@ } |
@@ -8,3 +8,3 @@ 'use strict'; | ||
docs: { | ||
description: 'require that all ol.require() have a valid arg and appear at the top level' | ||
description: 'require that all goog.require() have a valid arg and appear at the top level' | ||
} | ||
@@ -19,11 +19,11 @@ }, | ||
if (parent.type !== 'ExpressionStatement') { | ||
return context.report(expression, 'Expected ol.require() to be in an expression statement'); | ||
return context.report(expression, 'Expected goog.require() to be in an expression statement'); | ||
} | ||
if (parent.parent.type !== 'Program') { | ||
return context.report(expression, 'Expected ol.require() to be at the top level'); | ||
return context.report(expression, 'Expected goog.require() to be at the top level'); | ||
} | ||
if (expression.arguments.length !== 1) { | ||
return context.report(expression, 'Expected one argument for ol.require()'); | ||
return context.report(expression, 'Expected one argument for goog.require()'); | ||
} | ||
@@ -33,3 +33,3 @@ | ||
if (arg.type !== 'Literal' || !arg.value || typeof arg.value !== 'string') { | ||
return context.report(expression, 'Expected ol.require() to be called with a string'); | ||
return context.report(expression, 'Expected goog.require() to be called with a string'); | ||
} | ||
@@ -36,0 +36,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
13863
12
1
1
4
2
383