This repository has been archived by the owner on Apr 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
157 lines (133 loc) · 3.95 KB
/
gulpfile.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
var path = require('path');
var util = require('util');
var gulp = require('gulp');
var lazypipe = require('lazypipe');
var merge = require('merge-stream');
var cache = require('gulp-cache');
var jscs = require('gulp-jscs');
var jshint = require('gulp-jshint');
var replace = require('gulp-replace');
var FileCache = require('cache-swap');
var jshintStylish = require('jshint-stylish');
var globals = {};
var globalList = [
'Bot', 'CommandParser', 'Config', 'DataDownloader', 'Features', 'Formats', 'Settings', 'Tools',
'colors', 'sys', 'fs', 'path', 'PSClient',
'reloadConfig', 'reloadFeatures',
'toId', 'toRoomid', 'ok', 'info', 'error', 'errlog', 'debug', 'cmdr', 'recv', 'sent', 'monitor'
];
globalList.forEach(function (identifier) {globals[identifier] = false;});
function transformLet () {
// Replacing `var` with `let` is sort of a hack that stops jsHint from
// complaining that I'm using `var` like `let` should be used, but
// without having to deal with iffy `let` support.
return lazypipe()
.pipe(replace.bind(null, /\bvar\b/g, 'let'))();
}
function lint (jsHintOptions, jscsOptions) {
function cachedJsHint () {
return cache(jshint(jsHintOptions, {timeout: 450000}), {
success: function (file) {
return file.jshint.success;
},
value: function (file) {
return {jshint: file.jshint};
},
fileCache: new FileCache({tmpDir: '.', cacheDirName: 'gulp-cache'})
});
}
return lazypipe()
.pipe(cachedJsHint)
.pipe(jscs.bind(jscs, jscsOptions))();
}
var jsHintOptions = {};
jsHintOptions.base = {
"nonbsp": true,
"nonew": true,
"noarg": true,
"loopfunc": true,
"latedef": 'nofunc',
"freeze": true,
"undef": true,
"sub": true,
"evil": true,
"esnext": true,
"node": true,
"eqeqeq": true,
"globals": globals
};
var jscsOptions = {};
jscsOptions.base = {
"preset": "yandex",
"requireCurlyBraces": null,
"maximumLineLength": null,
"validateIndentation": '\t',
"validateQuoteMarks": null,
"disallowYodaConditions": null,
"disallowQuotedKeysInObjects": null,
"requireDotNotation": null,
"disallowMultipleVarDecl": null,
"disallowImplicitTypeConversion": null,
"requireSpaceAfterLineComment": null,
"validateJSDoc": null,
"disallowMixedSpacesAndTabs": "smart",
"requireSpaceAfterKeywords": true,
"disallowSpacesInFunctionDeclaration": null,
"requireSpacesInFunctionDeclaration": {
"beforeOpeningCurlyBrace": true
},
"requireSpacesInAnonymousFunctionExpression": {
"beforeOpeningRoundBrace": true,
"beforeOpeningCurlyBrace": true
},
"disallowSpacesInNamedFunctionExpression": null,
"requireSpacesInNamedFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"validateParameterSeparator": ", ",
"requireBlocksOnNewline": 1,
"disallowPaddingNewlinesInBlocks": true,
"requireOperatorBeforeLineBreak": true,
"disallowTrailingComma": true,
"requireCapitalizedConstructors": true,
"validateLineBreaks": require('os').EOL === '\n' ? 'LF' : null,
"disallowMultipleLineBreaks": null,
"esnext": true
};
jscsOptions.config = util._extend(util._extend({}, jscsOptions.base), {
"disallowTrailingComma": null
});
var lintData = [
{
dirs: ['./command-parser.js', './data-downloader.js', './index.js', './settings.js', './tools.js', './commands/*.js', './features/*/*.js', './languages/*.js'],
jsHint: jsHintOptions.base,
jscs: jscsOptions.base
}, {
dirs: ['./config-example.js'],
jsHint: jsHintOptions.base,
jscs: jscsOptions.config
}
];
var linter = function () {
return (
merge.apply(
null,
lintData.map(function (source) {
return gulp.src(source.dirs)
.pipe(transformLet())
.pipe(lint(source.jsHint, source.jscs));
})
).pipe(jshint.reporter(jshintStylish))
.pipe(jshint.reporter('fail'))
);
};
gulp.task('fastlint', function () {
var source = lintData[0];
return gulp.src(source.dirs)
.pipe(transformLet())
.pipe(lint(source.jsHint, source.jscs))
.pipe(jshint.reporter(jshintStylish))
.pipe(jshint.reporter('fail'));
});
gulp.task('lint', linter);
gulp.task('default', linter);