예제 #1
0
        public List <JSLintError> Lint(string javascript, JSLintOptions configuration, bool isJavaScript)
        {
            if (string.IsNullOrEmpty(javascript))
            {
                throw new ArgumentNullException("javascript");
            }

            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            lock (_lock)
            {
                Linters           linterToUse = isJavaScript ? configuration.SelectedLinter : Linters.JSLint;
                JavascriptContext context     = GetLinterContext(linterToUse);

                LintDataCollector dataCollector = new LintDataCollector(configuration.ErrorOnUnused);
                // Setting the externals parameters of the context
                context.SetParameter("dataCollector", dataCollector);
                context.SetParameter("javascript", javascript);
                context.SetParameter("options", configuration.ToJsOptionVar(linterToUse));

                // Running the script
                context.Run("lintRunner(linterName, dataCollector, javascript, options);");

                return(dataCollector.Errors);
            }
        }
예제 #2
0
        private static void MigrateOptions(JSLintOptions jsLintOptions, IDictionary <string, object> options)
        {
            if (options.ContainsKey("evil"))
            {
                var evil = options["evil"] as bool?;

                if (evil.HasValue)
                {
                    jsLintOptions.TolerateEval = evil;
                }
            }
        }
예제 #3
0
            public void Spec03()
            {
                var target = new JSLintOptions();
                target.PredefinedGlobals.Add("jasmine", false);

                var merge = new JSLintOptions();
                merge.PredefinedGlobals.Add("jasmine", true);

                target.Merge(merge);

                I.Expect(target.PredefinedGlobals["jasmine"]).ToBeTrue();
            }
예제 #4
0
            public void Spec02()
            {
                var target = new JSLintOptions();
                target.PredefinedGlobals.Add("jQuery", false);

                var merge = new JSLintOptions();
                merge.PredefinedGlobals.Add("$", false);

                target.Merge(merge);

                I.Expect(target.PredefinedGlobals).ToContainKey("$");
                I.Expect(target.PredefinedGlobals).ToContainKey("jQuery");
            }
예제 #5
0
        public OptionsViewModel(JSLintOptions jslintoptions)
        {
            this._options = jslintoptions;

            Linters = new ObservableCollection <LinterViewModel>();
            Linters.Add(new LinterViewModel(new LinterModel("JSLint", JSLint.Framework.OptionClasses.Linters.JSLint), jslintoptions));
            Linters.Add(new LinterViewModel(new LinterModel("JSLint Old", JSLint.Framework.OptionClasses.Linters.JSLintOld), jslintoptions));
            Linters.Add(new LinterViewModel(new LinterModel("JSHint", JSLint.Framework.OptionClasses.Linters.JSHint)
            {
                HasUnusedVariableOptionBakedIn = true, HasQuotMarkOption = true, HasMaxComplexityOptions = true
            }, jslintoptions));
            LoadSelected();
        }
예제 #6
0
            public void Spec03()
            {
                var target = new JSLintOptions();

                target.PredefinedGlobals.Add("jasmine", false);

                var merge = new JSLintOptions();

                merge.PredefinedGlobals.Add("jasmine", true);

                target.Merge(merge);

                I.Expect(target.PredefinedGlobals["jasmine"]).ToBeTrue();
            }
예제 #7
0
            public void Spec02()
            {
                var target = new JSLintOptions();

                target.PredefinedGlobals.Add("jQuery", false);

                var merge = new JSLintOptions();

                merge.PredefinedGlobals.Add("$", false);

                target.Merge(merge);

                I.Expect(target.PredefinedGlobals).ToContainKey("$");
                I.Expect(target.PredefinedGlobals).ToContainKey("jQuery");
            }
예제 #8
0
        private void MergeOptions(JSLintNetSettings merge)
        {
            if (merge.Options == null)
            {
                return;
            }

            if (this.Options == null)
            {
                this.Options = merge.Options;

                return;
            }

            this.Options.Merge(merge.Options);
        }
예제 #9
0
            public void Spec02()
            {
                using (var testable = new LintTestable())
                {
                    var options = new JSLintOptions()
                    {
                        TolerateStupidPractices = true
                    };

                    testable.GetMock <IJsonProvider>()
                    .Setup(x => x.SerializeOptions(options))
                    .Returns(@"{""some"":""json""}");

                    testable.Instance.Lint("some source", options);

                    testable.Verify <IJsonProvider>(x => x.DeserializeData(@"some source_{""some"":""json""}"));
                }
            }
