Skip to content

Commit

Permalink
feat: detected unsupported exts
Browse files Browse the repository at this point in the history
  • Loading branch information
lvjiaxuan committed Jan 11, 2024
1 parent 9f9ffc7 commit 02d0fb9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 8 additions & 2 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 } from './utils'
import { blockCommentRegex, getBlockComment, getLineComment } from './languageDefaults'
import { blockCommentRegex, getBlockComment, getLineComment, languageId } from './languageDefaults'
import log, { channel } from './log'

const disableSelection = commands.registerCommand('eslint-disable.disable', () => {
Expand Down Expand Up @@ -179,8 +179,14 @@ function getESLintDiagnostics() {
if (!existFileSync(fileName))
return

const { selection /* selections might be supported later */ } = activeTextEditor
const uri = activeTextEditor.document.uri.toString()

if (!languageId.includes(path.extname(uri).replace(/^\./, ''))) {
log('Sorry, it is a unsupported file extension for now.', true, 'OK')
return
}

const { selection /* selections might be supported later */ } = activeTextEditor
const basename = path.basename(uri)

const text = getTextBylines(selection.start.line, selection.end.line)
Expand Down
2 changes: 2 additions & 0 deletions src/languageDefaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ 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 Down

0 comments on commit 02d0fb9

Please sign in to comment.