12345678910111213141516171819202122232425262728293031323334353637 |
- '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 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: [] },
- create: function (context) {
- return {
- CallExpression(node) {
- if (isRequire(node) && !isStaticValue(node.arguments[0])) {
- context.report({
- node,
- message: 'Calls to require() should use string literals' });
- }
- } };
- } };
|