예제 #10
0
        public void LoadOptions(Options options)
        {
            outputAsError.IsChecked   = options.ErrorCategory == ErrorCategory.Error;
            outputAsWarning.IsChecked = options.ErrorCategory == ErrorCategory.Warning;
            outputAsMessage.IsChecked = options.ErrorCategory == ErrorCategory.Message;
            outputAsTask.IsChecked    = options.ErrorCategory == ErrorCategory.Task;

            todoAsError.IsChecked   = options.TODOCategory == ErrorCategory.Error;
            todoAsWarning.IsChecked = options.TODOCategory == ErrorCategory.Warning;
            todoAsMessage.IsChecked = options.TODOCategory == ErrorCategory.Message;
            todoAsTask.IsChecked    = options.TODOCategory == ErrorCategory.Task;
            findTODOs.IsChecked     = options.TODOEnabled;

            runOnSave.IsChecked = options.RunOnSave;

            runOnBuild.IsChecked         = options.RunOnBuild;
            cancelBuildOnError.IsChecked = options.CancelBuildOnError;

            includeJS.IsChecked   = (options.BuildFileTypes & IncludeFileType.JS) == IncludeFileType.JS;
            includeCSS.IsChecked  = (options.BuildFileTypes & IncludeFileType.CSS) == IncludeFileType.CSS;
            includeHTML.IsChecked = (options.BuildFileTypes & IncludeFileType.HTML) == IncludeFileType.HTML;
            onSaveJs.IsChecked    = (options.SaveFileTypes & IncludeFileType.JS) == IncludeFileType.JS;
            onSaveCss.IsChecked   = (options.SaveFileTypes & IncludeFileType.CSS) == IncludeFileType.CSS;
            onSaveHtml.IsChecked  = (options.SaveFileTypes & IncludeFileType.HTML) == IncludeFileType.HTML;

            fakeAtCharset.IsChecked = options.FakeCSSCharset;

            ignoreErrorStart.Text = options.IgnoreErrorStart;
            ignoreErrorEnd.Text   = options.IgnoreErrorEnd;
            IgnoreErrorLine.Text  = options.IgnoreErrorLine;

            JSLintOptions jslint = options.JSLintOptions;

            _optionsVM.LoadLinterSettings(jslint.SelectedLinter, jslint.BoolOptions2);

            warnOnUnused.IsChecked = jslint.ErrorOnUnused;
            indentSize.Text        = jslint.IndentSize.ToString();
            maxlen.Text            = jslint.MaxLength.ToString();

            if (jslint.PreDefined != null && jslint.PreDefined.Count > 0)
            {
                predefined.Text = string.Join(", ", jslint.PreDefined);
            }
        }
예제 #11
0
            public void Spec01()
            {
                var target = new JSLintOptions()
                {
                    MaximumErrors = 22,
                    AssumeBrowser = false,
                    TolerateUnusedParameters = true
                };

                var merge = new JSLintOptions()
                {
                    MaximumErrors = 33,
                    AssumeBrowser = true,
                    TolerateDebuggerStatements = false
                };

                target.Merge(merge);

                I.Expect(target.MaximumErrors).ToBe(33);
                I.Expect(target.AssumeBrowser).ToBeTrue();
                I.Expect(target.TolerateUnusedParameters).ToBeTrue();
                I.Expect(target.TolerateDebuggerStatements).ToBeFalse();
                I.Expect(target.TolerateStupidPractices).ToBeNull();
            }
예제 #12
0
            public void Spec01()
            {
                var target = new JSLintOptions()
                {
                    MaximumErrors            = 22,
                    AssumeBrowser            = false,
                    TolerateBitwiseOperators = true
                };

                var merge = new JSLintOptions()
                {
                    MaximumErrors = 33,
                    AssumeBrowser = true,
                    TolerateEval  = false
                };

                target.Merge(merge);

                I.Expect(target.MaximumErrors).ToBe(33);
                I.Expect(target.AssumeBrowser).ToBeTrue();
                I.Expect(target.TolerateBitwiseOperators).ToBeTrue();
                I.Expect(target.TolerateEval).ToBeFalse();
                I.Expect(target.TolerateMessyWhitespace).ToBeNull();
            }
예제 #13
0
            public void Spec01()
            {
                var target = new JSLintOptions()
                {
                    MaximumErrors            = 22,
                    AssumeBrowser            = false,
                    TolerateUnusedParameters = true
                };

                var merge = new JSLintOptions()
                {
                    MaximumErrors = 33,
                    AssumeBrowser = true,
                    TolerateDebuggerStatements = false
                };

                target.Merge(merge);

                I.Expect(target.MaximumErrors).ToBe(33);
                I.Expect(target.AssumeBrowser).ToBeTrue();
                I.Expect(target.TolerateUnusedParameters).ToBeTrue();
                I.Expect(target.TolerateDebuggerStatements).ToBeFalse();
                I.Expect(target.TolerateStupidPractices).ToBeNull();
            }
예제 #14
0
 public LinterViewModel(LinterModel linterModel, JSLintOptions jslintOptions)
 {
     _linter          = linterModel;
     _jslintOptions   = jslintOptions;
     _booleanSettings = new ObservableCollection <LintBooleanSettingViewModel>(GetBooleanSettings(_linter, _jslintOptions));
 }
예제 #15
0
 public LintBooleanSettingViewModel(LintBooleanSettingModel model, JSLintOptions jslintOptions)
 {
     _model         = model;
     _jslintOptions = jslintOptions;
 }
예제 #16
0
 public IEnumerable <LintBooleanSettingViewModel> GetBooleanSettings(LinterModel linter, JSLintOptions jslintoptions)
 {
     return(LintBooleanSettingModel.AllOptions
            .Where(a => ((a.LintersAppliesTo & linter.Type) > 0))
            .Select(a => new LintBooleanSettingViewModel(a, jslintoptions)));
 }
예제 #17
0
 /// <summary>
 /// Serializes the options.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <returns>
 /// A serialized string.
 /// </returns>
 public string SerializeOptions(JSLintOptions value)
 {
     return JsonConvert.SerializeObject(value, serializerSettings);
 }
예제 #18
0
 /// <summary>
 /// Serializes the options.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <returns>
 /// A serialized JSON string.
 /// </returns>
 public string SerializeOptions(JSLintOptions value)
 {
     return(JsonConvert.SerializeObject(value, SerializerSettings));
 }
예제 #19
0
        private static void MigrateOptions(JSLintOptions jsLintOptions, IDictionary<string, object> options)
        {
            if (options.ContainsKey("evil"))
            {
                var evil = options["evil"] as bool?;

                if (evil.HasValue)
                {
                    jsLintOptions.TolerateEval = evil;
                }
            }
        }
예제 #20
0
 public List <JSLintError> Lint(string javascript, JSLintOptions configuration, bool isJavaScript)
 {
     return(this.linter.Lint(javascript, configuration, isJavaScript));
 }