eslint-plugin-import-sorting
Version:
ESLint plugin to group and sort imports by module, à la Python isort
30 lines (29 loc) • 1.43 kB
JavaScript
;
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const utils = require("@typescript-eslint/utils");
function getCommentsBefore(node, source, tokenValueToIgnoreBefore) {
let commentsBefore = getCommentsBeforeNodeOrToken(node, source);
let tokenBeforeNode = source.getTokenBefore(node);
if (commentsBefore.length > 0 || !tokenValueToIgnoreBefore || (tokenBeforeNode == null ? void 0 : tokenBeforeNode.value) !== tokenValueToIgnoreBefore) {
return commentsBefore;
}
return getCommentsBeforeNodeOrToken(tokenBeforeNode, source);
}
function getCommentsBeforeNodeOrToken(node, source) {
return source.getCommentsBefore(node).filter((comment) => {
let tokenBeforeComment = source.getTokenBefore(comment);
return (tokenBeforeComment == null ? void 0 : tokenBeforeComment.loc.end.line) !== comment.loc.end.line;
});
}
function getCommentAfter(node, source) {
let token = source.getTokenAfter(node, {
filter: ({ value, type }) => !(type === utils.AST_TOKEN_TYPES.Punctuator && [",", ";", ":"].includes(value)),
includeComments: true
});
if (((token == null ? void 0 : token.type) === utils.AST_TOKEN_TYPES.Block || (token == null ? void 0 : token.type) === utils.AST_TOKEN_TYPES.Line) && node.loc.end.line === token.loc.end.line) {
return token;
}
return void 0;
}
exports.getCommentAfter = getCommentAfter;
exports.getCommentsBefore = getCommentsBefore;