Skip to content

Commit

Permalink
fix: basic mistake. damnn
Browse files Browse the repository at this point in the history
  • Loading branch information
lvjiaxuan committed Jan 11, 2024
1 parent da9572e commit 6db8fa7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
9 changes: 4 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from 'node:path'
import type { ExtensionContext } from 'vscode'
import { Position, Range, Selection, SnippetString, TextEditorRevealType, commands, languages, window } from 'vscode'
import { existFileSync, getTextBylines, isDisablingComment } from './utils'
import { blockCommentRegex, getBlockComment, getLineComment, languageId } from './languageDefaults'
import { blockCommentRegex, getBlockComment, getLineComment, languageIdExts } from './languageDefaults'
import log, { channel } from './log'

const disableSelection = commands.registerCommand('eslint-disable.disable', () => {
Expand All @@ -28,16 +28,15 @@ const disableSelection = commands.registerCommand('eslint-disable.disable', () =
const lineComment = getLineComment(languageId)
const blockComment = getBlockComment(languageId)

if (selection.isSingleLine && !isDisablingComment(text, languageId)) {
if (selection.isSingleLine) {
// Insert at previous line.
void activeTextEditor.insertSnippet(
!isDisablingComment(text, languageId) && void activeTextEditor.insertSnippet(
new SnippetString(`${lineComment} eslint-disable-next-line \${1:${[...insertRules].join(', ')}}\n`),
new Position(selection.anchor.line, insertIndex),
)
}
else {
// Wrap lines and Press `ctrl+d` to edit rules between lines.

void (async () => {
await activeTextEditor.insertSnippet(
new SnippetString(`${' '.repeat(insertIndex)}${blockComment[0]} eslint-enable ${[...insertRules].join(', ')} ${blockComment[1]}\n`),
Expand Down Expand Up @@ -183,7 +182,7 @@ function getESLintDiagnostics() {

const uri = activeTextEditor.document.uri.toString()

if (!languageId.includes(path.extname(uri).replace(/^\./, ''))) {
if (!languageIdExts.includes(path.extname(uri).replace(/^\./, ''))) {
log('Sorry, it is a unsupported file extension for now.', true, 'OK')
return
}
Expand Down
4 changes: 2 additions & 2 deletions src/languageDefaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ interface LanguageConfig {
blockComment: [string, string]
}

export const languageId = ['javascript', 'javascriptreact', 'typescript', 'typescriptreact', 'html', 'vue', 'coffeescript', 'yaml', 'graphql'] // as const

const languageId2Config: Map<string, LanguageConfig> = new Map([
['javascript', { ext: 'js', lineComment: '//', blockComment: ['/*', '*/'] }],
['javascriptreact', { ext: 'jsx', lineComment: '//', blockComment: ['/*', '*/'] }],
Expand All @@ -20,6 +18,8 @@ const languageId2Config: Map<string, LanguageConfig> = new Map([
['graphql', { ext: 'graphql', lineComment: '#', blockComment: ['#', ''] }],
])

export const languageIdExts = [...languageId2Config.values()].map(i => i.ext)

export const blockCommentRegex: { [x: string]: string } = {
'/*': '\\/\\*',
'*/': '\\*\\/',
Expand Down
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export function isDisablingComment(text: string, languageId: string) {

if (text.startsWith(blockLike) || text.startsWith(lineLike)) {
log('Your selected line is a disabling comment.')
return false
return true
}

return true
return false
}

0 comments on commit 6db8fa7

Please sign in to comment.