Gazebo_simulation-Frontend/node_modules/eslint-plugin-import/lib/rules/no-unassigned-import.js

87 lines
7.8 KiB
JavaScript
Raw Normal View History

2020-12-21 11:29:31 -04:00
'use strict';
var _path = require('path');
var _path2 = _interopRequireDefault(_path);
var _minimatch = require('minimatch');
var _minimatch2 = _interopRequireDefault(_minimatch);
var _staticRequire = require('../core/staticRequire');
var _staticRequire2 = _interopRequireDefault(_staticRequire);
var _docsUrl = require('../docsUrl');
var _docsUrl2 = _interopRequireDefault(_docsUrl);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function report(context, node) {
context.report({
node,
message: 'Imported module should be assigned'
});
}
function testIsAllow(globs, filename, source) {
if (!Array.isArray(globs)) {
return false; // default doesn't allow any patterns
}
let filePath;
if (source[0] !== '.' && source[0] !== '/') {
// a node module
filePath = source;
} else {
filePath = _path2.default.resolve(_path2.default.dirname(filename), source); // get source absolute path
}
return globs.find(glob => (0, _minimatch2.default)(filePath, glob) || (0, _minimatch2.default)(filePath, _path2.default.join(process.cwd(), glob))) !== undefined;
}
function create(context) {
const options = context.options[0] || {};
const filename = context.getFilename();
const isAllow = source => testIsAllow(options.allow, filename, source);
return {
ImportDeclaration(node) {
if (node.specifiers.length === 0 && !isAllow(node.source.value)) {
report(context, node);
}
},
ExpressionStatement(node) {
if (node.expression.type === 'CallExpression' && (0, _staticRequire2.default)(node.expression) && !isAllow(node.expression.arguments[0].value)) {
report(context, node.expression);
}
}
};
}
module.exports = {
create,
meta: {
docs: {
url: (0, _docsUrl2.default)('no-unassigned-import')
},
schema: [{
'type': 'object',
'properties': {
'devDependencies': { 'type': ['boolean', 'array'] },
'optionalDependencies': { 'type': ['boolean', 'array'] },
'peerDependencies': { 'type': ['boolean', 'array'] },
'allow': {
'type': 'array',
'items': {
'type': 'string'
}
}
},
'additionalProperties': false
}]
}
};
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInJ1bGVzL25v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