Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Verify valid TextEditor and path #109

Merged
merged 1 commit into from
Oct 18, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,29 @@ export default {
scope: 'file',
lintOnFly: true,
lint: (textEditor) => {
if (!atom.workspace.isTextEditor(textEditor)) {
return null;
}

const filePath = textEditor.getPath();
if (!filePath) {
// TextEditor has no path associated with it (yet)
return null;
}

const fileExt = path.extname(filePath);
if (fileExt === '.zsh' || fileExt === '.zsh-theme') {
// shellcheck does not support zsh
return [];
}

const text = textEditor.getText();
const cwd = path.dirname(filePath);
const showAll = this.enableNotice;
// The first -f parameter overrides any others
const parameters = [].concat(['-f', 'gcc'], this.userParameters, ['-']);
const options = { stdin: text, cwd, ignoreExitCode: true };

return helpers.exec(this.executablePath, parameters, options).then((output) => {
if (textEditor.getText() !== text) {
// The text has changed since the lint was triggered, tell Linter not to update
Expand Down