eslint-plugin-perfectionist
Version:
ESLint plugin for sorting various data such as objects, imports, types, enums, JSX props, etc.
35 lines (34 loc) • 1.08 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
const isCommentAboveOption = require('./is-comment-above-option.js')
const getCommentsBefore = require('./get-comments-before.js')
let getCommentAboveThatShouldExist = ({
rightGroupIndex,
leftGroupIndex,
sortingNode,
sourceCode,
options,
}) => {
if (leftGroupIndex !== null && leftGroupIndex >= rightGroupIndex) {
return null
}
let groupAboveRight = options.groups[rightGroupIndex - 1]
if (!isCommentAboveOption.isCommentAboveOption(groupAboveRight)) {
return null
}
let matchingCommentsAbove = getCommentsBefore
.getCommentsBefore({
node: sortingNode.node,
sourceCode,
})
.find(comment =>
commentMatches(comment.value, groupAboveRight.commentAbove),
)
return {
comment: groupAboveRight.commentAbove,
exists: !!matchingCommentsAbove,
}
}
let commentMatches = (comment, expected) =>
comment.toLowerCase().includes(expected.toLowerCase().trim())
exports.getCommentAboveThatShouldExist = getCommentAboveThatShouldExist