atom-nuclide
Version:
A unified developer experience for web and mobile development, built as a suite of features on top of Atom to provide hackability and the support of an active community.
51 lines (44 loc) • 1.29 kB
JavaScript
;
/* @noflow */
/*
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*/
/* NON-TRANSPILED FILE */
/* eslint-disable babel/func-params-comma-dangle, prefer-object-spread/prefer-object-spread */
const DEFAULT_TYPE_POSTFIX = 'Type';
function endWithTypePostfix(value) {
return value.length > DEFAULT_TYPE_POSTFIX.length &&
value.lastIndexOf(DEFAULT_TYPE_POSTFIX) === value.length - DEFAULT_TYPE_POSTFIX.length;
}
module.exports = function(context) {
function checkIdentifier(ident) {
if (!endWithTypePostfix(ident.name)) {
context.report({
node: ident,
data: {suggest: ident.name + DEFAULT_TYPE_POSTFIX},
message: 'Import type should be aliased as {{suggest}}',
});
}
}
return {
ImportNamespaceSpecifier(node) {
if (node.parent.importKind !== 'type') {
return;
}
checkIdentifier(node.local);
},
ImportSpecifier(node) {
if (node.parent.importKind !== 'type') {
return;
}
if (!node.imported || node.local.name === node.imported.name) {
return;
}
checkIdentifier(node.local);
},
};
};