Skip to content

Commit

Permalink
Merge pull request #2422 from atom-community/deps
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya authored Mar 21, 2021
2 parents 126777a + 19d08ec commit 400af8c
Show file tree
Hide file tree
Showing 35 changed files with 1,790 additions and 811 deletions.
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

4 changes: 4 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "eslint-config-atomic",
"ignorePatterns": ["dist/", "node_modules/", "spec/fixtures", "examples", "lib/grammars/*.coffee"]
}
22 changes: 0 additions & 22 deletions .eslintrc.yml

This file was deleted.

38 changes: 24 additions & 14 deletions lib/code-context-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class CodeContextBuilder {
//
// returns a {CodeContext} object
buildCodeContext(editor, argType = 'Selection Based') {
if (!editor) return null;
if (!editor) {return null;}

const codeContext = this.initCodeContext(editor);

Expand All @@ -35,7 +35,7 @@ export default class CodeContextBuilder {
editor.save();
} else if (codeContext.selection.isEmpty() && codeContext.filepath) {
codeContext.argType = 'File Based';
if (editor && editor.isModified()) editor.save();
if (editor && editor.isModified()) {editor.save();}
}

// Selection and Line Number Based runs both benefit from knowing the current line
Expand Down Expand Up @@ -66,9 +66,9 @@ export default class CodeContextBuilder {

const codeContext = new CodeContext(filename, filepath, textSource);
codeContext.selection = selection;
codeContext.shebang = this.getShebang(editor);
codeContext.shebang = getShebang(editor);

const lang = this.getLang(editor);
const lang = getLang(editor);

if (this.validateLang(lang)) {
codeContext.lang = lang;
Expand All @@ -77,18 +77,14 @@ export default class CodeContextBuilder {
return codeContext;
}

getShebang(editor) {
if (process.platform === 'win32') return null;
const text = editor.getText();
const lines = text.split('\n');
const firstLine = lines[0];
if (!firstLine.match(/^#!/)) return null;

return firstLine.replace(/^#!\s*/, '');
/** @deprecated use {getShebang} function */ // eslint-disable-next-line class-methods-use-this
getShebang(arg) {
return getShebang(arg);
}

getLang(editor) {
return editor.getGrammar().name;
/** @deprecated use {getLang} function */ // eslint-disable-next-line class-methods-use-this
getLang(arg) {
return getLang(arg);
}

validateLang(lang) {
Expand Down Expand Up @@ -117,3 +113,17 @@ export default class CodeContextBuilder {
return this.emitter.on('did-not-support-language', callback);
}
}

export function getShebang(editor) {
if (process.platform === 'win32') {return null;}
const text = editor.getText();
const lines = text.split('\n');
const firstLine = lines[0];
if (!firstLine.match(/^#!/)) {return null;}

return firstLine.replace(/^#!\s*/, '');
}

export function getLang(editor) {
return editor.getGrammar().name;
}
4 changes: 2 additions & 2 deletions lib/code-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class CodeContext {
// Returns the code selection {String}
getCode(prependNewlines = true) {
const code = this.textSource ? this.textSource.getText() : null;
if (!prependNewlines || !this.lineNumber) return code;
if (!prependNewlines || !this.lineNumber) {return code;}

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

return sections[0];
}
Expand Down
15 changes: 10 additions & 5 deletions lib/command-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,28 @@ export default class CommandContext {
return commandContext;
}

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

getRepresentation() {
if (!this.command || !this.args.length) return '';
if (!this.command || !this.args.length) {return '';}

// command arguments
const commandArgs = this.options.cmdArgs ? this.quoteArguments(this.options.cmdArgs).join(' ') : '';
const commandArgs = this.options.cmdArgs ? quoteArguments(this.options.cmdArgs).join(' ') : '';

// script arguments
const args = this.args.length ? this.quoteArguments(this.args).join(' ') : '';
const scriptArgs = this.options.scriptArgs ? this.quoteArguments(this.options.scriptArgs).join(' ') : '';
const args = this.args.length ? quoteArguments(this.args).join(' ') : '';
const scriptArgs = this.options.scriptArgs ? quoteArguments(this.options.scriptArgs).join(' ') : '';

return this.command.trim()
+ (commandArgs ? ` ${commandArgs}` : '')
+ (args ? ` ${args}` : '')
+ (scriptArgs ? ` ${scriptArgs}` : '');
}
}

export function quoteArguments(args) {
return args.map((arg) => (arg.trim().indexOf(' ') === -1 ? arg.trim() : `'${arg}'`));
}
6 changes: 3 additions & 3 deletions lib/grammar-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import path from 'path';
import { v1 as uuidv1 } from 'uuid';

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

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

/* eslint-disable global-require */
// Public: Get the Java helper object
//
// Returns an {Object} which assists in preparing java + javac statements
Expand Down Expand Up @@ -107,3 +106,4 @@ export default {
// Returns an {Object} which assists in creating temp files containing D code
D: require('./grammar-utils/d'),
};
export default GrammarUtils;
3 changes: 2 additions & 1 deletion lib/grammar-utils/R.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use babel';

// Public: GrammarUtils.R - a module which assist the creation of R temporary files
export default {
const GrammarUtilsR = {
// Public: Create a temporary file with the provided R code
//
// * `code` A {String} containing some R code
Expand All @@ -11,3 +11,4 @@ export default {
return module.parent.exports.createTempFileWithCode(code);
},
};
export default GrammarUtilsR;
3 changes: 2 additions & 1 deletion lib/grammar-utils/d.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import path from 'path';
import { v1 as uuidv1 } from 'uuid';

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

// Public: Create a temporary file with the provided D code
Expand All @@ -31,3 +31,4 @@ export default {
}
},
};
export default GrammarUtilsD;
3 changes: 2 additions & 1 deletion lib/grammar-utils/java.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os from 'os';
import path from 'path';

export default {
const GrammarUtilsJava = {
// Public: Get atom temp file directory
//
// Returns {String} containing atom temp file directory
Expand Down Expand Up @@ -47,3 +47,4 @@ export default {
return `${filenameRemoved}.`;
},
};
export default GrammarUtilsJava;
7 changes: 4 additions & 3 deletions lib/grammar-utils/lisp.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import _ from 'underscore';

// Public: GrammarUtils.Lisp - a module which exposes the ability to evaluate
// code
export default {
const GrammarUtilsLisp = {
// Public: Split a string of code into an array of executable statements
//
// Returns an {Array} of executable statements.
splitStatements(code) {
const iterator = (statements, currentCharacter) => {
if (!this.parenDepth) this.parenDepth = 0;
if (!this.parenDepth) {this.parenDepth = 0;}
if (currentCharacter === '(') {
this.parenDepth += 1;
this.inStatement = true;
} else if (currentCharacter === ')') {
this.parenDepth -= 1;
}

if (!this.statement) this.statement = '';
if (!this.statement) {this.statement = '';}
this.statement += currentCharacter;

if (this.parenDepth === 0 && this.inStatement) {
Expand All @@ -35,3 +35,4 @@ export default {
return statements;
},
};
export default GrammarUtilsLisp;
3 changes: 2 additions & 1 deletion lib/grammar-utils/matlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import path from 'path';
import { v1 as uuidv1 } from 'uuid';

// Public: GrammarUtils.MATLAB - a module which assist the creation of MATLAB temporary files
export default {
const GrammarUtilsMatlab = {
tempFilesDir: path.join(os.tmpdir(), 'atom_script_tempfiles'),

// Public: Create a temporary file with the provided MATLAB code
Expand All @@ -31,3 +31,4 @@ export default {
}
},
};
export default GrammarUtilsMatlab;
5 changes: 3 additions & 2 deletions lib/grammar-utils/nim.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fs from 'fs';
import path from 'path';

// Public: GrammarUtils.Nim - a module which selects the right file to run for Nim projects
export default {
const GrammarUtilsNim = {
// Public: Find the right file to run
//
// * `file` A {String} containing the current editor file
Expand Down Expand Up @@ -51,7 +51,7 @@ export default {
|| path.extname(name) === '.nimcgf'
|| path.extname(name) === '.cfg') {
const tfile = name.slice(0, -1);
if (fs.existsSync(tfile)) return path.basename(tfile);
if (fs.existsSync(tfile)) {return path.basename(tfile);}
}
}
}
Expand All @@ -60,3 +60,4 @@ export default {
return path.basename(editorfile);
},
};
export default GrammarUtilsNim;
3 changes: 2 additions & 1 deletion lib/grammar-utils/operating-system.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import os from 'os';

// Public: GrammarUtils.OperatingSystem - a module which exposes different
// platform related helper functions.
export default {
const GrammarUtilsOperatingSystem = {
isDarwin() {
return this.platform() === 'darwin';
},
Expand All @@ -29,3 +29,4 @@ export default {
return os.release();
},
};
export default GrammarUtilsOperatingSystem;
3 changes: 2 additions & 1 deletion lib/grammar-utils/perl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use babel';

// Public: GrammarUtils.Perl - a module which assist the creation of Perl temporary files
export default {
const GrammarUtilsPerl = {
// Public: Create a temporary file with the provided Perl code
//
// * `code` A {String} containing some Perl code
Expand All @@ -11,3 +11,4 @@ export default {
return module.parent.exports.createTempFileWithCode(code);
},
};
export default GrammarUtilsPerl;
5 changes: 3 additions & 2 deletions lib/grammar-utils/php.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
'use babel';

// Public: GrammarUtils.PHP - a module which assist the creation of PHP temporary files
export default {
const GrammarUtilsPhp = {
// Public: Create a temporary file with the provided PHP code
//
// * `code` A {String} containing some PHP code without <?php header
//
// Returns the {String} filepath of the new file
createTempFileWithCode(code) {
if (!/^[\s]*<\?php/.test(code)) { code = `<?php ${code}`; }
if (!/^\s*<\?php/.test(code)) { code = `<?php ${code}`; }
return module.parent.exports.createTempFileWithCode(code);
},
};
export default GrammarUtilsPhp;
5 changes: 3 additions & 2 deletions lib/grammars.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import doc from './grammars/doc.coffee';
import fortran from './grammars/fortran.coffee';
import haskell from './grammars/haskell.coffee';
import java from './grammars/java.coffee';
import js from './grammars/javascript';
import * as js from './grammars/javascript';
import lisp from './grammars/lisp.coffee';
import lua from './grammars/lua.coffee';
import ml from './grammars/ml.coffee';
Expand All @@ -21,7 +21,7 @@ import ruby from './grammars/ruby.coffee';
import shell from './grammars/shell.coffee';
import windows from './grammars/windows.coffee';

export default {
const Grammars = {
...grammarMap,

...apple,
Expand All @@ -43,3 +43,4 @@ export default {
...shell,
...windows,
};
export default Grammars;
Loading

0 comments on commit 400af8c

Please sign in to comment.