2011-08-14 22:55:30 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2012-01-14 10:23:10 +01:00
|
|
|
* Copyright 2012 Facebook, Inc.
|
2011-08-14 22:55:30 +02:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
final class DifferentialLintFieldSpecification
|
|
|
|
extends DifferentialFieldSpecification {
|
|
|
|
|
|
|
|
public function shouldAppearOnRevisionView() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function renderLabelForRevisionView() {
|
|
|
|
return 'Lint:';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getRequiredDiffProperties() {
|
2012-02-24 23:26:49 +01:00
|
|
|
return array('arc:lint', 'arc:lint-excuse');
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getLintExcuse() {
|
2012-05-01 19:15:56 +02:00
|
|
|
return $this->getDiffProperty('arc:lint-excuse');
|
2011-08-14 22:55:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function renderValueForRevisionView() {
|
|
|
|
$diff = $this->getDiff();
|
2012-05-01 19:15:56 +02:00
|
|
|
$path_changesets = mpull($diff->loadChangesets(), 'getID', 'getFilename');
|
2011-08-14 22:55:30 +02:00
|
|
|
|
|
|
|
$lstar = DifferentialRevisionUpdateHistoryView::renderDiffLintStar($diff);
|
|
|
|
$lmsg = DifferentialRevisionUpdateHistoryView::getDiffLintMessage($diff);
|
|
|
|
$ldata = $this->getDiffProperty('arc:lint');
|
|
|
|
$ltail = null;
|
2012-05-01 19:15:56 +02:00
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
|
|
|
|
$rows[] = array(
|
|
|
|
'style' => 'star',
|
|
|
|
'name' => $lstar,
|
|
|
|
'value' => $lmsg,
|
|
|
|
'show' => true,
|
|
|
|
);
|
|
|
|
|
|
|
|
$excuse = $this->getLintExcuse();
|
|
|
|
if ($excuse) {
|
|
|
|
$rows[] = array(
|
|
|
|
'style' => 'excuse',
|
|
|
|
'name' => 'Excuse',
|
|
|
|
'value' => nl2br(phutil_escape_html($excuse)),
|
|
|
|
'show' => true,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$show_limit = 10;
|
|
|
|
$hidden = array();
|
2012-05-01 01:08:01 +02:00
|
|
|
|
2011-08-14 22:55:30 +02:00
|
|
|
if ($ldata) {
|
|
|
|
$ldata = igroup($ldata, 'path');
|
|
|
|
foreach ($ldata as $path => $messages) {
|
2012-05-01 19:15:56 +02:00
|
|
|
|
|
|
|
$rows[] = array(
|
|
|
|
'style' => 'section',
|
|
|
|
'name' => phutil_escape_html($path),
|
|
|
|
'show' => $show_limit,
|
|
|
|
);
|
|
|
|
|
2011-08-14 22:55:30 +02:00
|
|
|
foreach ($messages as $message) {
|
|
|
|
$path = idx($message, 'path');
|
|
|
|
$line = idx($message, 'line');
|
|
|
|
|
|
|
|
$code = idx($message, 'code');
|
|
|
|
$severity = idx($message, 'severity');
|
|
|
|
|
|
|
|
$name = idx($message, 'name');
|
|
|
|
$description = idx($message, 'description');
|
|
|
|
|
2012-05-01 19:15:56 +02:00
|
|
|
$line_link = 'line '.phutil_escape_html($line);
|
2012-01-14 10:23:10 +01:00
|
|
|
if (isset($path_changesets[$path])) {
|
2012-01-24 09:37:50 +01:00
|
|
|
// TODO: Create standalone links for large diffs. Logic is in
|
|
|
|
// DifferentialDiffTableOfContentsView::renderChangesetLink().
|
2012-01-17 01:42:14 +01:00
|
|
|
$line_link = phutil_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '#C'.$path_changesets[$path].'NL'.$line,
|
|
|
|
),
|
|
|
|
$line_link);
|
2012-01-14 10:23:10 +01:00
|
|
|
}
|
2012-05-01 19:15:56 +02:00
|
|
|
|
|
|
|
if ($show_limit) {
|
|
|
|
--$show_limit;
|
|
|
|
$show = true;
|
|
|
|
} else {
|
|
|
|
$show = false;
|
|
|
|
if (empty($hidden[$severity])) {
|
|
|
|
$hidden[$severity] = 0;
|
|
|
|
}
|
|
|
|
$hidden[$severity]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
$rows[] = array(
|
|
|
|
'style' => $this->getSeverityStyle($severity),
|
|
|
|
'name' => phutil_escape_html(ucwords($severity)),
|
|
|
|
'value' => hsprintf(
|
|
|
|
"(%s) %s at {$line_link}",
|
|
|
|
$code,
|
|
|
|
$name),
|
|
|
|
'show' => $show,
|
|
|
|
);
|
|
|
|
|
|
|
|
if (strlen($description)) {
|
|
|
|
$rows[] = array(
|
|
|
|
'style' => 'details',
|
|
|
|
'value' => nl2br(phutil_escape_html($description)),
|
|
|
|
'show' => false,
|
|
|
|
);
|
|
|
|
if (empty($hidden['details'])) {
|
|
|
|
$hidden['details'] = 0;
|
|
|
|
}
|
|
|
|
$hidden['details']++;
|
2012-05-01 01:08:01 +02:00
|
|
|
}
|
2011-08-14 22:55:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-01 19:15:56 +02:00
|
|
|
$show_string = $this->renderShowString($hidden);
|
|
|
|
|
|
|
|
$view = new DifferentialResultsTableView();
|
|
|
|
$view->setRows($rows);
|
|
|
|
$view->setShowMoreString($show_string);
|
|
|
|
|
|
|
|
return $view->render();
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getSeverityStyle($severity) {
|
|
|
|
$map = array(
|
|
|
|
ArcanistLintSeverity::SEVERITY_ERROR => 'red',
|
|
|
|
ArcanistLintSeverity::SEVERITY_WARNING => 'yellow',
|
|
|
|
ArcanistLintSeverity::SEVERITY_AUTOFIX => 'yellow',
|
|
|
|
ArcanistLintSeverity::SEVERITY_ADVICE => 'yellow',
|
|
|
|
);
|
|
|
|
return idx($map, $severity);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderShowString(array $hidden) {
|
|
|
|
if (!$hidden) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reorder hidden things by severity.
|
|
|
|
$hidden = array_select_keys(
|
|
|
|
$hidden,
|
|
|
|
array(
|
|
|
|
ArcanistLintSeverity::SEVERITY_ERROR,
|
|
|
|
ArcanistLintSeverity::SEVERITY_WARNING,
|
|
|
|
ArcanistLintSeverity::SEVERITY_AUTOFIX,
|
|
|
|
ArcanistLintSeverity::SEVERITY_ADVICE,
|
|
|
|
'details',
|
|
|
|
)) + $hidden;
|
|
|
|
|
|
|
|
$singular = array(
|
|
|
|
ArcanistLintSeverity::SEVERITY_ERROR => 'Error',
|
|
|
|
ArcanistLintSeverity::SEVERITY_WARNING => 'Warning',
|
|
|
|
ArcanistLintSeverity::SEVERITY_AUTOFIX => 'Auto-Fix',
|
|
|
|
ArcanistLintSeverity::SEVERITY_ADVICE => 'Advice',
|
|
|
|
'details' => 'Detail',
|
|
|
|
);
|
|
|
|
|
|
|
|
$plural = array(
|
|
|
|
ArcanistLintSeverity::SEVERITY_ERROR => 'Errors',
|
|
|
|
ArcanistLintSeverity::SEVERITY_WARNING => 'Warnings',
|
|
|
|
ArcanistLintSeverity::SEVERITY_AUTOFIX => 'Auto-Fixes',
|
|
|
|
ArcanistLintSeverity::SEVERITY_ADVICE => 'Advice',
|
|
|
|
'details' => 'Details',
|
|
|
|
);
|
|
|
|
|
|
|
|
$show = array();
|
|
|
|
foreach ($hidden as $key => $value) {
|
|
|
|
if ($value == 1) {
|
|
|
|
$show[] = $value.' '.idx($singular, $key);
|
|
|
|
} else {
|
|
|
|
$show[] = $value.' '.idx($plural, $key);
|
|
|
|
}
|
2012-05-01 01:08:01 +02:00
|
|
|
}
|
|
|
|
|
2012-05-01 19:15:56 +02:00
|
|
|
return "Show Full Lint Results (".implode(', ', $show).")";
|
2011-08-14 22:55:30 +02:00
|
|
|
}
|
2012-05-01 19:15:56 +02:00
|
|
|
|
2011-08-14 22:55:30 +02:00
|
|
|
}
|