How to use the @stoplight/types.DiagnosticSeverity.Hint function in @stoplight/types

To help you get started, we’ve selected a few @stoplight/types examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stoplightio / spectral / src / rulesets / severity.ts View on Github external
if (newRule === 'recommended') {
    return existingRule.recommended !== false ? existingSeverity : -1;
  }

  if (newRule === 'all') {
    return existingSeverity;
  }

  return getSeverityForRule(newRule, existingSeverity);
}

const SEVERITY_MAP: Dictionary = {
  error: DiagnosticSeverity.Error,
  warn: DiagnosticSeverity.Warning,
  info: DiagnosticSeverity.Information,
  hint: DiagnosticSeverity.Hint,
  off: -1,
};

export function getDiagnosticSeverity(
  severity: DiagnosticSeverity | HumanReadableDiagnosticSeverity,
): SpectralDiagnosticSeverity {
  if (Number.isNaN(Number(severity))) {
    return SEVERITY_MAP[severity];
  }
  return Number(severity);
}
github stoplightio / spectral / src / formatters / stylish.ts View on Github external
Object.keys(groupedResults).map((path, index) => {
    const pathResults = groupedResults[path];

    const {
      [DiagnosticSeverity.Error]: errors,
      [DiagnosticSeverity.Warning]: warnings,
      [DiagnosticSeverity.Information]: infos,
      [DiagnosticSeverity.Hint]: hints,
    } = groupBySeverity(pathResults);

    errorCount += errors.length;
    warningCount += warnings.length;
    infoCount += infos.length;
    hintCount += hints.length;

    output += `${chalk.underline(path)}\n`;

    const pathTableData = sortResults(pathResults).map((result: IRuleResult) => [
      formatRange(result.range),
      getMessageType(result.severity),
      result.code !== undefined ? result.code : '',
      result.message,
    ]);
github stoplightio / spectral / src / formatters / stylish.ts View on Github external
*/
function pluralize(word: string, count: number): string {
  return count === 1 ? word : `${word}s`;
}

function formatRange(range?: IRange): string {
  if (!range) return '';

  return ` ${range.start.line + 1}:${range.start.character + 1}`;
}

const SEVERITY_COLORS = {
  [DiagnosticSeverity.Error]: 'red',
  [DiagnosticSeverity.Warning]: 'yellow',
  [DiagnosticSeverity.Information]: 'blue',
  [DiagnosticSeverity.Hint]: 'white',
};

function getColorForSeverity(severity: DiagnosticSeverity) {
  return SEVERITY_COLORS[severity];
}

function getMessageType(severity: DiagnosticSeverity) {
  const color = getColorForSeverity(severity);

  switch (severity) {
    case DiagnosticSeverity.Error:
      return chalk[color]('error');
    case DiagnosticSeverity.Warning:
      return chalk[color]('warning');
    case DiagnosticSeverity.Information:
      return chalk[color]('information');