mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-29 03:45:15 +00:00
64 lines
5.7 KiB
JavaScript
64 lines
5.7 KiB
JavaScript
'use strict';var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { 'default': obj };}
|
|
|
|
function isRequire(node) {
|
|
return node &&
|
|
node.callee &&
|
|
node.callee.type === 'Identifier' &&
|
|
node.callee.name === 'require' &&
|
|
node.arguments.length >= 1;
|
|
}
|
|
|
|
function isDynamicImport(node) {
|
|
return node &&
|
|
node.callee &&
|
|
node.callee.type === 'Import';
|
|
}
|
|
|
|
function isStaticValue(arg) {
|
|
return arg.type === 'Literal' ||
|
|
arg.type === 'TemplateLiteral' && arg.expressions.length === 0;
|
|
}
|
|
|
|
module.exports = {
|
|
meta: {
|
|
type: 'suggestion',
|
|
docs: {
|
|
url: (0, _docsUrl2['default'])('no-dynamic-require') },
|
|
|
|
schema: [
|
|
{
|
|
type: 'object',
|
|
properties: {
|
|
esmodule: {
|
|
type: 'boolean' } },
|
|
|
|
|
|
additionalProperties: false }] },
|
|
|
|
|
|
|
|
|
|
create: function () {function create(context) {
|
|
var options = context.options[0] || {};
|
|
|
|
return {
|
|
CallExpression: function () {function CallExpression(node) {
|
|
if (!node.arguments[0] || isStaticValue(node.arguments[0])) {
|
|
return;
|
|
}
|
|
if (isRequire(node)) {
|
|
return context.report({
|
|
node: node,
|
|
message: 'Calls to require() should use string literals' });
|
|
|
|
}
|
|
if (options.esmodule && isDynamicImport(node)) {
|
|
return context.report({
|
|
node: node,
|
|
message: 'Calls to import() should use string literals' });
|
|
|
|
}
|
|
}return CallExpression;}() };
|
|
|
|
}return create;}() };
|
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1keW5hbWljLXJlcXVpcmUuanMiXSwibmFtZXMiOlsiaXN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bnNbMF0gfHwge307XG5cbiAgICByZXR1cm4ge1xuICAgICAgQ2FsbEV4cHJlc3Npb24obm9kZSkge1xuICAgICAgICBpZiAoIW5vZGUuYXJndW1lbnRzWzBdIHx8IGlzU3RhdGljVmFsdWUobm9kZS5hcmd1bWVudHNbMF0pKSB7XG4gICAgICAgICAgcmV0dXJuO1xuICAgICAgICB9XG4gICAgICAgIGlmIChpc1JlcXVpcmUobm9kZSkpIHtcbiAgICAgICAgICByZXR1cm4gY29udGV4dC5yZXBvcnQoe1xuICAgICAgICAgICAgbm9kZSxcbiAgICAgICAgICAgIG1lc3NhZ2U6ICdDYWxscyB0byByZXF1aXJlKCkgc2hvdWxkIHVzZSBzdHJpbmcgbGl0ZXJhbHMnLFxuICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgICAgIGlmIChvcHRpb25zLmVzbW9kdWxlICYmIGlzRHluYW1pY0ltcG9ydChub2RlKSkge1xuICAgICAgICAgIHJldHVybiBjb250ZXh0LnJlcG9ydCh7XG4gICAgICAgICAgICBub2RlLFxuICAgICAgICAgICAgbWVzc2FnZTogJ0NhbGxzIHRvIGltcG9ydCgpIHNob3VsZCB1c2Ugc3RyaW5nIGxpdGVyYWxzJyxcbiAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgICAgfSxcbiAgICB9O1xuICB9LFxufTtcbiJdfQ==
|