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.

Disable advanced terminal behavior when TERM is dumb

See original GitHub issue

Description

lint-staged needs to respect when TERM is dumb and output simple information. This fixes issues in applications / plugins like vim-fugitive. An example is how chalk respects this here: https://github.com/chalk/supports-color/blob/8a40054cdbcd3f42b4f68eaefb41c3064835b991/index.js#L65-L67

Reference: https://github.com/tpope/vim-fugitive/issues/1446

Steps to reproduce

Running:

% export TERM=dumb && npx lint-staged
  ✔ Preparing...
  ✔ Running tasks...
  ✔ Applying modifications...
  ✔ Cleaning up...

Should output more simple information like:

% npx lint-staged | cat                                                                                                                                  ~/code/righttp develop +
Preparing... [started]
Preparing... [completed]
Running tasks... [started]
Running tasks for *.{js,jsx,ts,tsx} [started]
Running tasks for *.json [started]
Running tasks for *.json [skipped]
→ No staged files match *.json
prettier --write [started]
prettier --write [completed]
eslint --fix [started]
eslint --fix [completed]
jest --findRelatedTests [started]
jest --findRelatedTests [completed]
Running tasks for *.{js,jsx,ts,tsx} [completed]
Running tasks... [completed]
Applying modifications... [started]
Applying modifications... [completed]
Cleaning up... [started]
Cleaning up... [completed]

Debug Logs

expand to view
  lint-staged:bin Running `lint-staged@10.0.1` +0ms
  lint-staged:bin Options parsed from command-line: { allowEmpty: false,
  concurrent: true,
  configPath: undefined,
  debug: true,
  maxArgLength: 65536,
  quiet: false,
  relative: false,
  shell: false } +4ms
  lint-staged Loading config using `cosmiconfig` +0ms
  lint-staged Successfully loaded config from `/home/sqve/code/righttp/.lintstagedrc.json`:
  lint-staged { '*.{js,jsx,ts,tsx}':
  lint-staged    [ 'prettier --write', 'eslint --fix', 'jest --findRelatedTests' ],
  lint-staged   '*.json': [ 'prettier --write' ] } +13ms
  lint-staged:cfg Validating config +0ms
  lint-staged:run Running all linter scripts +0ms
  lint-staged:git Running git command [ 'rev-parse', '--show-toplevel' ] +0ms
  lint-staged:git Running git command [ 'rev-parse', '--show-superproject-working-tree' ] +19ms
  lint-staged:run Resolved git directory to be `/home/sqve/code/righttp` +29ms
  lint-staged:run Resolved git config directory to be `/home/sqve/code/righttp/.git` +1ms
  lint-staged:git Running git command [ 'diff', '--staged', '--diff-filter=ACMR', '--name-only' ] +10ms
  lint-staged:run Loaded list of staged files in git:
  lint-staged:run [ 'src/types.ts' ] +9ms
  lint-staged:chunkFiles Resolved an argument string length of 36 characters from 1 files +0ms
  lint-staged:chunkFiles Creating 1 chunks for maxArgLength of 65536 +0ms
  lint-staged:gen-tasks Generating linter tasks +0ms
  lint-staged:gen-tasks Generated task:
  lint-staged:gen-tasks { pattern: '*.{js,jsx,ts,tsx}',
  lint-staged:gen-tasks   commands:
  lint-staged:gen-tasks    [ 'prettier --write', 'eslint --fix', 'jest --findRelatedTests' ],
  lint-staged:gen-tasks   fileList: [ '/home/sqve/code/righttp/src/types.ts' ] } +6ms
  lint-staged:gen-tasks Generated task:
  lint-staged:gen-tasks { pattern: '*.json',
  lint-staged:gen-tasks   commands: [ 'prettier --write' ],
  lint-staged:gen-tasks   fileList: [] } +1ms
  lint-staged:make-cmd-tasks Creating listr tasks for commands [ 'prettier --write', 'eslint --fix', 'jest --findRelatedTests' ] +0ms
  lint-staged:task cmd: prettier --write /home/sqve/code/righttp/src/types.ts +0ms
  lint-staged:task execaOptions: { preferLocal: true, reject: false, shell: false } +0ms
  lint-staged:task cmd: eslint --fix /home/sqve/code/righttp/src/types.ts +1ms
  lint-staged:task execaOptions: { preferLocal: true, reject: false, shell: false } +0ms
  lint-staged:task cmd: jest --findRelatedTests /home/sqve/code/righttp/src/types.ts +0ms
  lint-staged:task execaOptions: { preferLocal: true, reject: false, shell: false } +0ms
  lint-staged:make-cmd-tasks Creating listr tasks for commands [ 'prettier --write' ] +2ms
  lint-staged:task cmd: prettier --write  +0ms
  lint-staged:task execaOptions: { preferLocal: true, reject: false, shell: false } +0ms
  lint-staged:git Backing up original state... +0ms
  lint-staged:git Backing up merge state... +0ms
  lint-staged:file Reading buffer from file `/home/sqve/code/righttp/.git/MERGE_HEAD` +0ms
  lint-staged:file Reading buffer from file `/home/sqve/code/righttp/.git/MERGE_MODE` +0ms
  lint-staged:file Reading buffer from file `/home/sqve/code/righttp/.git/MERGE_MSG` +0ms
  lint-staged:file File `/home/sqve/code/righttp/.git/MERGE_HEAD` doesn't exist, ignoring... +1ms
  lint-staged:file File `/home/sqve/code/righttp/.git/MERGE_MODE` doesn't exist, ignoring... +0ms
  lint-staged:file File `/home/sqve/code/righttp/.git/MERGE_MSG` doesn't exist, ignoring... +0ms
  lint-staged:git Done backing up merge state! +2ms
  lint-staged:git Running git command [ 'stash',
  'save',
  '--quiet',
  '--include-untracked',
  '--keep-index',
  'lint-staged automatic backup' ] +26ms
  lint-staged:git Restoring merge state... +46ms
  lint-staged:git Done restoring merge state! +0ms
  lint-staged:git Running git command [ 'ls-files', '--others', '--exclude-standard' ] +47ms
  lint-staged:git Running git command [ 'stash', 'list' ] +7ms
  lint-staged:git Running git command [ 'diff',
  '--binary',
  '--unified=0',
  '--no-color',
  '--no-ext-diff',
  '--patch',
  'stash@{0}',
  '-R' ] +8ms
  lint-staged:git Done backing up original state! +25ms
  lint-staged:git Running git command [ 'ls-files', '--modified' ] +8s
  lint-staged:git Running git command [ 'status', '--porcelain' ] +6ms
  lint-staged:git Restoring unstaged changes... +8s
  lint-staged:git Running git command [ 'apply',
  '-v',
  '--whitespace=nowarn',
  '--recount',
  '--unidiff-zero' ] +6ms
  lint-staged:git Done restoring unstaged changes! +10ms
  lint-staged:git Running git command [ 'stash', 'list' ] +9ms
  lint-staged:git Running git command [ 'show', '--format=%b', 'stash@{0}^3' ] +10ms
  lint-staged:git Dropping backup stash... +19ms
  lint-staged:git Running git command [ 'stash', 'list' ] +9ms
  lint-staged:git Running git command [ 'stash', 'drop', '--quiet', 'stash@{0}' ] +11ms
  lint-staged:git Done dropping backup stash! +27ms
  lint-staged tasks were executed successfully! +8s

