Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-eslint / server / util.ts
index d8f2eb4c15c2e9131d67267a62ca7a42f30482a6..32c0aa1ac1b13919ffb7bbf82ab40c967ecbfb30 100644 (file)
@@ -1,9 +1,8 @@
 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
@@ -91,7 +90,10 @@ export function getAllFixEdits(document: TextDocument, settings: TextDocumentSet
   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 []
@@ -143,19 +145,6 @@ export function getChange(oldStr: string, newStr: string): Change {
   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()