import * as path from 'path'
import fastDiff from 'fast-diff'
import { TextDocument, TextEdit } from 'vscode-languageserver'
-import { CLIOptions, Is, TextDocumentSettings } from './types'
+import { CLIOptions, ESLintProblem, Is, TextDocumentSettings } from './types'
import { URI } from 'vscode-uri'
-import resolveFrom from 'resolve-from'
interface Change {
start: number
const uri = URI.parse(document.uri)
if (uri.scheme != 'file') return []
const content = document.getText()
- const newOptions: CLIOptions = {...settings.options, fix: true}
+ const fixRule = (problem: ESLintProblem): boolean => {
+ return settings.autoFixSkipRules.indexOf(problem.ruleId) === -1;
+ }
+ const newOptions: CLIOptions = {...settings.options, fix: fixRule}
return executeInWorkspaceDirectory(document, settings, newOptions, (filename: string, options: CLIOptions) => {
if (!settings.validate) {
return []
return { start, end, newText }
}
-export function resolveModule(name: string, localPath: string, globalPath: string): Promise<string> {
- if (localPath) {
- let path = resolveFrom.silent(localPath, name)
- if (path) return Promise.resolve(path)
- }
- try {
- let path = resolveFrom(globalPath, name)
- return Promise.resolve(path)
- } catch (e) {
- return Promise.reject(e)
- }
-}
-
export function executeInWorkspaceDirectory(document: TextDocument, settings: TextDocumentSettings, newOptions: CLIOptions, callback: Function): TextEdit[] {
const filename = getFilePath(document)
const cwd = process.cwd()