Skip to content

Commit 42572f2

Browse files
author
Piotr Oleś
committed
eslint
1 parent f8ab8fa commit 42572f2

15 files changed

+101
-76
lines changed

.eslintrc.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"env": {
3+
"node": true
4+
},
5+
"extends": "eslint:recommended",
6+
"rules": {
7+
"indent": [
8+
"error",
9+
2
10+
],
11+
"linebreak-style": [
12+
"error",
13+
"unix"
14+
],
15+
"quotes": [
16+
"error",
17+
"single"
18+
],
19+
"semi": [
20+
"error",
21+
"always"
22+
]
23+
}
24+
}

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2017 Piotr Oleś
3+
Copyright (c) 2017 Realytics
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

karma.conf.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
var webpack = require('webpack');
2-
var path = require('path');
3-
var process = require('process');
4-
51
module.exports = function (config) {
62
config.set({
73
browsers: ['PhantomJS'],

lib/CancellationToken.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@ var os = require('os');
44
var path = require('path');
55
var crypto = require('crypto');
66

7-
function CancellationToken(cancellationFileName, isCancelled) {
7+
function CancellationToken (cancellationFileName, isCancelled) {
88
this.isCancelled = !!isCancelled;
99
this.cancellationFileName = cancellationFileName || crypto.randomBytes(64).toString('hex');
1010
this.lastCancellationCheckTime = 0;
1111
}
1212
module.exports = CancellationToken;
1313

14-
CancellationToken.createFromJSON = function(json) {
14+
CancellationToken.createFromJSON = function (json) {
1515
return new CancellationToken(
1616
json.cancellationFileName,
1717
json.isCancelled
1818
);
1919
};
2020

21-
CancellationToken.prototype.toJSON = function() {
21+
CancellationToken.prototype.toJSON = function () {
2222
return {
2323
cancellationFileName: this.cancellationFileName,
2424
isCancelled: this.isCancelled
2525
};
2626
};
2727

28-
CancellationToken.prototype.isCancellationRequested = function() {
28+
CancellationToken.prototype.isCancellationRequested = function () {
2929
if (this.isCancelled) {
3030
return true;
3131
}
@@ -42,13 +42,13 @@ CancellationToken.prototype.isCancellationRequested = function() {
4242
return this.isCancelled;
4343
};
4444

45-
CancellationToken.prototype.throwIfCancellationRequested = function() {
45+
CancellationToken.prototype.throwIfCancellationRequested = function () {
4646
if (this.isCancellationRequested()) {
4747
throw new ts.OperationCanceledException();
4848
}
4949
};
5050

51-
CancellationToken.prototype.requestCancellation = function() {
51+
CancellationToken.prototype.requestCancellation = function () {
5252
fs.writeFileSync(getCancellationFilePath(this.cancellationFileName), '');
5353
};
5454

@@ -58,6 +58,6 @@ CancellationToken.prototype.cleanupCancellation = function () {
5858
}
5959
};
6060

61-
function getCancellationFilePath(cancellationFileName) {
61+
function getCancellationFilePath (cancellationFileName) {
6262
return path.join(os.tmpdir(), cancellationFileName);
6363
}

lib/FilesRegister.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
function FilesRegister(oldRegister) {
2+
function FilesRegister (oldRegister) {
33
this.register = {};
44

55
if (oldRegister) {

lib/FilesWatcher.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var chokidar = require('chokidar');
22
var path = require('path');
33
var startsWith = require('lodash.startswith');
44

5-
function FilesWatcher(watchPaths, watchExtensions) {
5+
function FilesWatcher (watchPaths, watchExtensions) {
66
this.watchPaths = watchPaths;
77
this.watchExtensions = watchExtensions;
88
this.watchers = [];
@@ -11,8 +11,8 @@ function FilesWatcher(watchPaths, watchExtensions) {
1111
}
1212
module.exports = FilesWatcher;
1313

14-
FilesWatcher.prototype.isFileSupported = function(filePath) {
15-
return -1 !== this.watchExtensions.indexOf(path.extname(filePath));
14+
FilesWatcher.prototype.isFileSupported = function (filePath) {
15+
return this.watchExtensions.indexOf(path.extname(filePath)) !== -1;
1616
};
1717

1818
FilesWatcher.prototype.watch = function () {
@@ -21,14 +21,14 @@ FilesWatcher.prototype.watch = function () {
2121
watchPath,
2222
{ persistent: true }
2323
)
24-
.on('change', function(filePath, stats) {
24+
.on('change', function (filePath, stats) {
2525
if (this.isFileSupported(filePath)) {
2626
this.changeListeners.forEach(function (changeListener) {
2727
changeListener(filePath, stats);
2828
});
2929
}
3030
}.bind(this))
31-
.on('unlink', function(filePath) {
31+
.on('unlink', function (filePath) {
3232
if (this.isFileSupported(filePath)) {
3333
this.unlinkListeners.forEach(function (unlinkListener) {
3434
unlinkListener(filePath);
@@ -54,19 +54,19 @@ FilesWatcher.prototype.isWatching = function () {
5454
FilesWatcher.prototype.onChange = function (changeListener) {
5555
this.changeListeners.push(changeListener);
5656

57-
return function unsubscribe() {
57+
return function unsubscribe () {
5858
this.changeListeners.filter(function (listener) {
5959
return listener !== changeListener;
60-
})
60+
});
6161
}.bind(this);
6262
};
6363

6464
FilesWatcher.prototype.onUnlink = function (unlinkListener) {
6565
this.unlinkListeners.push(unlinkListener);
6666

67-
return function unsubscribe() {
67+
return function unsubscribe () {
6868
this.unlinkListeners.filter(function (listener) {
6969
return listener !== unlinkListener;
70-
})
70+
});
7171
}.bind(this);
7272
};

lib/IncrementalChecker.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
var ts = require('typescript');
22
var fs = require('fs');
33
var path = require('path');
4+
var endsWith = require('lodash.endswith');
45
var FilesRegister = require('./FilesRegister');
56
var FilesWatcher = require('./FilesWatcher');
67

7-
function IncrementalChecker(programConfigFile, linterConfigFile, watchPaths) {
8+
function IncrementalChecker (programConfigFile, linterConfigFile, watchPaths) {
89
this.programConfigFile = programConfigFile;
910
this.linterConfigFile = linterConfigFile;
1011
this.watchPaths = watchPaths;
@@ -25,11 +26,11 @@ IncrementalChecker.loadLinterConfig = function (configFile) {
2526
return tslint.Configuration.loadConfigurationFromPath(configFile);
2627
};
2728

28-
IncrementalChecker.createProgram = function(programConfig, register, watcher, oldProgram) {
29+
IncrementalChecker.createProgram = function (programConfig, register, watcher, oldProgram) {
2930
var host = ts.createCompilerHost(programConfig.options);
3031
var originGetSourceFile = host.getSourceFile;
3132

32-
host.getSourceFile = function(filePath, languageVersion, onError) {
33+
host.getSourceFile = function (filePath, languageVersion, onError) {
3334
// first check if watcher is watching file - if not - check it's mtime
3435
if (!watcher.isWatchingFile(filePath)) {
3536
var stats = fs.statSync(filePath);
@@ -56,13 +57,13 @@ IncrementalChecker.createProgram = function(programConfig, register, watcher, ol
5657
);
5758
};
5859

59-
IncrementalChecker.createLinter = function(program) {
60+
IncrementalChecker.createLinter = function (program) {
6061
var tslint = require('tslint');
6162

6263
return new tslint.Linter({ fix: false }, program);
6364
};
6465

65-
IncrementalChecker.prototype.nextIteration = function() {
66+
IncrementalChecker.prototype.nextIteration = function () {
6667
this.register = new FilesRegister(this.register);
6768

6869
if (!this.watcher) {
@@ -87,7 +88,7 @@ IncrementalChecker.prototype.nextIteration = function() {
8788
this.linter = IncrementalChecker.createLinter(this.program);
8889
};
8990

90-
IncrementalChecker.prototype.getDiagnostics = function(cancellationToken) {
91+
IncrementalChecker.prototype.getDiagnostics = function (cancellationToken) {
9192
var diagnostics = this.program.getSemanticDiagnostics(undefined, cancellationToken);
9293

9394
return diagnostics.map(function (diagnostic) {
@@ -106,11 +107,11 @@ IncrementalChecker.prototype.getDiagnostics = function(cancellationToken) {
106107
});
107108
};
108109

109-
IncrementalChecker.prototype.getLints = function(cancellationToken) {
110+
IncrementalChecker.prototype.getLints = function (cancellationToken) {
110111
this.register.forEach(function (fileName, fileEntry) {
111112
cancellationToken.throwIfCancellationRequested();
112113

113-
if (!fileName.endsWith('.d.ts') && !fileEntry.linted) {
114+
if (!endsWith(fileName, '.d.ts') && !fileEntry.linted) {
114115
this.linter.lint(fileName, undefined, this.linterConfig);
115116
fileEntry.linted = true;
116117
}
@@ -134,6 +135,6 @@ IncrementalChecker.prototype.getLints = function(cancellationToken) {
134135
file: lint.getFileName(),
135136
line: position.line,
136137
character: position.character
137-
}
138+
};
138139
});
139140
};

0 commit comments

Comments
 (0)