Example #1
0
        public async Task LintAsync(ILinterProvider provider, string filePath, CancellationToken token)
        {
            try
            {
                await _mutex.WaitAsync(token).ConfigureAwait(false);

                try
                {
                    token.ThrowIfCancellationRequested();

                    var directoryPath = Path.GetDirectoryName(filePath) ??
                                        throw new Exception($"exception: could not get directory for file {filePath}");

                    var eslintPath = EslintHelper.GetEslintPath(directoryPath);
                    var arguments  = string.Join(" ", QuoteArgument(filePath), EslintHelper.GetArguments(directoryPath));

                    var output = await RunAsync(eslintPath, arguments, token)
                                 .ConfigureAwait(false);

                    token.ThrowIfCancellationRequested();

                    if (string.IsNullOrEmpty(output))
                    {
                        throw new Exception("exception: linter returned empty result");
                    }

                    IEnumerable <EslintResult> results = new List <EslintResult>();

                    try
                    {
                        results = JsonConvert.DeserializeObject <IEnumerable <EslintResult> >(output);
                    }
                    catch (Exception e)
                    {
                        OutputWindowHelper.WriteLine(
                            "exception: error trying to deserialize output:" +
                            Environment.NewLine +
                            output);

                        OutputWindowHelper.WriteLine(e.Message);
                    }

                    var messages = ProcessResults(results);

                    token.ThrowIfCancellationRequested();

                    provider.Accept(filePath, messages);
                }
                catch (OperationCanceledException)
                { }
                catch (Exception e)
                {
                    OutputWindowHelper.WriteLine(e.Message);
                }
                finally
                {
                    _mutex.Release();
                }
            }
            catch (OperationCanceledException)
            { }
            catch (Exception e)
            {
                OutputWindowHelper.WriteLine(e.Message);
            }
        }
Example #2
0
        public async Task LintAsync(ILinterProvider provider, string filePath, CancellationToken token)
        {
            try
            {
                await _mutex.WaitAsync(token).ConfigureAwait(false);

                try
                {
                    token.ThrowIfCancellationRequested();

                    var relativePath = Path.GetDirectoryName(filePath) ??
                                       throw new Exception($"exception: could not get directory for file {filePath}");

                    var executable = EslintHelper.GetExecutableInfo(relativePath);
                    var config     = EslintHelper.GetConfigInfo(relativePath);
                    var ignore     = EslintHelper.GetIgnoreInfo(relativePath);

                    var arguments = GetArguments(filePath, config?.FullName, ignore?.FullName);

                    var output = await RunAsync(config?.DirectoryName, executable.FullName, arguments, token)
                                 .ConfigureAwait(false);

                    token.ThrowIfCancellationRequested();

                    if (string.IsNullOrEmpty(output))
                    {
                        throw new Exception("linter returned empty result~ please read output for detailed information ^");
                    }

                    IEnumerable <EslintResult> results = new List <EslintResult>();

                    try
                    {
                        results = JsonConvert.DeserializeObject <IEnumerable <EslintResult> >(output);
                    }
                    catch (Exception e)
                    {
                        OutputWindowHelper.WriteLine(
                            "exception: error trying to deserialize output:" +
                            Environment.NewLine +
                            output);

                        OutputWindowHelper.WriteLine(e.Message);
                    }

                    var messages = ProcessResults(results);

                    token.ThrowIfCancellationRequested();

                    provider.Accept(filePath, messages);
                }
                catch (OperationCanceledException)
                { }
                catch (Exception e)
                {
                    OutputWindowHelper.WriteLine(e.Message);
                }
                finally
                {
                    _mutex.Release();
                }
            }
            catch (OperationCanceledException)
            { }
            catch (Exception e)
            {
                OutputWindowHelper.WriteLine(e.Message);
            }
        }