mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-24 09:25:15 +00:00
137 lines
14 KiB
JavaScript
137 lines
14 KiB
JavaScript
'use strict';
|
|
|
|
|
|
|
|
|
|
var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { 'default': obj };}
|
|
|
|
var EXPORT_MESSAGE = 'Expected "export" or "export default"'; /**
|
|
* @fileoverview Rule to prefer ES6 to CJS
|
|
* @author Jamund Ferguson
|
|
*/var IMPORT_MESSAGE = 'Expected "import" instead of "require()"';function normalizeLegacyOptions(options) {
|
|
if (options.indexOf('allow-primitive-modules') >= 0) {
|
|
return { allowPrimitiveModules: true };
|
|
}
|
|
return options[0] || {};
|
|
}
|
|
|
|
function allowPrimitive(node, options) {
|
|
if (!options.allowPrimitiveModules) return false;
|
|
if (node.parent.type !== 'AssignmentExpression') return false;
|
|
return node.parent.right.type !== 'ObjectExpression';
|
|
}
|
|
|
|
function allowRequire(node, options) {
|
|
return options.allowRequire;
|
|
}
|
|
|
|
function allowConditionalRequire(node, options) {
|
|
return options.allowConditionalRequire !== false;
|
|
}
|
|
|
|
function validateScope(scope) {
|
|
return scope.variableScope.type === 'module';
|
|
}
|
|
|
|
// https://github.com/estree/estree/blob/master/es5.md
|
|
function isConditional(node) {
|
|
if (
|
|
node.type === 'IfStatement' ||
|
|
node.type === 'TryStatement' ||
|
|
node.type === 'LogicalExpression' ||
|
|
node.type === 'ConditionalExpression')
|
|
return true;
|
|
if (node.parent) return isConditional(node.parent);
|
|
return false;
|
|
}
|
|
|
|
function isLiteralString(node) {
|
|
return node.type === 'Literal' && typeof node.value === 'string' ||
|
|
node.type === 'TemplateLiteral' && node.expressions.length === 0;
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Rule Definition
|
|
//------------------------------------------------------------------------------
|
|
|
|
var schemaString = { 'enum': ['allow-primitive-modules'] };
|
|
var schemaObject = {
|
|
type: 'object',
|
|
properties: {
|
|
allowPrimitiveModules: { 'type': 'boolean' },
|
|
allowRequire: { 'type': 'boolean' },
|
|
allowConditionalRequire: { 'type': 'boolean' } },
|
|
|
|
additionalProperties: false };
|
|
|
|
|
|
module.exports = {
|
|
meta: {
|
|
type: 'suggestion',
|
|
docs: {
|
|
url: (0, _docsUrl2['default'])('no-commonjs') },
|
|
|
|
|
|
schema: {
|
|
anyOf: [
|
|
{
|
|
type: 'array',
|
|
items: [schemaString],
|
|
additionalItems: false },
|
|
|
|
{
|
|
type: 'array',
|
|
items: [schemaObject],
|
|
additionalItems: false }] } },
|
|
|
|
|
|
|
|
|
|
|
|
create: function () {function create(context) {
|
|
var options = normalizeLegacyOptions(context.options);
|
|
|
|
return {
|
|
|
|
'MemberExpression': function () {function MemberExpression(node) {
|
|
|
|
// module.exports
|
|
if (node.object.name === 'module' && node.property.name === 'exports') {
|
|
if (allowPrimitive(node, options)) return;
|
|
context.report({ node: node, message: EXPORT_MESSAGE });
|
|
}
|
|
|
|
// exports.
|
|
if (node.object.name === 'exports') {
|
|
var isInScope = context.getScope().
|
|
variables.
|
|
some(function (variable) {return variable.name === 'exports';});
|
|
if (!isInScope) {
|
|
context.report({ node: node, message: EXPORT_MESSAGE });
|
|
}
|
|
}
|
|
|
|
}return MemberExpression;}(),
|
|
'CallExpression': function () {function CallExpression(call) {
|
|
if (!validateScope(context.getScope())) return;
|
|
|
|
if (call.callee.type !== 'Identifier') return;
|
|
if (call.callee.name !== 'require') return;
|
|
|
|
if (call.arguments.length !== 1) return;
|
|
if (!isLiteralString(call.arguments[0])) return;
|
|
|
|
if (allowRequire(call, options)) return;
|
|
|
|
if (allowConditionalRequire(call, options) && isConditional(call.parent)) return;
|
|
|
|
// keeping it simple: all 1-string-arg `require` calls are reported
|
|
context.report({
|
|
node: call.callee,
|
|
message: IMPORT_MESSAGE });
|
|
|
|
}return CallExpression;}() };
|
|
|
|
|
|
}return create;}() };
|
|
//# sourceMappingURL=data:application/json;charset=utf-8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ogZmFsc2UsXG59O1xuXG5tb2R1bGUuZXhwb3J0cyA9IHtcbiAgbWV0YToge1xuICAgIHR5cGU6ICdzdWdnZXN0aW9uJyxcbiAgICBkb2NzOiB7XG4gICAgICB1cmw6IGRvY3NVcmwoJ25vLWNvbW1vbmpzJyksXG4gICAgfSxcblxuICAgIHNjaGVtYToge1xuICAgICAgYW55T2Y6IFtcbiAgICAgICAge1xuICAgICAgICAgIHR5cGU6ICdhcnJheScsXG4gICAgICAgICAgaXRlbXM6IFtzY2hlbWFTdHJpbmddLFxuICAgICAgICAgIGFkZGl0aW9uYWxJdGVtczogZmFsc2UsXG4gICAgICAgIH0sXG4gICAgICAgIHtcbiAgICAgICAgICB0eXBlOiAnYXJyYXknLFxuICAgICAgICAgIGl0ZW1zOiBbc2NoZW1hT2JqZWN0XSxcbiAgICAgICAgICBhZGRpdGlvbmFsSXRlbXM6IGZhbHNlLFxuICAgICAgICB9LFxuICAgICAgXSxcbiAgICB9LFxuICB9LFxuXG4gIGNyZWF0ZTogZnVuY3Rpb24gKGNvbnRleHQpIHtcbiAgICBjb25zdCBvcHRpb25zID0gbm9ybWFsaXplTGVnYWN5T3B0aW9ucyhjb250ZXh0Lm9wdGlvbnMpO1xuXG4gICAgcmV0dXJuIHtcblxuICAgICAgJ01lbWJlckV4cHJlc3Npb24nOiBmdW5jdGlvbiAobm9kZSkge1xuXG4gICAgICAgIC8vIG1vZHVsZS5leHBvcnRzXG4gICAgICAgIGlmIChub2RlLm9iamVjdC5uYW1lID09PSAnbW9kdWxlJyAmJiBub2RlLnByb3BlcnR5Lm5hbWUgPT09ICdleHBvcnRzJykge1xuICAgICAgICAgIGlmIChhbGxvd1ByaW1pdGl2ZShub2RlLCBvcHRpb25zKSkgcmV0dXJuO1xuICAgICAgICAgIGNvbnRleHQucmVwb3J0KHsgbm9kZSwgbWVzc2FnZTogRVhQT1JUX01FU1NBR0UgfSk7XG4gICAgICAgIH1cblxuICAgICAgICAvLyBleHBvcnRzLlxuICAgIC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