Skip to content

Commit 414f163

Browse files
committed
refactor: use documentManager to read jshint config
1 parent 3400247 commit 414f163

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/extensions/default/JSHint/main.js

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
// Parts of this file is adapted from https://github.com/cfjedimaster/brackets-jshint
2323

24+
/*global path*/
25+
2426
/**
2527
* Provides JSLint results via the core linting extension point
2628
*/
@@ -29,8 +31,10 @@ define(function (require, exports, module) {
2931
// Load dependent modules
3032
const _ = brackets.getModule("thirdparty/lodash"),
3133
CodeInspection = brackets.getModule("language/CodeInspection"),
34+
FileSystemError = brackets.getModule("filesystem/FileSystemError"),
3235
AppInit = brackets.getModule("utils/AppInit"),
3336
PreferencesManager = brackets.getModule("preferences/PreferencesManager"),
37+
DocumentManager = brackets.getModule("document/DocumentManager"),
3438
Strings = brackets.getModule("strings"),
3539
ProjectManager = brackets.getModule("project/ProjectManager"),
3640
FileSystem = brackets.getModule("filesystem/FileSystem"),
@@ -149,21 +153,19 @@ define(function (require, exports, module) {
149153
function _readConfig(dir, configFileName) {
150154
return new Promise((resolve, reject)=>{
151155
configFileName = configFileName || CONFIG_FILE_NAME;
152-
let file = FileSystem.getFileForPath(dir + configFileName);
153-
file.read(function (err, content) {
154-
if (err) {
155-
resolve(null); // no config file is a valid case. we just resolve with null
156-
return;
157-
}
156+
const configFilePath = path.join(dir, configFileName);
157+
let displayPath = ProjectManager.makeProjectRelativeIfPossible(configFilePath);
158+
displayPath = Phoenix.app.getDisplayPath(displayPath);
159+
DocumentManager.getDocumentForPath(configFilePath).done(function (configDoc) {
158160
let config;
161+
const content = configDoc.getText();
159162
try {
160163
config = JSON.parse(removeComments(content));
161-
console.log("JSHint: loaded config file for project " + file.fullPath);
164+
console.log("JSHint: loaded config file for project " + configFilePath);
162165
} catch (e) {
163-
console.log("JSHint: error parsing " + file.fullPath);
166+
console.log("JSHint: error parsing " + configFilePath);
164167
// just log and return as this is an expected failure for us while the user edits code
165-
reject("Error parsing JSHint config file: "
166-
+ ProjectManager.getProjectRelativePath(file.fullPath));
168+
reject("Error parsing JSHint config file: " + displayPath);
167169
return;
168170
}
169171
// Load any base config defined by "extends".
@@ -180,13 +182,19 @@ define(function (require, exports, module) {
180182
}
181183
resolve(mergedConfig);
182184
}).catch(()=>{
183-
reject("Error parsing JSHint config file: "
184-
+ ProjectManager.getProjectRelativePath(extendFile.name));
185+
reject("Error parsing JSHint config file: " + Phoenix.app.getDisplayPath(extendFile.fullPath));
185186
});
186187
}
187188
else {
188189
resolve(config);
189190
}
191+
}).fail((err)=>{
192+
if(err === FileSystemError.NOT_FOUND){
193+
resolve(null); // no config file is a valid case. we just resolve with null
194+
return;
195+
}
196+
console.error("Error reading JSHint Config File", configFilePath, err);
197+
reject("Error reading JSHint Config File", displayPath);
190198
});
191199
});
192200
}

0 commit comments

Comments
 (0)