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

Commit

Permalink
Move dependency loading to a function
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasdf committed Aug 19, 2017
1 parent 469d392 commit dc5d210
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,26 @@

// eslint-disable-next-line import/extensions, import/no-extraneous-dependencies
import { CompositeDisposable } from 'atom';
import fs from 'fs-plus';
import path from 'path';
import * as helpers from 'atom-linter';
import semver from 'semver';

let fs;
let path;
let helpers;
let semver;

function loadDeps() {
if (!semver) {
semver = require('semver');
}
if (!fs) {
fs = require('fs-plus');
}
if (!helpers) {
helpers = require('atom-linter');
}
if (!path) {
path = require('path');
}
}

// Local variables
const parseRegex = /(\d+):(\d+):\s(([A-Z])\d{2,3})\s+(.*)/g;
Expand Down Expand Up @@ -82,14 +98,14 @@ const determineExecVersion = async (execPath) => {
if (match !== null) {
execPathVersions.set(execPath, match[0]);
}
}
};

const getFlake8Version = async (execPath) => {
if (!execPathVersions.has(execPath)) {
await determineExecVersion(execPath);
}
return execPathVersions.get(execPath);
}
};

export default {
activate() {
Expand All @@ -108,6 +124,7 @@ export default {
if (typeof atom.config.get('linter-flake8.disableTimeout') !== 'undefined') {
atom.config.unset('linter-flake8.disableTimeout');
}
loadDeps();
};
packageDepsID = window.requestIdleCallback(linterFlake8Deps);
this.idleCallbacks.add(packageDepsID);
Expand Down Expand Up @@ -160,6 +177,8 @@ export default {
scope: 'file',
lintOnFly: true,
lint: async (textEditor) => {
loadDeps();

const filePath = textEditor.getPath();
const fileText = textEditor.getText();

Expand Down

0 comments on commit dc5d210

Please sign in to comment.