Beispiel #1
0
        public static result[] JSHINT(string source, options options = null)
        {
            var data = new Dictionary<string, object> {
                {"source", source},
                {"options", options},
            };
            var optionCode = "";
            if (options != null) {
                foreach (var prop in typeof(options).GetProperties()) {
                    optionCode += "\r\n\t'" + prop.Name + "': options0['" + prop.Name + "'],";
                }
            }
            var ie = new JSHint(@"
                    var options0 = external.Get('options'), options1 = {
                        " + optionCode.TrimEnd(',') + @"
                    }, result = JSHINT(external.Get('source'), options1),
                       errors = JSHINT.errors;
                    external.Set('result', result);
                    external.Set('errors', errors.length);
                    if (!result) {
                        for (var i = 0; i < errors.length; i++) {
                            external.AddResult(errors[i].line || 0, errors[i].character || 0, errors[i].reason || '', errors[i].evidence || '', errors[i].raw || '');
                        }
                    }
                ", data);
            ie.Execute();
            var result = ie.Get("result") as bool?;

            if (result ?? ie._Results.Count == 0) return null;
            return ie._Results.ToArray();
        }
Beispiel #2
0
        public static result[] JSHINT(string source, options options = null)
        {
            var data = new Dictionary <string, object> {
                { "source", source },
                { "options", options },
            };
            var optionCode = "";

            if (options != null)
            {
                foreach (var prop in typeof(options).GetProperties())
                {
                    optionCode += "\r\n\t'" + prop.Name + "': options0['" + prop.Name + "'],";
                }
            }
            var ie = new JSHint(@"
                    var options0 = external.Get('options'), options1 = {
                        " + optionCode.TrimEnd(',') + @"
                    }, result = JSHINT(external.Get('source'), options1), 
                       errors = JSHINT.errors;
                    external.Set('result', result);
                    external.Set('errors', errors.length);
                    if (!result) {
                        for (var i = 0; i < errors.length; i++) {
                            external.AddResult(errors[i].line || 0, errors[i].character || 0, errors[i].reason || '', errors[i].evidence || '', errors[i].raw || '');
                        }
                    }
                ", data);

            ie.Execute();
            var result = ie.Get("result") as bool?;

            if (result ?? ie._Results.Count == 0)
            {
                return(null);
            }
            return(ie._Results.ToArray());
        }