Loading ...
Sorry, an error occurred while loading the content.

2739Ternary Indentation Question

Expand Messages
  • spence.randall@ymail.com
    Jan 17, 2012
      Given the following example code:

      function test(x) {
      ~~~~'use strict';
      ~~~~return x === 1 ? 'one' :
      ~~~~~~~~x === 2 ? 'two' :
      ~~~~~~~~~~~~x === 3 ? 'three' :
      ~~~~~~~~~~~~~~~~x === 4 ? 'four' : 'zero';
      }

      JSLint will give you the following errors:


      Problem at line 5 character 9: Expected 'x' at column 13, not column 9.
      Problem at line 6 character 13: Expected 'x' at column 21, not column 13.
      Problem at line 7 character 17: Expected 'x' at column 29, not column 17.

      Which would result in this indentation scheme:

      function test(x) {
      ~~~~'use strict';
      ~~~~return x === 1 ? 'one' :
      ~~~~~~~~~~~~x === 2 ? 'two' :
      ~~~~~~~~~~~~~~~~~~~~~~~~x === 3 ? 'three' :
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~x === 4 ? 'four' : 'zero';
      }

      Is this the expected indentation level with strict white space?
    • Show all 8 messages in this topic