Who am I to suggest typed programming to you? See, with JS we are in a different domain: freed from types, we can easily express things that are hard or impossible to give a proper type which can certainly be an advantage. But without types there is little to keep our programs in check, so we are forced to introduce tests and to a lesser extend code styles.
I recommend you look at LISP e. ClojureScript for inspiration and invest in testing your codes. Read The way of the substack to get an idea. Well, Instead of doing manual lint settings we can include all the lint settings at the top of our JS file itself e. JSCS is a code style linter for programmatically enforcing your style guide. You can configure JSCS for your project in detail using over validation rules, including presets from popular style guides like jQuery, Airbnb, Google, and more.
It comes with multiple presets that you can choose from by simply specifying the preset in the. How are we doing? Please help us improve Stack Overflow. Take our short survey. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow.
Learn more. Asked 10 years, 3 months ago. Active 3 months ago. Viewed k times. Improve this question. Vikrant 5, 16 16 gold badges 47 47 silver badges 68 68 bronze badges. How about ESLint? Related: scottlogic. Not a JS developer. But I found JSHint very useful during our code review process. I recommend it. Add a comment. Active Oldest Votes. TL;DR Use JSLint if you're looking for a very high standard for yourself or your team, but bear in mind that it's not necessarily the standard, only a standard, some of which comes to us dogmatically from Doug Crockford.
Improve this answer. Aryan Beezadhur 2, 1 1 gold badge 13 13 silver badges 36 36 bronze badges. B Robster B Robster I must admit, I have been disappointed with the unprofessional quality of the advice that I have recently seen proliferated with respect to coding styles for JS and CSS too, incidentally.
It's as if the infatuation with a specific language has overridden the needs of non-expert practitioners i. This is such a shame considering they need good advice, and will blindly follow and perpetuate whatever is touted as best practice, without knowing any better. Often it is incompatible with other standards adopted by more established user-communities for other languages. The scope of i is the function. The syntax looks like it is creating a block scope, but it is not and that leads the less experienced JavaScript programmers and people writing in multiple languages to misunderstand the scope of a variable and that can result in subtle bugs.
Many of us myself included may not like how it looks to put all the declarations up top, but it is a good reminder that JavaScript does not have block scope. MarkEvans It's self contained from the view that if you moved just the loop to another function, i will not accidentally become global. The fact that i is function scoped not block scoped is not a good enough reason to declare variables at the top, variables should always be declared as close to where they are used as possible programmers.
MarkEvans I think you're focussing too much on language implementation details. Programming standards should be for humans, not compilers. Reliance on a static code analysis tool to catch common pitfalls is no replacement for adopting good habits that avoid them in the first place. I can't fathom a reason why an iterator variable for a simple loop should be declared any distance away from the loop that requires it.
Many coding standards for other languages say declare variables as close as to where they are used as possible, for readability. I haven't seen a good reason not to do this in JS. Using an iterator variable outside of a loop is the thing a linter ought to check for. The "Strings must use singlequote" and "Strings must use doublequote" errors are thrown when JSHint or ESLint encounters string literal delimited by double quote characters w….
In JSLint the warning given is "Only p…. Also known as Only properties should be deleted Variables should not be deleted W Also known as Weird relation Comparing to itself is potentially pointless. The "Wrap an immediate function invocation in parentheses" error is thrown when JSLint, JSHint and ESLint encounter an immediately invoked function expression that is not wrapped in pa….
Also known as Wrap an immediate function invocation in parentheses W Also known as The array literal notation [] is preferrable Use the array literal notation [] W Also known as Bad assignment Invalid left-hand side in assignment E Also known as Confusing minuses W In JSLint the warning given is "…. Also known as All 'debugger' statements should be removed Forgotten 'debugger' statement? Unexpected 'debugger' Unexpected 'debugger' statement W In JSLint the warning given is the gene….
This is one of many generic error messages uses by JSLint in a number of situations. Most of these cases are covered in detail by dedicated articles. Following is a list of situations that will…. It was introduced in the original version of JSHint and has remained in a way in all three tools from some point since.
In JSLint the wa…. Also known as Bad escapement of EOL. Use option multistr if needed Multiline support is limited to browsers supporting ES5 only W Also known as Do not assign to the exception parameter W The "The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype" error is thrown when JSLint encounters a for-in statement in which the….
Also known as The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype W The "Function statements should not be placed in blocks" error and the alternative "Function declarations should not be placed in blocks" error is thrown when JSLint or JSH….
Also known as Function statements should not be placed in blocks Function declarations should not be placed in blocks W In the followin…. Also known as Use the function form of 'use strict' W The "Option 'validthis' can't be used in a global scope" error is thrown when JSHint encounters the validthis option in a global scope. Here's a silly example in which…. Also known as Option 'validthis' can't be used in a global scope E Also known as Implied eval is evil.
Pass a function instead of a string Implied eval. Consider passing a function instead of a string W In the fol…. In JSLint versions dated before May t…. In JSLint the warning given is the generic…. Also known as Missing ' ' invoking a constructor W Also known as Missing 'use strict' statement E The "Move the invocation into the parens that contain the function" error is thrown when JSLint and ESLint encounter an immediately invoked function expression in which the invoking pa….
In JSLint the warning given is "'…. The "Spaces are hard to count. The "Did you mean to return a conditional instead of an assignment?
Also known as Did you mean to return a conditional instead of an assignment? Return statement should not contain assignment W The "Stopping. JSHint will only raise this…. Also known as Stopping. The regular expression used by JSLint to determine whether…. Also known as Unclosed comment E Also known as Unclosed regular expression E If you're looking for a very high standard for yourself or team, JSLint. But its not necessarily THE standard, just A standard, some of which comes to us dogmatically from a javascript god named Doug Crockford.
If you want to be a bit more flexible, or have some old pros on your team that don't buy into JSLint's opinions, or are going back and forth between JS and other C-family languages on a regular basis, try JSHint. So I guess the idea is that it's "community-driven" rather than Crockford-driven. In practicality, JSHint is generally a bit more lenient or at least configurable or agnostic on a few stylistic and minor syntactical "opinions" that JSLint is a stickler on.
As an example, if you think both the A and B below are fine, or if you want to write code with one or more of the aspects of A that aren't available in B, JSHint is for you. If you think B is the only correct option I'm sure there are other differences, but this highlights a few. A few of the whitespace things that JSLint enforces, I find to be not necessarily bad, but out of sync with some pretty standard whitespace conventions for other languages in the family C, Java, Python, etc Since I'm writing in various of these languages throughout the day, and working with team members who don't like Lint-style whitespace in our code, I find JSHint to be a good balance.
It catches stuff that's a legitimate bug or really bad form, but doesn't bark at me like JSLint does sometimes, in ways I can't disable for the stylistic opinions or syntactic nitpicks that I don't care for. A lot of good libraries aren't Lint'able, which to me demonstrates that there's some truth to the idea that some of JSLint is simply just about pushing 1 version of "good code" which is, indeed, good code.
0コメント