Comments (10)
For those looking for the .jshintrc
object key:
"-W086": true, //allow fall-through
from jshint.
Since more often than not case fall through is unintentional, I didn't add a separate option to just ignore the message. Instead, I re-used your approach with an explicit comment saying that fall through is intentional.
switch(foo) { case 1: dosmth(); /* falls through */ case 2: dosmth(); }
Related commit: 4a72da1.
from jshint.
Also, from #11 — JSHint probably should have an option to allow fall through all the way to the default
.
from jshint.
Awesome, thanks!
from jshint.
IIRC, Crockford makes a specific mention in his book why he dislikes case fall-through. The story is both amusing and somewhat delf-deprecating.
from jshint.
Sorry to comment on this, but the warning is still triggered for case
s with a throw at the end of a block. You can disable the warning with a /* falls through */
annotation, but the annotation is "disturbed" (in the sense that the warning is then triggered after all) by anything other than whitespace between the previous case, the annotation and the next case so I can't even comment on why the comment's there.
from jshint.
The /* falls through */
comment instead of break;
is an undocumented feature. Please add it to the docs.
Additional comments can be added on a line before /* falls through */
.
from jshint.
Seconded. Please add /*falls through*/
to the docs.
from jshint.
Also, please add supprt for:
case 'none':
default:
While technically the 'none'
case is unnecessary, it does add to the readability of the code.
from jshint.
+1 for adding info about this to the docs.
As a point of interest, I recently found a situation where "falls through" cases make sense. I used this for performing migrations of versioned data read from localStorage. Ex:
function migrate( version, data ) {
switch( version ) {
case 1 :
data.new1 = data.old; // convert data from version 1 to version 2
delete data.old;
case 2 :
data.new2 = data.new1; // convert data from version 2 to version 3
delete data.new1;
}
return data; // return data in version 3 format
}
As the data format evolves, the code can be maintained by adding cases for migrating older versions, and all migrations to bring a particular version up to the latest are applied.
from jshint.
Related Issues (20)
- Getting errors while adding as dev-dependancy HOT 1
- JSHint doesn't recognize bitwise operators like & | >> etc... HOT 2
- is there any kind of way to get the console log outputs using this tool? HOT 1
- can i customize the error messages generated by JSHINT? is there any locale files i can override? HOT 1
- Not work in VS Code's Terminal HOT 1
- 'fetch' is not defined. (W117) - Although it is a base feature of Node 18 (although experimental) HOT 3
- Error: JSHINT is not defined HOT 2
- False error on static property HOT 1
- W080 incorrect message for initializing const with undefined HOT 2
- jshint doesn't expect regexp literals in one-liners following if/while/for conditions, and also else HOT 3
- `jshint` breaks on experimental feature `import * as file_json from 'file.json' assert { 'type': 'json' };` HOT 11
- JShint in VScode HOT 1
- If variable is assigned but never used it should cause warning HOT 1
- esversion beyond 11 HOT 2
- Generate error on specific object properties HOT 1
- jshint 2.13.6 is not warning me about mixing tabs and spaces HOT 1
- No warnings about undefined variable when doing typeof yyy
- VSCode HOT 1
- Jshint doest trigger hint when access non exist property of an object HOT 1
- "Invalid regular expression" when /s flag is used on long RegExps
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jshint.