Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable advanced terminal behavior when TERM is dumb #781

Closed
sQVe opened this issue Jan 27, 2020 · 8 comments · Fixed by #782
Closed

Disable advanced terminal behavior when TERM is dumb #781

sQVe opened this issue Jan 27, 2020 · 8 comments · Fixed by #782
Labels

Comments

@sQVe
Copy link

sQVe commented Jan 27, 2020

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: tpope/vim-fugitive#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
@iiroj
Copy link
Member

iiroj commented Jan 27, 2020

Thanks for the issue! Since it seems simple, I went ahead and implemented it at #782.

Question: we use chalk to support colored output, but it doesn't seem to react itself to this variable. Should it?

@sQVe
Copy link
Author

sQVe commented Jan 27, 2020

@iiroj I would assume that it, but I'm unsure. Nicely done with the quick fix!

@tpope
Copy link

tpope commented 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

@tpope
Copy link

tpope commented Jan 27, 2020

Now that I think about it, the right way to do this probably is to use supports-color itself to decide whether to force color support down the line:

const supportsColor = require('supports-color');
if (supportsColor.stdout) {
  process.env.FORCE_COLOR = supportsColor.stdout.level.toString();
}

(Edit: Added .level.toString().)

@iiroj
Copy link
Member

iiroj commented Jan 27, 2020

Thanks for the tip, @tpope, I added it to the PR! It's a shame to add a new dependency, but then again it was already in via chalk.

@tpope
Copy link

tpope commented Jan 27, 2020

My reading of chalk's README is that you can use chalk.supportsColor directly to get the same effect.

@iiroj
Copy link
Member

iiroj commented Jan 27, 2020

@tpope Perfect, thanks for finding that. Made the change a bit simpler: 6803f6a

@okonet
Copy link
Collaborator

okonet commented Jan 29, 2020

🎉 This issue has been resolved in version 10.0.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

4 participants