Giter Site home page Giter Site logo

Comments (10)

jpillora avatar jpillora commented on July 28, 2024 3

For those looking for the .jshintrc object key:

"-W086": true, //allow fall-through

from jshint.

valueof avatar valueof commented on July 28, 2024 2

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.

valueof avatar valueof commented on July 28, 2024

Also, from #11 — JSHint probably should have an option to allow fall through all the way to the default.

from jshint.

nzakas avatar nzakas commented on July 28, 2024

Awesome, thanks!

from jshint.

cowboy avatar cowboy commented on July 28, 2024

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.

dslmeinte avatar dslmeinte commented on July 28, 2024

Sorry to comment on this, but the warning is still triggered for cases 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.

Daghall avatar Daghall commented on July 28, 2024

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.

CrabDude avatar CrabDude commented on July 28, 2024

Seconded. Please add /*falls through*/ to the docs.

from jshint.

CrabDude avatar CrabDude commented on July 28, 2024

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.

gregjacobs avatar gregjacobs commented on July 28, 2024

+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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.