This repository was archived by the owner on Nov 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathannotations.js
53 lines (43 loc) · 2.3 KB
/
annotations.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const R = require('ramda');
function createAnnotation(annotationClass, namespace, message, element) {
const annotation = new namespace.elements.Annotation(message);
annotation.classes = [annotationClass];
annotation.attributes.set('sourceMap', element.attributes.get('sourceMap'));
return annotation;
}
const createError = R.curry(createAnnotation)('error');
const createWarning = R.curry(createAnnotation)('warning');
function createUnsupportedMemberWarning(namespace, path, member) {
const message = `'${path}' contains unsupported key '${member.key.toValue()}'`;
return createWarning(namespace, message, member.key);
}
function createInvalidMemberWarning(namespace, path, member) {
const message = `'${path}' contains invalid key '${member.key.toValue()}'`;
return createWarning(namespace, message, member.key);
}
function createIdentifierNotUniqueWarning(namespace, path, member) {
return createWarning(namespace, `'${path}' '${member.key.toValue()}' is not a unique identifier: '${member.value.toValue()}'`, member.value);
}
function createMemberValueNotStringWarning(namespace, path, member) {
return createWarning(namespace, `'${path}' '${member.key.toValue()}' is not a string`, member.value);
}
function createMemberValueNotStringError(namespace, path, member) {
return createError(namespace, `'${path}' '${member.key.toValue()}' is not a string`, member.value);
}
function createMemberValueNotBooleanWarning(namespace, path, member) {
return createWarning(namespace, `'${path}' '${member.key.toValue()}' is not a boolean`, member.value);
}
function createMemberValueNotBooleanError(namespace, path, member) {
return createError(namespace, `'${path}' '${member.key.toValue()}' is not a boolean`, member.value);
}
module.exports = {
createError,
createWarning,
createUnsupportedMemberWarning: R.curry(createUnsupportedMemberWarning),
createInvalidMemberWarning: R.curry(createInvalidMemberWarning),
createIdentifierNotUniqueWarning: R.curry(createIdentifierNotUniqueWarning),
createMemberValueNotStringWarning: R.curry(createMemberValueNotStringWarning),
createMemberValueNotStringError: R.curry(createMemberValueNotStringError),
createMemberValueNotBooleanWarning: R.curry(createMemberValueNotBooleanWarning),
createMemberValueNotBooleanError: R.curry(createMemberValueNotBooleanError),
};