Skip to content

Commit 400af8c

Browse files
authored
Merge pull request #2422 from atom-community/deps
2 parents 126777a + 19d08ec commit 400af8c

35 files changed

+1790
-811
lines changed

.eslintignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

.eslintrc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "eslint-config-atomic",
3+
"ignorePatterns": ["dist/", "node_modules/", "spec/fixtures", "examples", "lib/grammars/*.coffee"]
4+
}

.eslintrc.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

lib/code-context-builder.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default class CodeContextBuilder {
2525
//
2626
// returns a {CodeContext} object
2727
buildCodeContext(editor, argType = 'Selection Based') {
28-
if (!editor) return null;
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) {
3737
codeContext.argType = 'File Based';
38-
if (editor && editor.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
@@ -66,9 +66,9 @@ export default class CodeContextBuilder {
6666

6767
const codeContext = new CodeContext(filename, filepath, textSource);
6868
codeContext.selection = selection;
69-
codeContext.shebang = this.getShebang(editor);
69+
codeContext.shebang = getShebang(editor);
7070

71-
const lang = this.getLang(editor);
71+
const lang = getLang(editor);
7272

7373
if (this.validateLang(lang)) {
7474
codeContext.lang = lang;
@@ -77,18 +77,14 @@ export default class CodeContextBuilder {
7777
return codeContext;
7878
}
7979

80-
getShebang(editor) {
81-
if (process.platform === 'win32') return null;
82-
const text = editor.getText();
83-
const lines = text.split('\n');
84-
const firstLine = lines[0];
85-
if (!firstLine.match(/^#!/)) return null;
86-
87-
return firstLine.replace(/^#!\s*/, '');
80+
/** @deprecated use {getShebang} function */ // eslint-disable-next-line class-methods-use-this
81+
getShebang(arg) {
82+
return getShebang(arg);
8883
}
8984

90-
getLang(editor) {
91-
return editor.getGrammar().name;
85+
/** @deprecated use {getLang} function */ // eslint-disable-next-line class-methods-use-this
86+
getLang(arg) {
87+
return getLang(arg);
9288
}
9389

9490
validateLang(lang) {
@@ -117,3 +113,17 @@ export default class CodeContextBuilder {
117113
return this.emitter.on('did-not-support-language', callback);
118114
}
119115
}
116+
117+
export function getShebang(editor) {
118+
if (process.platform === 'win32') {return null;}
119+
const text = editor.getText();
120+
const lines = text.split('\n');
121+
const firstLine = lines[0];
122+
if (!firstLine.match(/^#!/)) {return null;}
123+
124+
return firstLine.replace(/^#!\s*/, '');
125+
}
126+
127+
export function getLang(editor) {
128+
return editor.getGrammar().name;
129+
}

lib/code-context.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default class CodeContext {
4040
// Returns the code selection {String}
4141
getCode(prependNewlines = true) {
4242
const code = this.textSource ? this.textSource.getText() : null;
43-
if (!prependNewlines || !this.lineNumber) return code;
43+
if (!prependNewlines || !this.lineNumber) {return code;}
4444

4545
const newlineCount = Number(this.lineNumber);
4646
const newlines = Array(newlineCount).join('\n');
@@ -52,7 +52,7 @@ export default class CodeContext {
5252
// Returns the {String} name of the command or {undefined} if not applicable.
5353
shebangCommand() {
5454
const sections = this.shebangSections();
55-
if (!sections) return null;
55+
if (!sections) {return null;}
5656

5757
return sections[0];
5858
}

lib/command-context.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,28 @@ export default class CommandContext {
4848
return commandContext;
4949
}
5050

51+
/** @deprecated use {quoteArguments} function */ // eslint-disable-next-line class-methods-use-this
5152
quoteArguments(args) {
52-
return args.map((arg) => (arg.trim().indexOf(' ') === -1 ? arg.trim() : `'${arg}'`));
53+
return quoteArguments(args)
5354
}
5455

5556
getRepresentation() {
56-
if (!this.command || !this.args.length) return '';
57+
if (!this.command || !this.args.length) {return '';}
5758

5859
// command arguments
59-
const commandArgs = this.options.cmdArgs ? this.quoteArguments(this.options.cmdArgs).join(' ') : '';
60+
const commandArgs = this.options.cmdArgs ? quoteArguments(this.options.cmdArgs).join(' ') : '';
6061

6162
// script arguments
62-
const args = this.args.length ? this.quoteArguments(this.args).join(' ') : '';
63-
const scriptArgs = this.options.scriptArgs ? this.quoteArguments(this.options.scriptArgs).join(' ') : '';
63+
const args = this.args.length ? quoteArguments(this.args).join(' ') : '';
64+
const scriptArgs = this.options.scriptArgs ? quoteArguments(this.options.scriptArgs).join(' ') : '';
6465

6566
return this.command.trim()
6667
+ (commandArgs ? ` ${commandArgs}` : '')
6768
+ (args ? ` ${args}` : '')
6869
+ (scriptArgs ? ` ${scriptArgs}` : '');
6970
}
7071
}
72+
73+
export function quoteArguments(args) {
74+
return args.map((arg) => (arg.trim().indexOf(' ') === -1 ? arg.trim() : `'${arg}'`));
75+
}

lib/grammar-utils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import path from 'path';
77
import { v1 as uuidv1 } from 'uuid';
88

99
// Public: GrammarUtils - utilities for determining how to run code
10-
export default {
10+
const GrammarUtils = {
1111
tempFilesDir: path.join(os.tmpdir(), 'atom_script_tempfiles'),
1212

1313
// Public: Create a temporary file with the provided code
@@ -56,12 +56,11 @@ export default {
5656
// Public: Format args for cmd or bash, depending on the current OS
5757
formatArgs(command) {
5858
if (os.platform() === 'win32') {
59-
return [`/c ${command.replace(/['"]/g, '')}`];
59+
return [`/c ${command.replace(/["']/g, '')}`];
6060
}
6161
return ['-c', command];
6262
},
6363

64-
/* eslint-disable global-require */
6564
// Public: Get the Java helper object
6665
//
6766
// Returns an {Object} which assists in preparing java + javac statements
@@ -107,3 +106,4 @@ export default {
107106
// Returns an {Object} which assists in creating temp files containing D code
108107
D: require('./grammar-utils/d'),
109108
};
109+
export default GrammarUtils;

lib/grammar-utils/R.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use babel';
22

33
// Public: GrammarUtils.R - a module which assist the creation of R temporary files
4-
export default {
4+
const GrammarUtilsR = {
55
// Public: Create a temporary file with the provided R code
66
//
77
// * `code` A {String} containing some R code
@@ -11,3 +11,4 @@ export default {
1111
return module.parent.exports.createTempFileWithCode(code);
1212
},
1313
};
14+
export default GrammarUtilsR;

lib/grammar-utils/d.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import path from 'path';
77
import { v1 as uuidv1 } from 'uuid';
88

99
// Public: GrammarUtils.D - a module which assist the creation of D temporary files
10-
export default {
10+
const GrammarUtilsD = {
1111
tempFilesDir: path.join(os.tmpdir(), 'atom_script_tempfiles'),
1212

1313
// Public: Create a temporary file with the provided D code
@@ -31,3 +31,4 @@ export default {
3131
}
3232
},
3333
};
34+
export default GrammarUtilsD;

lib/grammar-utils/java.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os from 'os';
55
import path from 'path';
66

7-
export default {
7+
const GrammarUtilsJava = {
88
// Public: Get atom temp file directory
99
//
1010
// Returns {String} containing atom temp file directory
@@ -47,3 +47,4 @@ export default {
4747
return `${filenameRemoved}.`;
4848
},
4949
};
50+
export default GrammarUtilsJava;

0 commit comments

Comments
 (0)