summaryrefslogtreecommitdiffstats
path: root/rules
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-05-15 12:45:38 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-05-15 12:45:38 +0100
commit1d2cb297a1cd882e6b0ea75ca5c081f844742c18 (patch)
treef88f2d3ff9b0c2f7861fd4c80a1e38d3d15e12b3 /rules
parent90dca8a51be79ea3b8704afafb2cd75b2d65e31f (diff)
downloadrspamd-1d2cb297a1cd882e6b0ea75ca5c081f844742c18.tar.gz
rspamd-1d2cb297a1cd882e6b0ea75ca5c081f844742c18.zip
[Minor] Pet luacheck
Diffstat (limited to 'rules')
-rw-r--r--rules/misc.lua2
1 files changed, 1 insertions, 1 deletions
diff --git a/rules/misc.lua b/rules/misc.lua
index c70e90bbc..080d03584 100644
--- a/rules/misc.lua
+++ b/rules/misc.lua
@@ -658,7 +658,7 @@ local check_encrypted_name = rspamd_config:register_symbol{
elseif cld:is_text() then
seen_text = true
else
- local type,subtype,attrs = cld:get_type_full()
+ local type,subtype,_ = cld:get_type_full()
if type:lower() == 'application' then
if string.find(subtype:lower(), 'pkcs7%-mime') then
77'>77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
/*
 * SonarQube
 * Copyright (C) 2009-2024 SonarSource SA
 * mailto:info AT sonarsource DOT com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
import styled from '@emotion/styled';
import classNames from 'classnames';
import {
  BasicSeparator,
  LightGreyCard,
  NakedLink,
  TextBold,
  TextSubdued,
  themeColor,
} from 'design-system';
import * as React from 'react';
import { useIntl } from 'react-intl';
import { DEFAULT_ISSUES_QUERY } from '../../../components/shared/utils';
import { formatMeasure, formatRating } from '../../../helpers/measures';
import { getComponentIssuesUrl } from '../../../helpers/urls';
import {
  SoftwareImpactMeasureData,
  SoftwareImpactSeverity,
  SoftwareQuality,
} from '../../../types/clean-code-taxonomy';
import { MetricKey, MetricType } from '../../../types/metrics';
import { Component, MeasureEnhanced } from '../../../types/types';
import { softwareQualityToMeasure } from '../utils';
import SoftwareImpactMeasureBreakdownCard from './SoftwareImpactMeasureBreakdownCard';
import SoftwareImpactMeasureRating from './SoftwareImpactMeasureRating';

export interface SoftwareImpactBreakdownCardProps {
  component: Component;
  softwareQuality: SoftwareQuality;
  ratingMetricKey: MetricKey;
  measures: MeasureEnhanced[];
}

export function SoftwareImpactMeasureCard(props: Readonly<SoftwareImpactBreakdownCardProps>) {
  const { component, softwareQuality, ratingMetricKey, measures } = props;

  const intl = useIntl();

  // Find measure for this software quality
  const metricKey = softwareQualityToMeasure(softwareQuality);
  const measureRaw = measures.find((m) => m.metric.key === metricKey);
  const measure = JSON.parse(measureRaw?.value ?? 'null') as SoftwareImpactMeasureData;

  // Find rating measure
  const ratingMeasure = measures.find((m) => m.metric.key === ratingMetricKey);
  const ratingLabel = ratingMeasure?.value ? formatRating(ratingMeasure.value) : undefined;

  const totalLinkHref = getComponentIssuesUrl(component.key, {
    ...DEFAULT_ISSUES_QUERY,
    impactSoftwareQualities: softwareQuality,
  });

  // We highlight the highest severity breakdown card with non-zero count if the rating is not A
  let highlightedSeverity: SoftwareImpactSeverity | undefined;
  if (measure && (!ratingLabel || ratingLabel !== 'A')) {
    highlightedSeverity = [
      SoftwareImpactSeverity.High,
      SoftwareImpactSeverity.Medium,
      SoftwareImpactSeverity.Low,
    ].find((severity) => measure[severity] > 0);
  }

  return (
    <LightGreyCard
      data-testid={`software-impact-card-${softwareQuality}`}
      className="sw-w-1/3 sw-overflow-hidden sw-rounded-2 sw-p-4 sw-flex-col"
    >
      <TextBold name={intl.formatMessage({ id: `software_quality.${softwareQuality}` })} />
      <BasicSeparator className="sw--mx-4" />
      <div className="sw-flex sw-flex-col sw-gap-3">
        <div
          className={classNames('sw-flex sw-gap-1 sw-items-end', {
            'sw-opacity-60': !measure,
          })}
        >
          {measure ? (
            <NakedLink
              aria-label={intl.formatMessage(
                {
                  id: `overview.measures.software_impact.see_list_of_x_open_issues`,
                },
                {
                  count: measure.total,
                  softwareQuality: intl.formatMessage({
                    id: `software_quality.${softwareQuality}`,
                  }),
                },
              )}
              className="sw-text-xl"
              to={totalLinkHref}
            >
              {formatMeasure(measure.total, MetricType.ShortInteger)}
            </NakedLink>
          ) : (
            <StyledDash className="sw-self-center sw-font-bold" name="-" />
          )}
          <TextSubdued className="sw-body-sm sw-mb-2">
            {intl.formatMessage({ id: 'overview.measures.software_impact.total_open_issues' })}
          </TextSubdued>
          <div className="sw-flex-grow sw-flex sw-justify-end">
            <SoftwareImpactMeasureRating
              softwareQuality={softwareQuality}
              value={ratingMeasure?.value}
            />
          </div>
        </div>
        <div className="sw-flex sw-gap-2">
          {[
            SoftwareImpactSeverity.High,
            SoftwareImpactSeverity.Medium,
            SoftwareImpactSeverity.Low,
          ].map((severity) => (
            <SoftwareImpactMeasureBreakdownCard
              key={severity}
              component={component}
              softwareQuality={softwareQuality}
              value={measure?.[severity]?.toString()}
              severity={severity}
              active={highlightedSeverity === severity}
            />
          ))}
        </div>
      </div>
      {!measure && (
        <>
          <BasicSeparator className="sw--mx-4 sw-mb-0 sw-mt-3" />
          <StyledInfoSection className="sw--ml-4 sw--mr-4 sw--mb-4 sw-text-xs sw-p-4 sw-flex sw-gap-1 sw-flex-wrap">
            <span>{intl.formatMessage({ id: 'overview.project.no_data' })}</span>
            <span>
              {intl.formatMessage({
                id: `overview.run_analysis_to_compute.${component.qualifier}`,
              })}
            </span>
          </StyledInfoSection>
        </>
      )}
    </LightGreyCard>
  );
}

const StyledDash = styled(TextBold)`
  font-size: 36px;
`;

const StyledInfoSection = styled.div`
  background-color: ${themeColor('overviewSoftwareImpactSeverityNeutral')};
`;

export default SoftwareImpactMeasureCard;