473,405 Members | 2,415 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Javascript Lint error.

i have to make a lint free java script file.
I'm almost done with all the changes. only one line is killing me.

[HTML]var newlnk = 'javascript:promptConfirmBox(\'' + ss[1] + '\', ' + newWindow + ')';[/HTML]

I'm getting a Script URL lint error in this line. Can some one tell me how to fix this or how to make the compiler ignore this.
Oct 21 '08 #1
13 1867
I'm actually using this var to set attribute href to the <a> tag.
Oct 21 '08 #2
pronerd
392 Expert 256MB
A semi colon in the string would not be a bad idea.



[HTML]var newlnk = 'javascript:promptConfirmBox(\'' + ss[1] + '\', ' + newWindow + ');';[/HTML]
Oct 21 '08 #3
rnd me
427 Expert 256MB
if you want to save some time, run your raw code though my compressor/formater before using lint.

it auto fixes things like semi-colons.

i have had files that had hundereds of lint errors, too many to continue.
after i ran it though my for matter, it was down to 8 errors, with just two click!


the app itself works in firefox only, but handles code for everyone.
the app is located here
Oct 21 '08 #4
Putting a comma at the end does n't fix the error.
Please let me know if there is any other way to Fix this.
Oct 22 '08 #5
rnd me
427 Expert 256MB
lint is not perfect. frankly, it offers advice that could be considered opinion at best, dogma at worst. doug's treatment of eval and paren-less constructors comes to mind.

this is a perfect example. all the "error" means is that you are using javascript in as an A tag's href. this works fine in all browsers, but lint does not like it. There is nothing "wrong" with your code.

That said, i am not a huge fan of this pattern either. i would use a <span> instead of the <A> and move the href code into an onclick attrib. This cleans up the status bar and allows for more semantic documents.

if the script still works, i wouldn't lose any sleep over it. javascript code is not the structured markup of HTML. this makes it very difficult to "validate" javascript.
and since there is no standards on how to write javascript, a validator will reflect the whims of it's creator.
Oct 22 '08 #6
thanks for the reply.

i have no other option other than to go for <a>.
My java script actually takes all the <a> tags and replaces its href with a prompt.

This is a prompt before moving to some other url.

Is there a way that i can suppress this error from the lint compiler. just make it ignore this error?
Oct 22 '08 #7
acoder
16,027 Expert Mod 8TB
Remove the "javascript:" protocol and set the onclick instead of the href attribute. The href should be set to a valid URL. To avoid going to that page too, add a return false at the end of the function.
Oct 22 '08 #8
i found a interesting way to do that

var newlnk = /'javascript:promptConfirmBox/;
arr[i].setAttribute('href', newlnk.toString().substring(2, newlnk.toString().length - 1) + '(\'' + ss[1] + '\', ' + newWindow + ');');
Oct 22 '08 #9
acoder
16,027 Expert Mod 8TB
Interesting and very ugly too at that! What a hack just to get around a lint warning/error! As I said, remove the "javascript:" and set the onclick instead.
Oct 22 '08 #10
rnd me
427 Expert 256MB
grrr. i am starting to like lint even less.

when users are crapifying their code to jump though a lint hoop, it defeats the whole purpose.
in mu opinoion, this is worse than validation (something else i hate when people fret over).
it probably wont be long before we see button badges that say "Lint Me" right next to the also useless "Validate Me" button. Sometimes you need to validate, like when using XSLT or another processing method. but most of the time, validation only really solves "fake problems".

i've actually met someone who was literally embarrassed about his page not validating, so get this: he took it down. this was a departmental webpage and he put several users out for an afternoon because of a missing img tag alt attrib. Javascript could care less about that alt attrib...


I don't blame the OP, i blame doug for not qualifying lint's usage better.
Lint doesn't hurt my feelings, it offends my wisdom.


wait a second, what does this have to do with the question?
-hmm nothing i guess, but since i already typed my venting, i'll just click submit.
Oct 22 '08 #11
acoder
16,027 Expert Mod 8TB
Sometimes you need to validate, like when using XSLT or another processing method. but most of the time, validation only really solves "fake problems".
Validation is important, not because it solves problems, but it provides a base to begin to solve problems. If your code's not valid in the first place, how can you expect browsers to display the markup properly and consistently? A missing alt attribute would be obvious from the validation errors. I don't for one minute suggest that a web page should be taken down because it doesn't validate, but it should be validated eventually and pages that are being written from scratch should definitely be validated and tested before being published.
Oct 23 '08 #12
rnd me
427 Expert 256MB
yup. that's what they say alright...

google uses quirks mode and it's not because they don't know what they are doing...

this is where programmers and page authors should agree to disagree.
Oct 23 '08 #13
acoder
16,027 Expert Mod 8TB
Why can't someone be both? ;)

I'm not going to defend or criticise Google. Just one thing I will say is that most of the validation errors can be resolved in matter of minutes. However, if you've got a page which is not looking right and there's validation errors, you've got no room for complaints.
Oct 24 '08 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Douglas Crockford | last post by:
JSLINT now includes a list of member names in its report, along with the number of occurences of each member name. This is intended to make it easier to find misspellings. JSLINT takes a...
15
by: Pat | last post by:
I've been searching for a good multi-module lint checker for Python and I haven't found one yet. Pylint does a decent job at checking for errors only within a single module. Here's one of my...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.