question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Default rules enabled / extends

See original GitHub issue

I have not much knowledge of EsLint, but it is annoying to go through all rules and find out, which to use.

Could not you – just like plain EsLint – somehow also use a thing/things like "extends": "eslint:recommended", so one can get a set of rules that are almost always good for mocha tests?

I think there are many rules that should be enabled “by default”/“by extends”.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
Lakitnacommented, Jul 7, 2019

I would very much like a proper recommended ruleset. So let me kick off the discussion.

How about the following

// Will always result in a failed test, throw error to prevent this
'mocha/handle-done-callback': 'error',

// For low level tests it makes a lot of sense to enforce a single top level suite. For higher
// level tests you'll sometimes want more that one top level suite, but not often. Enforcing
// at 1 seems best for recommended
'mocha/max-top-level-suites': ['error', {limit: 1}],

// Exclusive tests (`.only`) in CI should be caught with `--forbid-only`. While working on
// tests a warning will suffice.
'mocha/no-exclusive-tests': 'warn',

// A test is always run in context, not adding a suite is a bad practice on the maintenance
// side of things.
'mocha/no-global-tests': 'error',

// Hooks (`.before` etc) are a very powerful part of Mocha and should not be disallowed.
// Disallowing this is very opinionated. 
'mocha/no-hooks': 'off',

// This can be a sign of bad test design. It can also be a valid separation of concerns imo.
// Am I opinionated?
'mocha/no-hooks-for-single-case': 'warn',

// You probably made a copypasta oopsy
'mocha/no-identical-title': 'error',

// `it(() => {})` should never be used because you loose `this`. A common trap that can be
// prevented with this rule
'mocha/no-mocha-arrows': 'error',

// Nested tests don't behave like you expect. You probably wanted to make a suite
'mocha/no-nested-tests': 'error',

// `it('is pending');`
// Not sure about this one. Might have to make this an error?
'mocha/no-pending-tests': 'warn',

// According to the docs, it causes a failure in Mocha. Prevent that with this rule
'mocha/no-return-and-callback': 'error',

// You should do this kind of thing in a hook.
'mocha/no-setup-in-describe': 'error',

// Generally confusing and unnecessary. The few times where you do want this you can
// skip the rule with an annotation. 
'mocha/no-sibling-hooks': 'error',

// Skipping tests can be a bad thing you should not forget about. I'm not sure about this
// one but I'd say you should catch this with `--forbid-pending` when you want to fail on
// this.
'mocha/no-skipped-tests': 'warn',

// Opinionated
'mocha/no-synchronous-tests': 'off',

// Hooks should always be part of a suite
'mocha/no-top-level-hooks': 'error',

// Opinionated
'mocha/prefer-arrow-callback': 'off',

// Opinionated and dependent on the way the project chooses to structure things
'mocha/valid-suite-description': 'off',

// Opinionated and dependent on the way the project chooses to structure things
'mocha/valid-test-description': 'off',

// Results in unexpected behaviour
'mocha/no-async-describe': 'error',
0reactions
lo1tumacommented, Jul 8, 2019

That sounds reasonable.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuration to enable all rules #6240 - eslint/eslint - GitHub
I would love to have a configuration that enables all rules, that way I can selectively disable them: extends: ['eslint:all'] This way I...
Read more >
Configuring ESLint - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
`.gitlab-ci.yml` keyword reference - GitLab Documentation
extends, Configuration entries that this job inherits from. image, Use Docker images. inherit, Select which global defaults all jobs inherit ...
Read more >
Configuration | Stylelint
No rules are turned on by default and there are no default values. ... For example, you can extend the stylelint-config-standard and then...
Read more >
Is only rules will be extends in share eslint config?
A configuration file can extend the set of enabled rules from base configurations. so only rules will be extended, and the other options( ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found