[pve-devel] [PATCH jslint] improve jslint

Thomas Lamprecht t.lamprecht at proxmox.com
Mon Jan 8 10:31:21 CET 2018


IMHO, it would have been good to split this in three patches,
for the sake of a nice git history:
* add Proxmox to predefined global variables
* do not abort on first error but check all files
* print errors at the end

But, the end result looks OK, besides whitespace/indentation problems
- albeit, most of them where already present before. so:

Reviewed-by: Thomas Lamprecht <t.lamprecht at proxmox.com>

side note, this uses still dpkg-deb a change to buildpackage would
be nice. But, really unimportant for now - just noticed it.

On 1/4/18 12:59 PM, Dominik Csapak wrote:
> include 'Proxmox' into global variables (from widget toolkit)
> and check all files and show the errors together at the end
> 
> Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
> ---
>  rhino.js | 31 +++++++++++++++++++++----------
>  1 file changed, 21 insertions(+), 10 deletions(-)
> 
> diff --git a/rhino.js b/rhino.js
> index d1892dc..1996bda 100644
> --- a/rhino.js
> +++ b/rhino.js
> @@ -1,12 +1,14 @@
>  (function (a) {
> -    var e, i, input, filename, defaults;
> +    var e, i, j, input, filename, defaults;
> +    var error = 0;
> +    var errorstring = '';
>      if (!a[0]) {
>          print("Usage: jslint.js file.js ...");
>          quit(1);
>      }
>  
>      defaults = {
> -	predef: ['Ext', 'PVE', 'PMG', 'PVE_vnc_console_event', 'FormData', 'gettext'],
> +	predef: ['Ext', 'PVE', 'PMG', 'PVE_vnc_console_event', 'FormData', 'gettext', 'Proxmox'],
>  	devel:      true,
>  	'continue': true,   /// Allow continue statement
>  	bitwise:    true,   //  Allow bitwise operators
> @@ -26,27 +28,36 @@
>      
>      for (i = 0; i < a.length; ++i) {
>      	filename = a[i];
> +	input = undefined;
>  	input = readFile( filename );
>  	if (!input) {
>              print("jslint: Couldn't open file '" + filename + "'.");
> -            quit(1);
> +            if (error < 1) {
> +		error = 1;
> +		continue;
> +	    }
>  	}
>  
>  	if (!JSLINT(input, defaults)) {
> -            for (i = 0; i < JSLINT.errors.length; i += 1) {
> -		e = JSLINT.errors[i];
> +            for (j = 0; j < JSLINT.errors.length; j += 1) {
> +		e = JSLINT.errors[j];
>  		if (e) {
> -                    print('[' + filename + '] Lint at line ' + e.line + ' character ' +
> +                    errorstring += ('[' + filename + '] Lint at line ' + e.line + ' character ' +
>                            e.character + ': ' + e.reason);
> -                    print((e.evidence || '').
> +		    errorstring += "\n";
> +                    errorstring += ((e.evidence || '').
>                            replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"));
> -                    print('');
> +		    errorstring += "\n\n";
>  		}
>              }
> -            quit(2);
> +            if (error < 2) {
> +		error = 2;
> +		continue;
> +	    }
>  	} else {
>              print("jslint: " + filename + " OK");
>  	}
>      }
> -    quit();
> +    print(errorstring);
> +    quit(error);
>  }(arguments));
> 





More information about the pve-devel mailing list