Environment

  • OS: Arch Linux, 5.4.15
  • Node.js: v10.18.1
  • lint-staged: 10.0.1

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
tpopecommented, Jan 27, 2020

lint-staged appears to be setting FORCE_COLOR for all ttys, which has higher precedence than TERM=dumb in chalk’s supports-color library. A conservative change would be to add a TERM check to this conditional. It appears this behavior was added in #50 for, frankly, dubious reasons (at least from an outsider’s perspective); I would recommend reassessing if it’s still necessary.

https://github.com/okonet/lint-staged/blob/4010db09f6d168af677bd4ca1c815ba40460ae80/bin/lint-staged#L7-L10

0reactions
okonetcommented, Jan 29, 2020

🎉 This issue has been resolved in version 10.0.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

Read more comments on GitHub >

github_iconTop Results From Across the Web

Terminal Emulation - byexample - GitHub Pages
By default byexample uses a dumb terminal ( +term=dumb ) which is fast and works well in most cases. But you can change...
Read more >
Wall-of-text issue with refreshing git hooks #1446 - GitHub
Disabling the advanced terminal behavior when TERM is dumb should do the trick. Here's something similar I found when poking around Husky:.
Read more >
FAQ - iTerm2 - macOS Terminal Replacement
Turn on Preferences > Advanced > Terminal windows resize smoothly to disable this behavior and that usually fixes the issue.
Read more >
less(1) - Linux manual page - man7.org
-d or --dumb The -d option suppresses the error message normally displayed if the terminal is dumb; that is, lacks some important capability,...
Read more >
How can I turn off "scrolling the history" in iTerm2
It's a mode (alternate screen) for terminal emulation set by the remote to your terminal which is then left on and not set...
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