Ejemplo n.º 1
0
		public void TestMultipleDifferentOptions()
		{
            JsLintConfiguration config = new JsLintConfiguration();
			SharpLinter lint = new SharpLinter(config);
            
            config.SetOption("eqeqeq",true);
            config.SetOption("plusplus",true);
            
            JsLintResult result = lint.Lint(
							@"function annon() { var i, number, x; for (i = 0; i == 5; i++) { number += ++i; } }"							
                            );

			Assert.AreEqual(3, result.Errors.Count);

            config = new JsLintConfiguration();
            config.SetOption("unused", false);

            // should fail on ++ since "plusplus=true" -- note that we are testing with JSHINT so the
            // behavior is opposite of JSLINT for this options

			JsLintResult result2 = lint.Lint(
							@"function annon() { var i, number; for (i = 0; i === 5; i++) { number += i; } }");

			Assert.AreEqual(1, result2.Errors.Count);
		}
Ejemplo n.º 2
0
        public void ErrorLimit()
        {
            var config = TestResources.DefaultConfig;
            config.SetOption("maxerr", 10);

            SharpLinter lint = new SharpLinter(config);

            string file = TestResources.LoadAppRootedFile("resources\\errors.js") ;
            var result = lint.Lint(file);

            Assert.AreEqual(10, result.Errors.Count);
            Assert.AreEqual(true, result.Limited);

            config.SetOption("maxerr", 10000);
            result = lint.Lint(file);

            Assert.IsTrue(result.Errors.Count>100);
            Assert.AreEqual(false, result.Limited);
        }
Ejemplo n.º 3
0
        public void TestMultipleCalls()
        {
            var config = DefaultConfig;

            SharpLinter lint = new SharpLinter(config);

            JsLintResult result = lint.Lint(
                            @"var i, y; for (i = 0; i < 5; i++) console.Print(message + ' (' + i + ')'); number += i;");

            // original test was 4 errors - jshint defaults?
            Assert.AreEqual(4, result.Errors.Count);

            JsLintResult result2 = lint.Lint(
                            @"function annon() { var i, number; for (i = 0; i === 5; i++) { number += i; } }");

            Assert.AreEqual(1, result2.Errors.Count);

            JsLintResult result3 = lint.Lint(
                            @"function annon() { var i, number, x; for (i = 0; i == 5; i++) { number += i; } }");

            Assert.AreEqual(2, result3.Errors.Count);
        }
Ejemplo n.º 4
0
    public List<JsLintData> LintFile(string file, SharpLinter lint)
    {
        List<JsLintData> fileErrors = new List<JsLintData>();
        string javascript = File.ReadAllText(file);
        JsLintResult result = lint.Lint(javascript);
        bool hasErrors = result.Errors.Count > 0;

        if (hasErrors)
        {
            foreach (JsLintData error in result.Errors)
            {
                error.FilePath = file;
                fileErrors.Add(error);
            }
        }

        SharpCompressor compressor = new SharpCompressor();

        // We always check for YUI errors when there were no lint errors and
        // Otherwise it might not compress.
        if (!hasErrors)
        {
            compressor.Clear();
            compressor.AllowEval = true;
            //compressor.KeepHeader = Configuration.MinimizeKeepHeader;
            //compressor.CompressorType = Configuration.CompressorType;

            hasErrors = !compressor.YUITest(javascript);

            if (hasErrors)
            {
                foreach (var error in compressor.Errors)
                {
                    fileErrors.Add(error);
                }
            }
        }

        fileErrors.Sort(LintDataComparer);
        return fileErrors;
    }