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

Checking for null/undefined filePath from editor. #156

Merged
merged 3 commits into from
Apr 14, 2017
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,12 @@ export default {

async lint(textEditor, options) {
const filePath = textEditor.getPath();
const text = textEditor.getText();

if (filePath === null || filePath === undefined) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this only ever returns a path or undefined, no reason not to check both though 😉.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually I prefer doing a value == undefined since this type-juggles null also. But the linting rules in this project disallow == even in the undefined case =[

return null;
}

const text = textEditor.getText();
const Linter = await this.getLinter(filePath);
const configurationPath = Linter.findConfigurationPath(null, filePath);
const configuration = Linter.loadConfigurationFromPath(configurationPath);
Expand Down
8 changes: 8 additions & 0 deletions spec/linter-tslint-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@ describe('The TSLint provider for Linter', () => {
}),
);
});

it('handles undefined filepath', () => {
waitsForPromise(() =>
atom.workspace.open().then(editor => lint(editor)).then((result) => {
expect(result).toBeNull();
}),
);
});
});