Skip to content

Commit

Permalink
feat: detailed list for inclusive language check
Browse files Browse the repository at this point in the history
  • Loading branch information
NGPixel committed Jan 28, 2025
1 parent 120ea6e commit 7ce83f0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/components/DrawerChecks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,10 @@ function hyphenationCheck (silent = false) {
}
function inclusiveLangCheck (silent = false) {
const warnings = checkInclusiveLanguage(modelStore[docsStore.activeDocument.id].getValue())
if (warnings < 1) {
const results = checkInclusiveLanguage(modelStore[docsStore.activeDocument.id].getValue())
if (results.count < 1) {
editorStore.setValidationCheckState('inclusiveLanguage', 1)
editorStore.setValidationCheckDetails('inclusiveLanguage', [])
if (!silent) {
$q.notify({
message: 'Looks good!',
Expand All @@ -165,6 +166,7 @@ function inclusiveLangCheck (silent = false) {
}
} else {
editorStore.setValidationCheckState('inclusiveLanguage', -2)
editorStore.setValidationCheckDetails('inclusiveLanguage', results.details)
}
}
Expand Down
27 changes: 24 additions & 3 deletions src/tools/inclusive-language.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { find, flatten } from 'lodash-es'
import { find, flatten, sortBy } from 'lodash-es'
import { decorationsStore } from 'src/stores/models'

const dictionnary = [
Expand Down Expand Up @@ -41,9 +41,16 @@ export function checkInclusiveLanguage (text) {
const textLines = text.split('\n')

const decorations = []
const occurences = []
const details = []
for (const [lineIdx, line] of textLines.entries()) {
for (const match of line.matchAll(matchRgx)) {
const dictEntry = find(dictionnary, d => d.triggers.includes(match[1].toLowerCase()))
const term = match[1].toLowerCase()
const dictEntry = find(dictionnary, d => d.triggers.includes(term))
let occIdx = occurences.indexOf(term)
if (occIdx < 0) {
occIdx = occurences.push(term) - 1
}
decorations.push({
options: {
hoverMessage: {
Expand All @@ -62,10 +69,24 @@ export function checkInclusiveLanguage (text) {
endColumn: match.index + 1 + match[0].length
}
})
details.push({
key: crypto.randomUUID(),
group: occIdx + 1,
message: match[1].toLowerCase(),
range: {
startLineNumber: lineIdx + 1,
startColumn: match.index + 2,
endLineNumber: lineIdx + 1,
endColumn: match.index + 1 + match[0].length
}
})
}
}

decorationsStore.get('inclusiveLanguage').set(decorations)

return decorations.length
return {
count: decorations.length,
details: sortBy(details, d => d.range.startLineNumber)
}
}

0 comments on commit 7ce83f0

Please sign in to comment.