Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Brief] Modification de la séparation du bloc commentaire #2030

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,35 @@ export function Comments({ comments }: { comments: string | undefined }) {
if (uglyComments.length < THRESHOLD) {
return [uglyComments]
}
const middle = Math.floor(uglyComments.length / 2)
const breakPointDot = uglyComments.lastIndexOf('.', middle)
const breakPointBreakline = uglyComments.lastIndexOf('\n', middle)
const breakPoint = Math.max(breakPointDot, breakPointBreakline)
const prettyComments: string[] = []
const firstParagraph = uglyComments.slice(0, breakPoint + 1)
const secondParagraph = uglyComments.slice(breakPoint + 1)

if (firstParagraph) {
prettyComments.push(firstParagraph)
}
if (secondParagraph) {
prettyComments.push(secondParagraph)
const closeToMiddle = Math.floor(uglyComments.length * (3 / 5))

// Chercher les points de rupture logiques proches du milieu
const punctuations = ['.', '!', '?', ';', ',', ':', '\n', '\r']
let breakPoint = -1

punctuations.forEach(ponctuation => {
const lastBeforeMiddle = uglyComments.lastIndexOf(ponctuation, closeToMiddle)
if (lastBeforeMiddle > breakPoint) {
breakPoint = lastBeforeMiddle
}
})

// if no punctuation find the word in the middle
if (breakPoint === -1) {
const commentWordByWord = uglyComments.split(' ')

const middleWordIndex = Math.floor(commentWordByWord.length / 2)

return [
commentWordByWord.slice(0, middleWordIndex + 1).join(' '),
commentWordByWord.slice(middleWordIndex + 1).join(' ')
].filter(Boolean)
}

return prettyComments
const firstParagraph = uglyComments.slice(0, breakPoint + 1).trim()
const secondParagraph = uglyComments.slice(breakPoint + 1).trim()

return [firstParagraph, secondParagraph].filter(Boolean)
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,35 @@ export function Comments({ comments }: { comments: string | undefined }) {
if (uglyComments.length < THRESHOLD) {
return [uglyComments]
}
const middle = Math.floor(uglyComments.length / 2)
const breakPointDot = uglyComments.lastIndexOf('.', middle)
const breakPointBreakline = uglyComments.lastIndexOf('\n', middle)
const breakPoint = Math.max(breakPointDot, breakPointBreakline)
const prettyComments: string[] = []
const firstParagraph = uglyComments.slice(0, breakPoint + 1)
const secondParagraph = uglyComments.slice(breakPoint + 1)

if (firstParagraph) {
prettyComments.push(firstParagraph)
}
if (secondParagraph) {
prettyComments.push(secondParagraph)
const closeToMiddle = Math.floor(uglyComments.length * (3 / 5))

// Chercher les points de rupture logiques proches du milieu
const punctuations = ['.', '!', '?', ';', ',', ':', '\n', '\r']
let breakPoint = -1

punctuations.forEach(ponctuation => {
const lastBeforeMiddle = uglyComments.lastIndexOf(ponctuation, closeToMiddle)
if (lastBeforeMiddle > breakPoint) {
breakPoint = lastBeforeMiddle
}
})

// if no punctuation find the word in the middle
if (breakPoint === -1) {
const commentWordByWord = uglyComments.split(' ')

const middleWordIndex = Math.floor(commentWordByWord.length / 2)

return [
commentWordByWord.slice(0, middleWordIndex + 1).join(' '),
commentWordByWord.slice(middleWordIndex + 1).join(' ')
].filter(Boolean)
}

return prettyComments
const firstParagraph = uglyComments.slice(0, breakPoint + 1).trim()
const secondParagraph = uglyComments.slice(breakPoint + 1).trim()

return [firstParagraph, secondParagraph].filter(Boolean)
}

return (
Expand Down
Loading