jfmengels/eslint-plugin-fp

Rules tend to be noisy in test frameworks

Opened this issue · 3 comments

Popular test frameworks like Mocha, Jasmine, and Jest encourage having many anonymous functions with assertions instead of return values. While this is inherently not a very functional paradigm, many functional libraries still use these test frameworks and it can be inconvenient to batch disable many rules at once.

Possible solutions

  1. Tell users to disable eslint in the test directory with an .eslintignore file. This is pretty drastic, but if we agree on this it wouldn't require any changes.
  2. Provide a configuration that disables all rules from this plugin. Unfortunately, eslint doesn't have an option for disabling all of a plugin's rules (see eslint/eslint#3419), so this would be a workaround.
  3. Provide a configuration that's similar to recommended, but friendlier to anonymous functions with assertions. This could disable rules like no-nil and no-unused-expressions. Users would then switch to this configuration only for test directories.

@nickmccurdy another solution is to recommend users us the Validation applicative function instead of asserts.

Thanks for the link. I've used applicatives in Haskell, and while it's a great pattern for general purpose pure functional programming, I'm concerned that this works against the much more imperative styles of almost all popular JavaScript testing frameworks (Mocha, Jasmine, Jest, Ava, Tape). I could use this pattern in my implementation, but I would need to use a test framework that only uses applicatives and pure results (which as far as I'm aware doesn't exist yet, though I've been experimenting with one. One could write their own testing infrastructure from scratch to meet these rules, but I feel like that's a lot of work for a linting library to impose.

What do you think about my possible solutions? I just converted them to a numbered list.

@nickmccurdy I like your option 3, but this package seem to be unmaintained 😢
Option 1 is also okayish.