coffeelint-advanced-colon-assignment-spacing

Validate a spacing left and right of a colon assignment

Usage no npm install needed!

<script type="module">
  import coffeelintAdvancedColonAssignmentSpacing from 'https://cdn.skypack.dev/coffeelint-advanced-colon-assignment-spacing';
</script>

README

Coffeelint - Advanced Colon Assignment Spacing

Validate minimum and maximum spacing left and right of a colon assignment.

Description

This CoffeeLint plugin verifies whether or not a minimum amount of spacing is to the left and/or right of a colon assignment. It is based on the 'colon_assignment_spacing' rule but is more powerful allowing you to specify a minimum and maximum allowed spacing. This can come in handy when you have files with object assignments where the colon are vertically aligned. See the Router class in the examples part.

Installation

[sudo] npm install -g coffeelint-advanced-colon-assignment-spacing

Note: Right now a Coffeelint plugin cannot be installed as a project dependency and must be installed globally. Perhaps this will be improved in a future version of Coffeelint. If you would like to track progress on this enhancement head over here.

Usage

Insert the below configuration into coffeelint.json that you use for linting your scripts:

"advanced_colon_assignment_spacing": {
  "module": "coffeelint-advanced-colon-assignment-spacing",
  "level": "error",
  "spacing": {
    "left": {
      "min": 0,
      "max": 0
    },
    "right": {
      "min": 1,
      "max": null
    }
  }
}

Example

This code will lint without errors:

class TestClass

  foo: ->
    bar()

class Router
  routes:
    "/main":            "main"
    "/dashboard/users": "dashboard"
    "/settings":        settings

But this will fail:

class TestClass

  foo:->
    console.log("Oh no! I have linting errors.")

Configuration

The only configuration option specific to this plugin is the spacing property. Change the min/max of the left/right property to control the rule. You can ignore an option by providing null instead of an integer.

Credits

Credits go to Ian McNally and Tom Herold whose colon_assignment_spacing and min_colon_spacing rules serve as the basis for this fork.

License

MIT © Levi Buzolic