sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    JSLint - what's important, what's not?

    Scheduled Pinned Locked Moved Developers' Forum
    9 Posts 3 Posters 1.9k Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • chrisglasierC Offline
      chrisglasier
      last edited by

      Here is sampling from a JSLinting of one "core" js file, with some requests for help ... (Btw it runs OK on my machine and is IE only)

      ` Problem at line 15 character 5: 'window' is not defined.

      window.location = "skp:" + callback + "@" + params.join(';');`

      This seems very odd to me; surely it cannot be bad!

      ` Problem at line 29 character 9: 'nameDown' is not defined.

      nameDown(params);`

      nameDown is a function in another file; any problem with that? There will be other similar calls.

      ` Problem at line 103 character 65: Be careful when making functions within a loop. Consider putting the function in a closure.

      o.onmousedown = function() { coreDown(this , c , dv ); };`

      This one is more difficult. Here is the relevant part of the function:

      // o is a div
      
      o.className = p + cn;
      o.onmousedown = function() { coreDown(this , c , dv ); };
      s = o.style;
      s.width = "100%";
      s.height = ch;
      

      Is the recommendation relevant, possible?

      Problem at line 141 character 5: Bad line breaking

      ... ,interval); in this code

      function coreAnimate(obj, elm, begin, end, duration, fps) {
      	var change,interval,steps,i;
      	change      = end-begin;
      	interval    = Math.ceil(1000/fps);
      	steps		= Math.ceil(duration/interval);
      	if(obj.coreStop){
      		window.clearInterval(obj.coreStop);
      	}
      	i = 0;
          obj.coreStop = window.setInterval(
      	function() { 
      		obj.last = linearTween(i, begin, change, steps);
      		obj.style[elm]  = obj.last + 'px'; 
      		i+=1;
      		if (i > steps){
      			window.clearInterval(obj.coreStop);
      		}
      	} 
      	,interval);
      }
      
      

      It certainly does not look good but is it bad?

      ` Problem at line 148 character 14: 'ActiveXObject' is not defined.

      fs = new ActiveXObject("Scripting.FileSystemObject");`

      I guess this is the same as window as noted in the last bit of the report:

      Implied global: window 7,15,130,133,139, nameDown 29, Refresh 63, ActiveXObject 148,162,171

      Any help and suggestions gratefully received.

      Chris

      With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

      1 Reply Last reply Reply Quote 0
      • tbdT Offline
        tbd
        last edited by

        @unknownuser said:

        Problem at line 15 character 5: 'window' is not defined.

        window is defined only in browser environment and it is done by the browser, so JSLint doesn't know that.

        use option Assume a browser

        @unknownuser said:

        Problem at line 29 character 9: 'nameDown' is not defined.

        nameDown is a function in another file; any problem with that? There will be other similar calls.

        you can try to combine all js files and run it through jslint after.

        @unknownuser said:

        Problem at line 103 character 65: Be careful when making functions within a loop. Consider putting the function in a closure.

        it is a warning as functions/variables are not what you expect to be when they are executed.

        @unknownuser said:

        Problem at line 141 character 5: Bad line breaking
        It certainly does not look good but is it bad?

        kinda. if you add something before ,interval it screw things up

        @unknownuser said:

        Problem at line 148 character 14: 'ActiveXObject' is not defined.

        see #1

        @unknownuser said:

        Implied global: window 7,15,130,133,139, nameDown 29, Refresh 63, ActiveXObject 148,162,171

        try with assume as browser activated and see what is left.

        JSLint comes with "Warning: JSLint will hurt your feelings" πŸ’š

        SketchUp Ruby Consultant | Podium 1.x developer
        http://plugins.ro

        1 Reply Last reply Reply Quote 0
        • chrisglasierC Offline
          chrisglasier
          last edited by

          @unknownuser said:

          try with assume as browser activated and see what is left.

          JSLint comes with "Warning: JSLint will hurt your feelings"

          Thanks for that. Yes I did tick assume as browser but it says in the instructions

          @unknownuser said:

          The browser option does not include the aliases of the global object, window and self.

          So I thought I would ask the brains. As for feelings ... I think I lost them at the turn of the century.

          Chris

          With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

          1 Reply Last reply Reply Quote 0
          • M Offline
            MartinRinehart
            last edited by

            @chrisglasier said:

            window.location = "skp:" + callback + "@" + params.join(';');

            In a browser, window is the global object so window.location difers from location only in the amount of typing you do.

            More exactly, window is one of the global objects. In a frameset, every frame has its own window. If you launch two WebDialogs, each has its own window (or, windows).

            For those who do not know, JSLint is Doug Crockford's JavaScript checker, analogous to the W3C HTML validators (although Crockford's work is cleaner). It is extremely picky and I have never found it wrong.

            Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

            1 Reply Last reply Reply Quote 0
            • chrisglasierC Offline
              chrisglasier
              last edited by

              Thank you Martin, I understand ... but when I untyped all window prefixed statements I still get one notification:

              @unknownuser said:

              Problem at line 15 character 5: Read only.

              location = "skp:" + callback + "@" + params.join(';');

              and in another file, this:

              @unknownuser said:

              Error:
              Problem at line 6 character 17: 'window' is not defined.

              f.left = window.screenLeft;

              Problem at line 7 character 16: 'screenTop' is not defined.

              f.top = screenTop;

              which I find confusing.

              With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

              1 Reply Last reply Reply Quote 0
              • tbdT Offline
                tbd
                last edited by

                without having the complete file to test it on jslint cant help much.

                @unknownuser said:

                Problem at line 15 character 5: Read only.

                maybe it depends on another variable defined before

                @unknownuser said:

                Problem at line 6 character 17: 'window' is not defined.

                f.left = window.screenLeft;

                window is still used πŸ˜‰

                @unknownuser said:

                Problem at line 7 character 16: 'screenTop' is not defined.

                f.top = screenTop;

                as you removed window screenTop is undefined now as well

                do you want to make the .js warning/error free ? how many left ?

                SketchUp Ruby Consultant | Podium 1.x developer
                http://plugins.ro

                1 Reply Last reply Reply Quote 0
                • chrisglasierC Offline
                  chrisglasier
                  last edited by

                  @ TBD

                  I am jslinting the other files and will combine and retest them as you suggested. Error free would be optimal but understood non-harmful errors like window would be acceptable second best.

                  Thanks for your reply - will post any interesting (to me!) outcome.

                  Chris

                  With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

                  1 Reply Last reply Reply Quote 0
                  • chrisglasierC Offline
                    chrisglasier
                    last edited by

                    Another thing is that I removed all eval()s but I am very unsure why sourcing js files (not JSON) from remote locations over the Net seems not to be mentioned as similarly evil.

                    With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

                    1 Reply Last reply Reply Quote 0
                    • chrisglasierC Offline
                      chrisglasier
                      last edited by

                      @chrisglasier said:

                      @ TBD ... will post any interesting (to me!) outcome.

                      @unknownuser said:

                      Error:
                      Problem at line 116 character 5: Bad line breaking before ','.

                      }

                      Problem at line 161 character 65: Be careful when making functions within a loop. Consider putting the function in a closure.

                      o.onmousedown = function() { coreDown(this , c , dv ); };

                      Problem at line 297 character 18: 'noldDown' was used before it was defined.

                      function noldDown(params){ //params = cell , sliderName , sliderNo , cnt...

                      Problem at line 389 character 18: 'moldDown' was used before it was defined.

                      function moldDown(params){

                      Implied global: ActiveXObject 16,34, window 43,44

                      Well not perfect but I think acceptable (please correct me if I am wrong).

                      With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

                      1 Reply Last reply Reply Quote 0
                      • 1 / 1
                      • First post
                        Last post
                      Buy SketchPlus
                      Buy SUbD
                      Buy WrapR
                      Buy eBook
                      Buy Modelur
                      Buy Vertex Tools
                      Buy SketchCuisine
                      Buy FormFonts

                      Advertisement