canonical
Version:
Canonical code style linter and formatter for JavaScript, SCSS, CSS and JSON.
44 lines (36 loc) • 1.18 kB
JavaScript
/**
* @fileoverview Restrict usage of specified node imports.
* @author Guy Ellis
* @copyright 2015 Guy Ellis. All rights reserved.
* See LICENSE file in root directory for full license.
*/
;
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = function(context) {
var restrictedImports = context.options;
// if no imports are restricted we don"t need to check
if (restrictedImports.length === 0) {
return {};
}
return {
"ImportDeclaration": function(node) {
if (node && node.source && node.source.value) {
var value = node.source.value.trim();
if (restrictedImports.indexOf(value) !== -1) {
context.report(node, "'{{importName}}' import is restricted from being used.", {
importName: value
});
}
}
}
};
};
module.exports.schema = {
"type": "array",
"items": {
"type": "string"
},
"uniqueItems": true
};