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.

How to produce less logging output when running via lint-staged?

See original GitHub issue

Hello, thank you for this awesome project! 👋

I’m finding that the default reporter produces a lot of duplication when running it with lint-staged:

\ | /     _         _   _
'-.ooo.-'  | |__  ___| |_| |_ ___ _ __ ___ _ __
---ooooo--- | '_ \/ _ \ __| __/ _ \ '__/ _ \ '__|
.-'ooo'-.  | |_)|  __/ |_| ||  __/ | |  __/ |
/ | \    |_.__/\___|\__|\__\___|_|  \___|_|

🌟 Betterer (12ms): 14 tests running...
🤔 test1: running "test1"!
🤔 test2: running "test2"!

\ | /     _         _   _
'-.ooo.-'  | |__  ___| |_| |_ ___ _ __ ___ _ __
---ooooo--- | '_ \/ _ \ __| __/ _ \ '__/ _ \ '__|
.-'ooo'-.  | |_)|  __/ |_| ||  __/ | |  __/ |
/ | \    |_.__/\___|\__|\__\___|_|  \___|_|

🌟 Betterer (112ms): 14 tests running...
🤔 test1: running "test1"!
🤔 test2: running "test2"!

\ | /     _         _   _
'-.ooo.-'  | |__  ___| |_| |_ ___ _ __ ___ _ __
---ooooo--- | '_ \/ _ \ __| __/ _ \ '__/ _ \ '__|
.-'ooo'-.  | |_)|  __/ |_| ||  __/ | |  __/ |
/ | \    |_.__/\___|\__|\__\___|_|  \___|_|

🌟 Betterer (214ms): 14 tests running...
🤔 test1: running "test1"!
🤔 test2: running "test2"!

I guess this is due to refreshing the screen which doesn’t work the same way in a non interactive mode?

This output is normally hidden, but if the code got worse then I would see a lot of logging output mixed in with the error message, which is not ideal.

I’ve tried to write a console reporter to replace the default reporter, with the following code:

import { BettererReporter } from '@betterer/betterer';

export const reporter: BettererReporter = createReporter();

function createReporter (): BettererReporter {
    return {
        contextError (ctx, error) {
            console.error(error);
        }
    }
}

However this doesn’t produce any output, betterer exits with 1. I’ve tried running this under Node 12, 14 & 16 with the same result.

Is there an alternative reporter I could use to print errors only? Or did I miss something from my custom reporter definition?

Many thanks 🙂

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
phenomnomnominalcommented, Feb 12, 2022

Hmm okay, there’s definitely something weird going on because that’s pretty much what it should be printing. I’ll dig in a little bit more.

For this particular case though, you might want to use @betterer/eslint and use https://eslint.org/docs/rules/no-console#no-console and https://eslint.org/docs/rules/no-restricted-imports or https://eslint.org/docs/rules/no-restricted-properties ?

0reactions
ben-ebcommented, Feb 13, 2022

Thanks, I’ll give that a try. 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

Output as plain text when running lint-staged through husky
Description When using lint-staged through a pre-commit hook with Husky, the output is shown as plain text as such: git commit When I...
Read more >
Is this a right way to use husky + lint-staged? - Stack Overflow
Run npm install --save-dev husky lint-staged and create a .lintstagedrc and as well as an .huskyrc at root. Example setup for some scripts...
Read more >
Lint Staged With Husky for Pre-commit Validations - YouTube
Learn how to use lint staged with husky to implement linting and formatting your code with Prettier and Eslint on pre-commit.
Read more >
Linting Staged Git Files with lint-staged -- newline - Fullstack.io
You can configure lint-staged to run a specific linter command against files that match a glob pattern. For JavaScript files ( *.js ),...
Read more >
Run a TypeScript type check in your pre-commit hook using ...
The issue I found - and at the time of writing, it is still being discussed - is that lint-staged would pass each...
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