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(); }
 }
Exemplo n.º 2
0
        private async System.Threading.Tasks.Task 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())
            {
                await LinterService.LintAsync(true, files.ToArray());
            }
            else
            {
                WebLinterPackage.Dte.StatusBar.Text = "No files found to lint";
            }
        }
        private void CleanErrors(object sender, EventArgs e)
        {
            string msg    = "This will reset the configuration for all the linters to their defaults.\n\nDo you wish to continue?";
            var    result = MessageBox.Show(msg, Constants.VSIX_NAME, MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                LinterService.EnsureDefaults(true);
                WebLinterPackage.Dte.StatusBar.Text = "Web Linter configuration files have been reset";
            }
        }
Exemplo n.º 4
0
        private void BeforeQueryStatus(object sender, EventArgs e)
        {
            var button = (OleMenuCommand)sender;
            var paths  = ProjectHelpers.GetSelectedItemPaths();

            button.Visible = false;

            if (paths.Any(f => string.IsNullOrEmpty(Path.GetExtension(f)) || LinterService.IsFileSupported(f)))
            {
                button.Visible = true;
            }
        }
Exemplo n.º 5
0
        private async void ResetConfigurationFiles(object sender, EventArgs e)
        {
            string msg    = "This will reset the configuration for the TypeScript Analyzer to its defaults.\n\nDo you wish to continue?";
            var    result = MessageBox.Show(msg, Vsix.Name, MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                await LinterService.EnsureDefaultsAsync(true);

                WebLinterPackage.Settings.ResetSettings();
                WebLinterPackage.Dte.StatusBar.Text = "TypeScript Analyzer (tslint) configuration files have been reset";
            }
        }
Exemplo n.º 6
0
        private async void ResetConfigurationFiles(object sender, EventArgs e)
        {
            string msg    = "This will reset the configuration for all the linters to their defaults.\n\nDo you wish to continue?";
            var    result = MessageBox.Show(msg, Constants.VSIX_NAME, MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                await LinterService.EnsureDefaultsAsync(true);

                WebLinterPackage.Settings.ResetSettings();
                WebLinterPackage.Dte.StatusBar.Text = "Web Linter configuration files have been reset";
                Telemetry.TrackEvent($"VS Reset Configs");
            }
        }
Exemplo n.º 7
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);
            }
        }
Exemplo n.º 8
0
        private async void ResetConfigurationFiles(object sender, EventArgs e)
        {
            try
            {
                string msg    = "This will reset the configuration for the TypeScript Analyzer to its defaults.\n\nDo you wish to continue?";
                var    result = MessageBox.Show(msg, Vsix.Name, MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (result == DialogResult.Yes)
                {
                    await LinterService.CopyResourceFilesToUserProfile(true);

                    WebLinterPackage.Settings.ResetSettings();
                    WebLinterPackage.Dte.StatusBar.Text = "TypeScript Analyzer (tslint) configuration files have been reset";
                }
            }
            catch (Exception ex)
            {
                Logger.LogAndWarn(ex);
            }
        }
        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);
            }
        }
Exemplo n.º 10
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);
     }
 }