Beispiel #1
0
        private void LintSelectedFiles(object sender, EventArgs e)
        {
            var           paths = ProjectHelpers.GetSelectedItemPaths();
            List <string> files = new List <string>();

            foreach (string path in paths)
            {
                if (Directory.Exists(path))
                {
                    var children = GetFiles(path, "*.*");
                    files.AddRange(children.Where(c => LinterService.IsFileSupported(c)));
                }
                else if (File.Exists(path) && LinterService.IsFileSupported(path))
                {
                    files.Add(path);
                }
            }

            if (files.Any())
            {
                LinterService.Lint(true, files.ToArray());
            }
            else
            {
                WebLinterPackage.Dte.StatusBar.Text = "No files found to lint";
            }
        }
 protected async System.Threading.Tasks.Task <bool> LintBuildSelection(bool isBuildingSolution)
 {
     try
     {
         Benchmark.Start();
         if (!LinterService.IsLinterEnabled)
         {
             return(false);
         }
         UIHierarchyItem[]           selectedItems = BuildSelectedItems.Get(isBuildingSolution);
         Dictionary <string, string> fileToProjectMap;
         string[] files = WebLinterPackage.Settings.UseTsConfig ?
                          TsconfigLocations.FindPathsFromSelectedItems(selectedItems, out fileToProjectMap) :
                          LintFileLocations.FindPathsFromSelectedItems(selectedItems, out fileToProjectMap);
         if (!files.Any())
         {
             return(false);
         }
         return(await LinterService.Lint(showErrorList : true, fixErrors : false, callSync : true,
                                         fileNames : files, clearAllErrors : true, fileToProjectMap));
     }
     catch (Exception ex)
     {
         Logger.LogAndWarn(ex);
         Linter.Server.Down();
         return(true);  // Return value is true if we have VS errors
     }
     finally { Benchmark.End(); }
 }
Beispiel #3
0
        internal static async System.Threading.Tasks.Task <bool> LintLintLint(bool fixErrors, UIHierarchyItem[] selectedItems)
        {
            IEnumerable <string> files = WebLinterPackage.Settings.UseTsConfig ?
                                         TsconfigLocations.FindPathsFromSelectedItems(selectedItems) :
                                         LintFileLocations.FindPathsFromSelectedItems(selectedItems);

            if (files.Any())
            {
                string[] filterFileNames = WebLinterPackage.Settings.UseTsConfig ?
                                           TsconfigLocations.FindFilterFiles(selectedItems) : null;
                return(await LinterService.Lint(showErrorList : true, fixErrors : fixErrors, callSync : false,
                                                fileNames : files.ToArray(), filterFileNames : filterFileNames));
            }
            else
            {
                WebLinterPackage.Dte.StatusBar.Text = $"No {(WebLinterPackage.Settings.UseTsConfig ? "tsconfig.json" : "ts or tsx")} files found to {(fixErrors ? "fix" : "lint")}";
                return(false);
            }
        }
        internal static async System.Threading.Tasks.Task <bool> LintSelectedItems(bool fixErrors, UIHierarchyItem[] selectedItems)
        {
            Dictionary <string, string> fileToProjectMap;
            IEnumerable <string>        files = WebLinterPackage.Settings.UseTsConfig ?
                                                TsconfigLocations.FindPathsFromSelectedItems(selectedItems, out fileToProjectMap) :
                                                LintFileLocations.FindPathsFromSelectedItems(selectedItems, out fileToProjectMap);

            if (files.Any())
            {
                bool clearAllErrors = AnyItemNotLintableSingleFile(selectedItems);
                return(await LinterService.Lint(showErrorList : true, fixErrors : fixErrors, callSync : false, fileNames : files.ToArray(),
                                                clearAllErrors, fileToProjectMap));
            }
            else
            {
                WebLinterPackage.Dte.StatusBar.Text = $"No {(WebLinterPackage.Settings.UseTsConfig ? "tsconfig.json" : "ts or tsx")}" +
                                                      $" files found to {(fixErrors ? "fix" : "lint")}";
                return(false);
            }
        }
Beispiel #5
0
 protected async System.Threading.Tasks.Task <bool> LintBuildSelection(bool isBuildingSolution)
 {
     try
     {
         if (!LinterService.IsLinterEnabled)
         {
             return(false);
         }
         UIHierarchyItem[]    selectedItems = WebLinterPackage.Dte.ToolWindows.SolutionExplorer.SelectedItems as UIHierarchyItem[];
         IEnumerable <string> files         = BuildFileLocations.GetBuildFilesToLint(isBuildingSolution, selectedItems,
                                                                                     WebLinterPackage.Settings.UseTsConfig);
         if (!files.Any())
         {
             return(false);
         }
         return(await LinterService.Lint(showErrorList : true, fixErrors : false, callSync : true, fileNames : files.ToArray()));
     }
     catch (Exception ex)
     {
         Logger.LogAndWarn(ex);
         Linter.Server.Down();
         return(false);
     }
 }