public void Spec01()
            {
                var target = new JSLintNetSettings()
                {
                    Output = Output.Error
                };

                var merge = new JSLintNetSettings()
                {
                    Output = Output.Message
                };

                target.Merge(merge);

                I.Expect(target.Output).Not.ToBe(Output.Error);
                I.Expect(target.Output).ToBe(Output.Message);
            }
Пример #2
0
            public void Spec04()
            {
                var settings = new JSLintNetSettings()
                {
                    Options = new JSLintOptions()
                    {
                        AssumeBrowser            = true,
                        TolerateUnusedParameters = true
                    }
                };

                settings.Options.PredefinedGlobals.Add("MyGlobal", false);

                var actual = this.Instance.SerializeSettings(settings);

                I.Expect(actual).ToMatch(@"""options"": \{\s*""predef"": \{\s*""MyGlobal"": false\s*\},\s*""browser"": true,\s*""unparam"": true\s*\}");
            }
Пример #3
0
            public void Spec04()
            {
                var settings = new JSLintNetSettings()
                {
                    Options = new JSLintOptions()
                    {
                        AssumeBrowser           = true,
                        TolerateMessyWhitespace = true
                    }
                };

                settings.GlobalVariables.Add("MyGlobal");

                var actual = this.Instance.SerializeSettings(settings);

                I.Expect(actual).ToMatch(@"""options"": \{\s*""browser"": true,\s*""white"": true\s*\},\s*""globalVariables"": \[\s*""MyGlobal""\s*\]");
            }
            public void Spec07()
            {
                var target = new JSLintNetSettings();

                target.ErrorLimit  = 50;
                target.RunOnBuild  = false;
                target.CancelBuild = true;

                var merge = new JSLintNetSettings();

                merge.ErrorLimit = 100;
                merge.RunOnBuild = true;
                merge.RunOnSave  = false;

                target.Merge(merge);

                I.Expect(target.ErrorLimit).ToBe(100);
                I.Expect(target.RunOnBuild).ToBeTrue();
                I.Expect(target.CancelBuild).ToBeTrue();
                I.Expect(target.RunOnSave).ToBeFalse();
            }
Пример #5
0
        /// <summary>
        /// Validates the specified document using JSLint.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="settings">The settings.</param>
        /// <returns>
        /// The total number of JSLint errors found.
        /// </returns>
        public int LintDocument(Document document, JSLintNetSettings settings)
        {
            this.errorListProvider.ClearJSLintErrors(document.FullName);

            int errors;
            var source    = document.Access().Source;
            var hierarchy = this.GetHierarchy(document.ProjectItem.ContainingProject);

            using (var jsLintContext = this.jsLintFactory())
            {
                var result = jsLintContext.Lint(source, settings.Options, settings.GlobalVariables);

                this.errorListProvider.AddJSLintErrors(document.FullName, result.Warnings, settings.Output, hierarchy);

                errors = result.Warnings.Count;
                var text = GetMessageText(errors);
                this.SetStatusBar(text);
            }

            return(errors);
        }
Пример #6
0
        private IList <TaskFile> GetSourceFiles(JSLintNetSettings settings)
        {
            var ignored   = settings.NormalizeIgnore();
            var taskFiles = new List <TaskFile>();

            if (this.sourceFilesSet)
            {
                foreach (var item in this.SourceFiles)
                {
                    if (JSLint.CanLint(item.ItemSpec))
                    {
                        var taskFile = new TaskFile(this.SourceDirectory, item);

                        if (!taskFile.IsIgnored(ignored))
                        {
                            taskFiles.Add(taskFile);
                        }
                    }
                }

                return(taskFiles);
            }

            var files = this.fileSystemWrapper.GetFiles(this.SourceDirectory, "*", SearchOption.AllDirectories);

            foreach (var file in files)
            {
                if (JSLint.CanLint(file))
                {
                    var taskFile = new TaskFile(this.SourceDirectory, file);

                    if (!taskFile.IsIgnored(ignored))
                    {
                        taskFiles.Add(taskFile);
                    }
                }
            }

            return(taskFiles);
        }
Пример #7
0
 /// <summary>
 /// Serializes the settings.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <returns>
 /// A serialized JSON string.
 /// </returns>
 public string SerializeSettings(JSLintNetSettings value)
 {
     return(JsonConvert.SerializeObject(value, SerializerSettings));
 }
Пример #8
0
        /// <summary>
        /// Validates the specified project items using JSLint.
        /// </summary>
        /// <param name="projectItems">The project items.</param>
        /// <param name="settings">The settings.</param>
        /// <returns>
        /// The total number of JSLint errors found.
        /// </returns>
        public int LintProjectItems(IList <ProjectItem> projectItems, JSLintNetSettings settings)
        {
            if (projectItems.Count < 1)
            {
                return(0);
            }

            var hierarchy  = this.GetHierarchy(projectItems[0].ContainingProject);
            var errors     = 0;
            var files      = 0;
            var errorFiles = 0;
            var exceptions = 0;
            var errorLimit = settings.ErrorLimitOrDefault();
            var filesLimit = settings.FileLimitOrDefault();

            using (var jsLintContext = this.jsLintFactory())
            {
                foreach (var item in projectItems)
                {
                    var fileName = item.Access().FileName;
                    this.errorListProvider.ClearJSLintErrors(fileName);

                    var isOpen = item.Document != null;

                    var result = ExecutionHelper.Try(() =>
                    {
                        string source;
                        if (isOpen)
                        {
                            source = item.Document.Access().Source;
                        }
                        else
                        {
                            source = this.fileSystemWrapper.ReadAllText(fileName, Encoding.UTF8);
                        }

                        return(jsLintContext.Lint(source, settings.Options, settings.GlobalVariables));
                    });

                    if (result.Success)
                    {
                        var data = result.Data;

                        if (data.Warnings.Count > 0)
                        {
                            errors     += data.Warnings.Count;
                            errorFiles += 1;

                            this.errorListProvider.AddJSLintErrors(fileName, data.Warnings, settings.Output, hierarchy);

                            if (errors >= errorLimit)
                            {
                                this.errorListProvider.AddCustomError(CoreResources.ErrorLimitReachedFormat, errors);

                                break;
                            }
                        }
                    }
                    else
                    {
                        var ex = result.Exception;

                        this.errorListProvider.AddCustomError(CoreResources.ProcessingExceptionFormat, fileName, ex.Message);

                        exceptions += 1;

                        if (exceptions >= JSLintNetSettings.ExceptionLimit)
                        {
                            this.errorListProvider.AddCustomError(CoreResources.ExceptionLimitReachedFormat, exceptions);

                            break;
                        }
                    }

                    files += 1;

                    if (files >= filesLimit)
                    {
                        this.errorListProvider.AddCustomError(CoreResources.FileLimitReachedFormat, files);

                        break;
                    }
                }
            }

            var text = GetMessageText(projectItems.Count, errorFiles, errors);

            this.SetStatusBar(text);

            return(errors);
        }