Skip to content

Commit

Permalink
style(*): fix formatting and linting issues (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
derevnjuk committed Mar 23, 2021
1 parent a797c20 commit 86c66ad
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
48 changes: 25 additions & 23 deletions src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ export enum EnvironmentalMetric {
MODIFIED_AVAILABILITY = 'MA'
}

export type Metric = BaseMetric | TemporalMetric | EnvironmentalMetric;
export type BaseMetricValue = 'A' | 'C' | 'H' | 'L' | 'N' | 'P' | 'R' | 'U';
export type TemporalMetricValue =
| 'X'
| 'F'
| 'H'
| 'O'
| 'T'
| 'W'
| 'U'
| 'P'
| 'C'
| 'R';

export const baseMetrics: ReadonlyArray<BaseMetric> = [
BaseMetric.ATTACK_VECTOR,
BaseMetric.ATTACK_COMPLEXITY,
Expand All @@ -40,6 +54,17 @@ export const baseMetrics: ReadonlyArray<BaseMetric> = [
BaseMetric.AVAILABILITY
];

export type EnvironmentalMetricValue = BaseMetricValue | 'M' | 'X';
export type MetricValue =
| BaseMetricValue
| TemporalMetricValue
| EnvironmentalMetricValue;
export type MetricValues<
M extends Metric = Metric,
V extends MetricValue = MetricValue
> = Record<M, V[]>;
export type Metrics<M = Metric> = ReadonlyArray<M>;

export const temporalMetrics: Metrics<TemporalMetric> = [
TemporalMetric.EXPLOIT_CODE_MATURITY,
TemporalMetric.REMEDIATION_LEVEL,
Expand Down Expand Up @@ -97,29 +122,6 @@ export const environmentalMetricValues: MetricValues<
[EnvironmentalMetric.MODIFIED_AVAILABILITY]: ['X', 'N', 'L', 'H']
};

export type Metric = BaseMetric | TemporalMetric | EnvironmentalMetric;
export type BaseMetricValue = 'A' | 'C' | 'H' | 'L' | 'N' | 'P' | 'R' | 'U';
export type TemporalMetricValue =
| 'X'
| 'F'
| 'H'
| 'O'
| 'T'
| 'W'
| 'U'
| 'P'
| 'C'
| 'R';
export type EnvironmentalMetricValue = BaseMetricValue | 'M' | 'X';
export type MetricValue =
| BaseMetricValue
| TemporalMetricValue
| EnvironmentalMetricValue;
export type MetricValues<
M extends Metric = Metric,
V extends MetricValue = MetricValue
> = Record<M, V[]>;
export type Metrics<M = Metric> = ReadonlyArray<M>;
export type AllMetricValues =
| typeof baseMetricValues
| typeof temporalMetricValues
Expand Down
8 changes: 4 additions & 4 deletions src/score-calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,13 @@ export const calculateBaseScore = (cvssString: string): number => {
export const calculateEnvironmentalResult = (
cvssString: string
): ScoreResult => {
const { versionStr } = validate(cvssString);
let { metricsMap } = validate(cvssString);
const result = validate(cvssString);
let { metricsMap } = result;

metricsMap = populateTemporalMetricDefaults(metricsMap);
metricsMap = populateEnvironmentalMetricDefaults(metricsMap);
const miss = calculateMiss(metricsMap);
const impact = calculateMImpact(metricsMap, miss, versionStr);
const impact = calculateMImpact(metricsMap, miss, result.versionStr);
const exploitability = calculateMExploitability(metricsMap);
const scopeUnchanged =
metricsMap.get(EnvironmentalMetric.MODIFIED_SCOPE) === 'U';
Expand Down Expand Up @@ -421,7 +421,7 @@ export const calculateEnvironmentalScore = (cvssString: string): number => {
export const calculateTemporalResult = (cvssString: string): ScoreResult => {
const { metricsMap } = validate(cvssString);
// populate temp metrics if not provided
[...temporalMetrics].map((metric) => {
[...temporalMetrics].forEach((metric) => {
if (![...metricsMap.keys()].includes(metric)) {
metricsMap.set(metric, 'X');
}
Expand Down

0 comments on commit 86c66ad

Please sign in to comment.