Skip to content

Commit

Permalink
fix: severity pass through
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc MacLeod committed Dec 11, 2018
1 parent 212cdaa commit eb0699c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
32 changes: 31 additions & 1 deletion src/__tests__/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('linter', () => {
expect(result.results.length).toBe(0);
});

test('should return extra properties', () => {
test('should return all properties', () => {
const message = '4xx responses require a description';

spectral.addFunctions({
Expand Down Expand Up @@ -94,6 +94,36 @@ describe('linter', () => {
});
});

test('should support rule overriding severity', () => {
spectral.addFunctions({
func1: () => {
return [
{
message: 'foo',
},
];
},
});

spectral.addRules({
rule1: {
given: '$.x',
severity: ValidationSeverity.Info,
severityLabel: ValidationSeverityLabel.Info,
then: {
function: 'func1',
},
},
});

const result = spectral.run({
x: true,
});

expect(result.results[0].severity).toEqual(ValidationSeverity.Info);
expect(result.results[0].severityLabel).toEqual(ValidationSeverityLabel.Info);
});

describe('functional tests for the given property', () => {
let fakeLintingFunction: any;

Expand Down
4 changes: 2 additions & 2 deletions src/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ export const lintNode = (
return {
name: rule.name,
message: result.message,
severity: ValidationSeverity.Error || rule.severity,
severityLabel: ValidationSeverityLabel.Error || rule.severityLabel,
severity: rule.severity || ValidationSeverity.Error,
severityLabel: rule.severityLabel || ValidationSeverityLabel.Error,
path: result.path || targetPath,
};
})
Expand Down
2 changes: 2 additions & 0 deletions src/spectral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
RunRuleCollection,
} from './types';

export * from './types';

export class Spectral {
private _rules: RuleCollection = {};
private _functions: FunctionCollection = defaultFunctions;
Expand Down

0 comments on commit eb0699c

Please sign in to comment.