This repository has been archived by the owner on Mar 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 515
/
preset.js
61 lines (55 loc) · 1.73 KB
/
preset.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
54
55
56
57
58
59
60
61
var presets = {
// https://github.com/airbnb/javascript
airbnb: require('../../presets/airbnb.json'),
// http://javascript.crockford.com/code.html
crockford: require('../../presets/crockford.json'),
// https://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml
google: require('../../presets/google.json'),
// https://contribute.jquery.org/style-guide/js/
jquery: require('../../presets/jquery.json'),
// https://github.com/mrdoob/three.js/wiki/Mr.doob's-Code-Style%E2%84%A2
mdcs: require('../../presets/mdcs.json'),
// https://www.mediawiki.org/wiki/Manual:Coding_conventions/JavaScript
wikimedia: require('../../presets/wikimedia.json'),
// https://github.com/ymaps/codestyle/blob/master/js.md
yandex: require('../../presets/yandex.json')
};
module.exports = {
/**
* Get does not exist error
* @param {String} preset
* @return {String}
*/
getDoesNotExistError: function(preset) {
return 'Preset "' + preset + '" does not exist';
},
/**
* Is preset exists in jscs
* @param {String} preset
* @return {Boolean}
*/
exists: function(preset) {
return !!presets[preset];
},
/**
* Extend jscs config with preset rules
* @param {Object} config
* @return {Boolean}
*/
extend: function(config) {
if (!config.preset) {
return true;
}
var preset = presets[config.preset];
if (!preset) {
return false;
}
delete config.preset;
for (var rule in preset) {
if (preset.hasOwnProperty(rule) && !(rule in config)) {
config[rule] = preset[rule];
}
}
return true;
}
};