stalniy/bdd-lazy-var

Add eslint rule/plugin to handle $foo global vars

stalniy opened this issue · 6 comments

Requirements:

  • perceive all variables with name $* as defined
  • if onlyDefined option is set to true, then additionally check whether the lazy var is defined with def
  • if noDynamicName option is set to true, then rule will not allow to use dynamically defined lazy vars
  • allow to specify dialects (bdd, bdd/getter, bdd/global) to check defined lazy vars
  • adds its, def, subject, get, sharedExamplesFor, includeExamplesFor, itBehavesLike and is to global variables
  • this rule must play nice with no-undef rule or substitute it (implement its behavior inside)

+1 from me. Love the lib but I also love a clean lint log.

I started the work in feat/eslint-rule branch, probably it need to be a plugin not just a few rules

I did work around this issue by disabling the rule specifically for tests:

    "overrides": [
        {
            "files": ["*.test.js"],
            "rules": {
                "no-undef": 0
            }
        }
    ],

in eslintrc.js

I did work around this issue by disabling the rule specifically for tests:

    "overrides": [
        {
            "files": ["*.test.js"],
            "rules": {
                "no-undef": 0
            }
        }
    ],

in eslintrc.js

not Ideal to ignore the rule, but it's a good enough workaround while we don't have the real deal 🤷

Another good workaround which I saw in the wild is $.name. You have almost the same as with global interface using getter interface (bdd-lazy-var/getter)

const { get } = require('bdd-lazy-var/getter')
global.$ = get

This will be redundant with a new version. The API is shown in this comment