From b1f0df88d562ab0e294b7faeba727d8a177b26ac Mon Sep 17 00:00:00 2001 From: Ava Thorn Date: Fri, 9 Apr 2021 14:52:53 -0400 Subject: [PATCH] Update to always use terminal width rather than fixed narrow width --- .gitignore | 1 + lib/reporter/cli_reporter.js | 2 +- test/cli_reporter.js | 32 ++++++++++++++------------------ 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 030fc7a..617a1da 100755 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules/ .nyc_output/ +.idea/ diff --git a/lib/reporter/cli_reporter.js b/lib/reporter/cli_reporter.js index dfd0e6b..268629e 100644 --- a/lib/reporter/cli_reporter.js +++ b/lib/reporter/cli_reporter.js @@ -4,7 +4,7 @@ const chalk = require('chalk'); const cliui = require('cliui'); const Reporter = require('./reporter'); -const DEFAULT_TOTAL_WIDTH = 110; +const DEFAULT_TOTAL_WIDTH = process.stdout.columns; const ISSUE_COL0_WIDTH = 5; const ISSUE_COL1_WIDTH = 14; const ISSUE_TITLE_WIDTH_MAX = 40; diff --git a/test/cli_reporter.js b/test/cli_reporter.js index 3833d6c..6b98b88 100644 --- a/test/cli_reporter.js +++ b/test/cli_reporter.js @@ -9,9 +9,9 @@ describe('cli_reporter', () => { describe('#constructor(opts)', () => { it('sets defaults with no options given', () => { let reporter = new CliReporter(); - expect(reporter.ui.width).to.equal(110); + expect(reporter.ui.width).to.equal(process.stdout.columns); expect(reporter.ui.wrap).to.equal(true); - expect(reporter.issueTitleWidth).to.equal(22); + expect(reporter.issueTitleWidth).to.equal(40); expect(reporter.styles['Deprecation']).to.be.a('function'); expect(reporter.styles['Possible Bug']).to.be.a('function'); expect(reporter.styles['Clarity']).to.be.a('function'); @@ -28,9 +28,9 @@ describe('cli_reporter', () => { it('doesn\'t blow up when width is NaN', () => { let reporter = new CliReporter({ width: 'hello' }); - expect(reporter.ui.width).to.equal(110); + expect(reporter.ui.width).to.equal(process.stdout.columns); expect(reporter.ui.wrap).to.equal(true); - expect(reporter.issueTitleWidth).to.equal(22); + expect(reporter.issueTitleWidth).to.equal(40); }); }); @@ -112,22 +112,18 @@ describe('cli_reporter', () => { 'Issues: 4', '', 'Line 5: ' + chalk.magenta('FROM ubuntu'), - 'Issue Category Title Description', - ' ' + chalk.cyan('1') + ' ' + chalk.cyan.inverse('Clarity') + ' ' + chalk.cyan('Base Image Missing') + ' ' + chalk.gray('Base images should specify a tag to use.'), - ' ' + chalk.cyan('Tag'), + 'Issue Category Title Description', + ' ' + chalk.cyan('1') + ' ' + chalk.cyan.inverse('Clarity') + ' ' + chalk.cyan('Base Image Missing Tag') + ' ' + chalk.gray('Base images should specify a tag to use.'), '', 'Line 6: ' + chalk.magenta('FROM ubuntu:latest'), - 'Issue Category Title Description', - ' ' + chalk.yellow('2') + ' ' + chalk.yellow.inverse('Possible Bug') + ' ' + chalk.yellow('First Command Must') + ' ' + chalk.gray('The first instruction in a Dockerfile must specify the base image'), - ' ' + chalk.yellow('Be FROM') + ' ' + chalk.gray('using a FROM command. Additionally, FROM cannot appear later in a'), - ' ' + chalk.gray('Dockerfile.'), - ' ' + chalk.cyan('3') + ' ' + chalk.cyan.inverse('Clarity') + ' ' + chalk.cyan('Base Image Latest') + ' ' + chalk.gray('Base images should not use the latest tag.'), - ' ' + chalk.cyan('Tag'), + 'Issue Category Title Description', + ' ' + chalk.yellow('2') + ' ' + chalk.yellow.inverse('Possible Bug') + ' ' + chalk.yellow('First Command Must Be FROM') + ' ' + chalk.gray('The first instruction in a Dockerfile must specify the base image using a FROM command. Additionally, FROM cannot appear'), + ' ' + chalk.gray('later in a Dockerfile.'), + ' ' + chalk.cyan('3') + ' ' + chalk.cyan.inverse('Clarity') + ' ' + chalk.cyan('Base Image Latest Tag') + ' ' + chalk.gray('Base images should not use the latest tag.'), '', 'Line 25: ' + chalk.magenta('EXPOSE 80:80'), - 'Issue Category Title Description', - ' ' + chalk.red('4') + ' ' + chalk.red.inverse('Deprecation') + ' ' + chalk.red('Expose Only') + ' ' + chalk.gray('Using `EXPOSE` to specify a host port is not allowed.'), - ' ' + chalk.red('Container Port'), + 'Issue Category Title Description', + ' ' + chalk.red('4') + ' ' + chalk.red.inverse('Deprecation') + ' ' + chalk.red('Expose Only Container Port') + ' ' + chalk.gray('Using `EXPOSE` to specify a host port is not allowed.'), '' ]); }); @@ -151,8 +147,8 @@ describe('cli_reporter', () => { 'Issues: 1', '', 'Line 5: ' + chalk.magenta('RUN apt-get update && \\'), - 'Issue Category Title Description', - ' ' + chalk.cyan('1') + ' ' + chalk.cyan.inverse('Hello') + ' ' + chalk.cyan('Hello World!') + ' ' + chalk.gray('This is a test.'), + 'Issue Category Title Description', + ' ' + chalk.cyan('1') + ' ' + chalk.cyan.inverse('Hello') + ' ' + chalk.cyan('Hello World!') + ' ' + chalk.gray('This is a test.'), '' ]); });