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

Commit 1ea13e7

Browse files
committed
Use lazy-req to only load modules when needed
1 parent 550f399 commit 1ea13e7

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

lib/index.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
// eslint-disable-next-line import/extensions, import/no-extraneous-dependencies
44
import { CompositeDisposable } from 'atom';
5-
import fs from 'fs';
6-
import path from 'path';
7-
import { findAsync, rangeFromLineNumber } from 'atom-linter';
8-
import stripJSONComments from 'strip-json-comments';
5+
import { readFile as fsReadFile } from 'fs';
6+
import { dirname } from 'path';
97

10-
const readFile = require('tiny-promisify')(fs.readFile);
8+
const lazyReq = require('lazy-req')(require);
9+
10+
const { findAsync, rangeFromLineNumber } = lazyReq('atom-linter')('findAsync', 'rangeFromLineNumber');
11+
const stripJSONComments = lazyReq('strip-json-comments');
12+
const tinyPromisify = lazyReq('tiny-promisify');
1113

1214
const grammarScopes = [];
1315

@@ -30,13 +32,14 @@ export function deactivate() {
3032
}
3133

3234
const getConfig = async (filePath) => {
33-
const configPath = await findAsync(path.dirname(filePath), '.htmlhintrc');
35+
const readFile = tinyPromisify()(fsReadFile);
36+
const configPath = await findAsync(dirname(filePath), '.htmlhintrc');
3437
let conf = null;
3538
if (configPath !== null) {
3639
conf = await readFile(configPath, 'utf8');
3740
}
3841
if (conf) {
39-
return JSON.parse(stripJSONComments(conf));
42+
return JSON.parse(stripJSONComments()(conf));
4043
}
4144
return null;
4245
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"atom-linter": "^8.0.0",
4848
"atom-package-deps": "^4.0.1",
4949
"htmlhint": "0.9.13",
50+
"lazy-req": "^1.1.0",
5051
"strip-json-comments": "^2.0.1",
5152
"tiny-promisify": "^0.1.1"
5253
},

0 commit comments

Comments
 (0)