Skip to content

Commit 668057c

Browse files
committed
Make linter happy and fix convert errors
1 parent bd85bb0 commit 668057c

33 files changed

+491
-518
lines changed

.eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
spec/fixtures
2+
examples

.eslintrc.yml

+8
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,11 @@ globals:
1010

1111
settings:
1212
import/core-modules: [ atom ]
13+
14+
rules:
15+
no-restricted-syntax: [0, "FunctionExpression", "no-restricted-syntax"]
16+
no-param-reassign: [0]
17+
class-methods-use-this: [0]
18+
default-case: [0]
19+
guard-for-in: [0]
20+
no-this-before-super: [0]

examples/longrun.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ let i = 1;
22
const run = setInterval(() => {
33
console.log(`line ${i}`);
44
i++;
5-
if (i == 20) {
5+
if (i === 20) {
66
stop();
77
}
88
}, 1000);

examples/longrun.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var i: number = 1;
22
var run = setInterval(function() {
33
console.log("line " + i);
44
i++;
5-
if (i == 20) {
5+
if (i === 20) {
66
stop();
77
}
88
}, 1000);

lib/code-context-builder.js

+10-13
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use babel';
22

3-
import CodeContext from './code-context';
4-
import grammarMap from './grammars';
5-
63
import { Emitter } from 'atom';
74

5+
import CodeContext from './code-context';
6+
import grammarMap from './grammars.coffee';
7+
88
export default class CodeContextBuilder {
99
constructor(emitter = new Emitter()) {
1010
this.emitter = emitter;
@@ -25,7 +25,7 @@ export default class CodeContextBuilder {
2525
//
2626
// returns a {CodeContext} object
2727
buildCodeContext(editor, argType = 'Selection Based') {
28-
if (editor == null) { return; }
28+
if (!editor) return null;
2929

3030
const codeContext = this.initCodeContext(editor);
3131

@@ -35,7 +35,7 @@ export default class CodeContextBuilder {
3535
editor.save();
3636
} else if (codeContext.selection.isEmpty() && (codeContext.filepath != null)) {
3737
codeContext.argType = 'File Based';
38-
if (__guard__(editor, x => x.isModified())) { editor.save(); }
38+
if (editor && editor.isModified()) editor.save();
3939
}
4040

4141
// Selection and Line Number Based runs both benefit from knowing the current line
@@ -57,10 +57,11 @@ export default class CodeContextBuilder {
5757
// If the selection was empty or if ignore selection is on, then "select" ALL
5858
// of the text
5959
// This allows us to run on new files
60+
let textSource;
6061
if (selection.isEmpty() || ignoreSelection) {
61-
var textSource = editor;
62+
textSource = editor;
6263
} else {
63-
var textSource = selection;
64+
textSource = selection;
6465
}
6566

6667
const codeContext = new CodeContext(filename, filepath, textSource);
@@ -77,11 +78,11 @@ export default class CodeContextBuilder {
7778
}
7879

7980
getShebang(editor) {
80-
if (process.platform === 'win32') { return; }
81+
if (process.platform === 'win32') return null;
8182
const text = editor.getText();
8283
const lines = text.split('\n');
8384
const firstLine = lines[0];
84-
if (!firstLine.match(/^#!/)) { return; }
85+
if (!firstLine.match(/^#!/)) return null;
8586

8687
return firstLine.replace(/^#!\s*/, '');
8788
}
@@ -116,7 +117,3 @@ export default class CodeContextBuilder {
116117
return this.emitter.on('did-not-support-language', callback);
117118
}
118119
}
119-
120-
function __guard__(value, transform) {
121-
return (typeof value !== 'undefined' && value !== null) ? transform(value) : undefined;
122-
}

lib/code-context.js

+8-11
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ export default class CodeContext {
2828
//
2929
// Returns the "file colon line" {String}.
3030
fileColonLine(fullPath = true) {
31+
let fileColonLine;
3132
if (fullPath) {
32-
var fileColonLine = this.filepath;
33+
fileColonLine = this.filepath;
3334
} else {
34-
var fileColonLine = this.filename;
35+
fileColonLine = this.filename;
3536
}
3637

3738
if (!this.lineNumber) { return fileColonLine; }
@@ -44,8 +45,8 @@ export default class CodeContext {
4445
//
4546
// Returns the code selection {String}
4647
getCode(prependNewlines = true) {
47-
const code = __guard__(this.textSource, x => x.getText());
48-
if (!prependNewlines || !this.lineNumber) { return code; }
48+
const code = this.textSource ? this.textSource.getText() : null;
49+
if (!prependNewlines || !this.lineNumber) return code;
4950

5051
const newlineCount = Number(this.lineNumber);
5152
const newlines = Array(newlineCount).join('\n');
@@ -57,7 +58,7 @@ export default class CodeContext {
5758
// Returns the {String} name of the command or {undefined} if not applicable.
5859
shebangCommand() {
5960
const sections = this.shebangSections();
60-
if (!sections) { return; }
61+
if (!sections) return null;
6162

6263
return sections[0];
6364
}
@@ -70,19 +71,15 @@ export default class CodeContext {
7071
const sections = this.shebangSections();
7172
if (!sections) { return []; }
7273

73-
return sections.slice(1, sections.length - 1 + 1 || undefined);
74+
return sections.slice(1, sections.length);
7475
}
7576

7677
// Public: Splits the shebang string by spaces to extra the command and
7778
// arguments
7879
//
7980
// Returns the {String} name of the command or {undefined} if not applicable.
8081
shebangSections() {
81-
return __guard__(this.shebang, x => x.split(' '));
82+
return this.shebang ? this.shebang.split(' ') : null;
8283
}
8384
}
8485
CodeContext.initClass();
85-
86-
function __guard__(value, transform) {
87-
return (typeof value !== 'undefined' && value !== null) ? transform(value) : undefined;
88-
}

lib/command-context.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use babel';
22

3-
import grammarMap from './grammars';
3+
import grammarMap from './grammars.coffee';
44

55
export default class CommandContext {
66
static initClass() {
@@ -13,16 +13,18 @@ export default class CommandContext {
1313
static build(runtime, runOptions, codeContext) {
1414
const commandContext = new CommandContext();
1515
commandContext.options = runOptions;
16+
let buildArgsArray;
1617

1718
try {
1819
if ((runOptions.cmd == null) || runOptions.cmd === '') {
1920
// Precondition: lang? and lang of grammarMap
20-
commandContext.command = codeContext.shebangCommand() || grammarMap[codeContext.lang][codeContext.argType].command;
21+
commandContext.command = codeContext.shebangCommand() ||
22+
grammarMap[codeContext.lang][codeContext.argType].command;
2123
} else {
2224
commandContext.command = runOptions.cmd;
2325
}
2426

25-
var buildArgsArray = grammarMap[codeContext.lang][codeContext.argType].args;
27+
buildArgsArray = grammarMap[codeContext.lang][codeContext.argType].args;
2628
} catch (error) {
2729
runtime.modeNotSupported(codeContext.argType, codeContext.lang);
2830
return false;

lib/grammar-utils.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,28 @@ export default {
2727

2828
return tempFilePath;
2929
} catch (error) {
30-
throw (`Error while creating temporary file (${error})`);
30+
throw new Error(`Error while creating temporary file (${error})`);
3131
}
3232
},
3333

34-
// Public: Delete all temporary files and the directory created by {GrammarUtils::createTempFileWithCode}
34+
// Public: Delete all temporary files and the directory created by
35+
// {GrammarUtils::createTempFileWithCode}
3536
deleteTempFiles() {
3637
try {
3738
if (fs.existsSync(this.tempFilesDir)) {
3839
const files = fs.readdirSync(this.tempFilesDir);
3940
if (files.length) {
40-
files.forEach((file, index) => fs.unlinkSync(this.tempFilesDir + path.sep + file));
41+
files.forEach(file => fs.unlinkSync(this.tempFilesDir + path.sep + file));
4142
}
4243
return fs.rmdirSync(this.tempFilesDir);
4344
}
45+
return null;
4446
} catch (error) {
45-
throw (`Error while deleting temporary files (${error})`);
47+
throw new Error(`Error while deleting temporary files (${error})`);
4648
}
4749
},
4850

51+
/* eslint-disable global-require */
4952
// Public: Get the Java helper object
5053
//
5154
// Returns an {Object} which assists in preparing java + javac statements

lib/grammar-utils/coffee-script-compiler.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ try {
1010
if (coffee.toString().match(/--cli/)) { // -redux
1111
args.push('--cli');
1212
}
13-
} catch (error) {}
13+
} catch (error) { /* Don't throw */ }
1414

15-
export { args };
15+
export default { args };

lib/grammar-utils/d.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default {
2727

2828
return tempFilePath;
2929
} catch (error) {
30-
throw (`Error while creating temporary file (${error})`);
30+
throw new Error(`Error while creating temporary file (${error})`);
3131
}
3232
},
3333
};

lib/grammar-utils/java.js

+1-11
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,7 @@ export default {
2626
// Returns {String} containing the matching project path
2727
getProjectPath(context) {
2828
const projectPaths = atom.project.getPaths();
29-
return (() => {
30-
const result = [];
31-
for (const projectPath of projectPaths) {
32-
let item;
33-
if (context.filepath.includes(projectPath)) {
34-
item = projectPath;
35-
}
36-
result.push(item);
37-
}
38-
return result;
39-
})();
29+
return projectPaths.find(projectPath => context.filepath.includes(projectPath));
4030
},
4131

4232
// Public: Get package of file in context

lib/grammar-utils/lisp.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default {
99
//
1010
// Returns an {Array} of executable statements.
1111
splitStatements(code) {
12-
const iterator = function (statements, currentCharacter, _memo, _context) {
12+
const iterator = (statements, currentCharacter) => {
1313
if (this.parenDepth == null) { this.parenDepth = 0; }
1414
if (currentCharacter === '(') {
1515
this.parenDepth += 1;

lib/grammar-utils/matlab.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default {
2727

2828
return tempFilePath;
2929
} catch (error) {
30-
throw (`Error while creating temporary file (${error})`);
30+
throw new Error(`Error while creating temporary file (${error})`);
3131
}
3232
},
3333
};

lib/grammar-utils/nim.js

+16-32
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
'use babel';
22

3+
import fs from 'fs';
4+
import path from 'path';
5+
36
// Public: GrammarUtils.Nim - a module which selects the right file to run for Nim projects
47
export default {
58
// Public: Find the right file to run
@@ -9,43 +12,29 @@ export default {
912
// Returns the {String} filepath of file to run
1013

1114
projectDir(editorfile) {
12-
const path = require('path');
1315
return path.dirname(editorfile);
1416
},
1517

1618
findNimProjectFile(editorfile) {
17-
const path = require('path');
18-
const fs = require('fs');
19-
2019
if (path.extname(editorfile) === '.nims') {
2120
// if we have an .nims file
22-
try {
23-
var tfile = editorfile.slice(0, -1);
24-
var stats = fs.statSync(tfile);
21+
const tfile = editorfile.slice(0, -1);
22+
23+
if (fs.existsSync(tfile)) {
2524
// it has a corresponding .nim file. so thats a config file.
2625
// we run the .nim file instead.
2726
return path.basename(tfile);
28-
} catch (error) {
29-
// it has no corresponding .nim file, it is a standalone script
30-
return path.basename(editorfile);
3127
}
28+
// it has no corresponding .nim file, it is a standalone script
29+
return path.basename(editorfile);
3230
}
3331

3432
// check if we are running on a file with config
35-
try {
36-
var stats = fs.statSync(`${editorfile}s`);
33+
if (fs.existsSync(`${editorfile}s`) ||
34+
fs.existsSync(`${editorfile}.cfg`) ||
35+
fs.existsSync(`${editorfile}cfg`)) {
3736
return path.basename(editorfile);
38-
} catch (error) {}
39-
40-
try {
41-
var stats = fs.statSync(`${editorfile}.cfg`);
42-
return path.basename(editorfile);
43-
} catch (error1) {}
44-
45-
try {
46-
var stats = fs.statSync(`${editorfile}cfg`);
47-
return path.basename(editorfile);
48-
} catch (error2) {}
37+
}
4938

5039
// assume we want to run a project
5140
// searching for the first file which has
@@ -59,15 +48,10 @@ export default {
5948
const name = `${filepath}/${file}`;
6049
if (fs.statSync(name).isFile()) {
6150
if (path.extname(name) === '.nims' ||
62-
path.extname(name) === '.nimcgf' ||
63-
path.extname(name) === '.cfg') {
64-
try {
65-
var tfile = name.slice(0, -1);
66-
var stats = fs.statSync(tfile);
67-
return path.basename(tfile);
68-
} catch (error) {
69-
console.log('File does not exist.');
70-
}
51+
path.extname(name) === '.nimcgf' ||
52+
path.extname(name) === '.cfg') {
53+
const tfile = name.slice(0, -1);
54+
if (fs.existsSync(tfile)) return path.basename(tfile);
7155
}
7256
}
7357
}

lib/header-view.js

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default class HeaderView extends View {
1919
case 'stop': return this.status.addClass('icon-check');
2020
case 'kill': return this.status.addClass('icon-stop');
2121
case 'err': return this.status.addClass('icon-alert');
22+
default: return null;
2223
}
2324
}
2425
}

lib/link-paths.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use babel';
22

3+
/* eslint-disable no-multi-str, prefer-const*/
34
let linkPaths;
45
const regex = new RegExp('\
56
((?:\\w:)?/?\
@@ -12,14 +13,14 @@ const template = '<a class="-linked-path" data-path="$1" data-line="$2" data-col
1213
export default linkPaths = lines => lines.replace(regex, template);
1314

1415
linkPaths.listen = parentView =>
15-
parentView.on('click', '.-linked-path', function (event) {
16+
parentView.on('click', '.-linked-path', () => {
1617
const el = this;
1718
let { path, line, column } = el.dataset;
1819
line = Number(line) - 1;
1920
// column number is optional
2021
column = column ? Number(column) - 1 : 0;
2122

22-
return atom.workspace.open(path, {
23+
atom.workspace.open(path, {
2324
initialLine: line,
2425
initialColumn: column,
2526
});

0 commit comments

Comments
 (0)