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

Output list instead of table #5426

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
"ajv": "8.17.1",
"chalk": "4.1.2",
"cheerio": "1.0.0-rc.12",
"columnify": "1.6.0",
"common-tags": "1.8.2",
"deepmerge": "4.3.1",
"eslint": "8.57.0",
Expand Down
117 changes: 27 additions & 90 deletions src/linter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import path from 'path';

import columnify from 'columnify';
import chalk from 'chalk';
import { oneLine } from 'common-tags';
import { lstat } from 'addons-scanner-utils/dist/io/utils';
Expand All @@ -10,7 +9,6 @@ import {
} from 'addons-scanner-utils/dist/errors';
import { Directory, Xpi, Crx } from 'addons-scanner-utils/dist/io';

import { terminalWidth } from 'cli';
import * as constants from 'const';
import { BANNED_LIBRARIES, UNADVISED_LIBRARIES } from 'libraries';
import * as messages from 'messages';
Expand Down Expand Up @@ -154,104 +152,43 @@ export default class Linter {
return _JSON.stringify.apply(null, args);
}

textOutput(_terminalWidth = terminalWidth) {
const maxColumns = _terminalWidth();
textOutput() {
const out = [];

out.push(i18n._('Validation Summary:'));
out.push('');
out.push(
columnify(this.output.summary, {
showHeaders: false,
minWidth: 15,
})
);
Object.entries(this.output.summary).forEach(([key, value]) => {
out.push(`${key}: ${value}`);
});
out.push('');

constants.MESSAGE_TYPES.forEach((type) => {
const messageType = `${type}s`;
if (this.output[messageType].length) {
const outputConfig = {
code: {
dataTransform: (value) => {
return this.colorize(type)(value);
},
headingTransform: () => {
return i18n._('Code');
},
maxWidth: 35,
},
message: {
headingTransform: () => {
return i18n._('Message');
},
maxWidth: (maxColumns - 35) * 0.25,
},
description: {
headingTransform: () => {
return i18n._('Description');
},
maxWidth: (maxColumns - 35) * 0.5,
},
file: {
headingTransform: () => {
return i18n._('File');
},
maxWidth: (maxColumns - 35) * 0.25,
},
line: {
headingTransform: () => {
return i18n._('Line');
},
maxWidth: 6,
},
column: {
headingTransform: () => {
return i18n._('Column');
},
maxWidth: 6,
},
};

const outputColumns = [
'code',
'message',
'description',
'file',
'line',
'column',
];

// If the terminal is this small we cave and don't size things
// contextually anymore.
if (maxColumns < 60) {
delete outputColumns[outputColumns.indexOf('column')];
delete outputConfig.column;
delete outputColumns[outputColumns.indexOf('description')];
delete outputConfig.description;
delete outputColumns[outputColumns.indexOf('line')];
delete outputConfig.line;

outputConfig.message.maxWidth = 15;
outputConfig.file.maxWidth = 15;
} else if (maxColumns < 78) {
delete outputColumns[outputColumns.indexOf('description')];
delete outputConfig.description;

outputConfig.message.maxWidth = (maxColumns - 47) * 0.5;
outputConfig.file.maxWidth = (maxColumns - 35) * 0.5;
}

out.push(`${messageType.toUpperCase()}:`);
out.push(this.colorize(type)(`${messageType.toUpperCase()}:`));
out.push('');
out.push(
columnify(this.output[messageType], {
maxWidth: 35,
columns: outputColumns,
columnSplitter: ' ',
config: outputConfig,
})
);

const groupedMessages = {};
this.output[messageType].forEach((message) => {
if (!groupedMessages[message.code]) {
groupedMessages[message.code] = [];
}
groupedMessages[message.code].push(message);
});

Object.entries(groupedMessages).forEach(([code, list]) => {
out.push(this.colorize(type)(` ${code}`));
out.push(` ${list[0].message}`);
list.forEach((message) => {
const location = message.file
? `${message.file}${message.line ? `:${message.line}` : ''}${
message.column ? `:${message.column}` : ''
}`
: 'N/A';
out.push(` ${location}`);
});
out.push('');
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@willdurand @rpl This code is straight out of Claude. We can bikeshed the output but I think it's a vast improvement already.

Codebase cleanup and tests update will follow after approval

}
});

Expand Down