Skip to content

Commit

Permalink
chore: better logic
Browse files Browse the repository at this point in the history
  • Loading branch information
lvjiaxuan committed Mar 22, 2023
1 parent 186c692 commit d80e327
Showing 1 changed file with 6 additions and 28 deletions.
34 changes: 6 additions & 28 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,15 @@ const disableForLines = commands.registerCommand('eslint-disable.disable', () =>
return
}

const { text, selection, activeTextEditor, eslintDiagnostics } = result
const { text, selection, activeTextEditor, eslintDiagnostics, selectionDiagnostics } = result

let insertIndex = 0
while (text.charAt(insertIndex) == ' ') {
insertIndex++
}

const insertRules = eslintDiagnostics.reduce((insertRules, item) => {
const isRuleInLine = selection.isSingleLine
? item.range.start.line === selection.start.line
: selection.start.line <= item.range.start.line && item.range.start.line <= selection.end.line

if (isRuleInLine) {
// @ts-ignore
insertRules.add(item.code.value as string)
}
return insertRules
}, new Set<string>())
// @ts-ignore
const insertRules = new Set(selectionDiagnostics.map(item => item.code.value as string))

const lineComment = getLineComment(activeTextEditor.document.languageId)
const blockComment = getBlockComment(activeTextEditor.document.languageId)
Expand Down Expand Up @@ -73,23 +64,10 @@ const disableForFile = commands.registerCommand('eslint-disable.entire', async (
return
}

const { selection, activeTextEditor, eslintDiagnostics } = result

let insertRules = eslintDiagnostics.reduce((insertRules, item) => {

let isAlwaysAdd: boolean = allRules
if (!isAlwaysAdd) {
isAlwaysAdd = selection.isSingleLine
? item.range.start.line === selection.start.line
: selection.start.line <= item.range.start.line && item.range.start.line <= selection.end.line
}
const { selection, activeTextEditor, eslintDiagnostics, selectionDiagnostics } = result

if (isAlwaysAdd) {
// @ts-ignore
insertRules.add(item.code.value as string)
}
return insertRules
}, new Set<string>())
// @ts-ignore
const insertRules = new Set((allRules ? eslintDiagnostics : selectionDiagnostics).map(item => item.code.value as string))

// TODO Maybe not 0 line.
const startLineText = getTextBylines(0)
Expand Down

0 comments on commit d80e327

Please sign in to comment.