Skip to content

Commit fa373a9

Browse files
committed
chore: eslint detect and tweak dark theme warning underline colors to be less harsh
1 parent 6a87f5d commit fa373a9

5 files changed

Lines changed: 40 additions & 90 deletions

File tree

src/extensions/default/JSLint/ESLint.js

Lines changed: 31 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ define(function (require, exports, module) {
4242
IndexingWorker = brackets.getModule("worker/IndexingWorker");
4343

4444
let prefs = PreferencesManager.getExtensionPrefs("ESLint"),
45-
projectSpecificOptions = null,
46-
esLintConfigFileErrorMessage = null;
45+
esLintEnabled = false,
46+
projectSpecificOptions = null;
4747

4848
const ESLINT_ERROR_MODULE_LOAD_FAILED = "ESLINT_MODULE_LOAD_FAILED",
4949
ESLINT_ERROR_MODULE_NOT_FOUND = "ESLINT_MODULE_NOT_FOUND",
@@ -75,7 +75,7 @@ define(function (require, exports, module) {
7575
case ESLINT_ERROR_LINT_FAILED:
7676
errorMessage = Strings.DESCRIPTION_ESLINT_FAILED; break;
7777
case ESLINT_ERROR_MODULE_NOT_FOUND:
78-
errorMessage = Strings.DESCRIPTION_ESLINT_NOT_FOUND; break;
78+
errorMessage = Strings.DESCRIPTION_ESLINT_DO_NPM_INSTALL; break;
7979
case ESLINT_ERROR_MODULE_LOAD_FAILED:
8080
errorMessage = Strings.DESCRIPTION_ESLINT_LOAD_FAILED; break;
8181
}
@@ -131,7 +131,7 @@ define(function (require, exports, module) {
131131
resolve({ errors: errors });
132132
} else if(esLintResult.isError) {
133133
resolve({ errors: _getLintError(esLintResult.errorCode) });
134-
} else {
134+
} else if(!esLintResult.result){
135135
console.error("ESLint Unknown result", esLintResult);
136136
resolve();
137137
}
@@ -143,105 +143,50 @@ define(function (require, exports, module) {
143143
* @private
144144
* @type {string}
145145
*/
146-
const CONFIG_FILE_NAME = ".jshintrc";
147-
148-
/**
149-
* Removes JavaScript comments from a string by replacing
150-
* everything between block comments and everything after
151-
* single-line comments in a non-greedy way.
152-
*
153-
* English version of the regex:
154-
* match '/*'
155-
* then match zero or more instances of any character (incl. \n)
156-
* except for instances of '* /' (without a space, obv.)
157-
* then match '* /' (again, without a space)
158-
*
159-
* @param {string} str a string with potential JavaScript comments.
160-
* @returns {string} a string without JavaScript comments.
161-
*/
162-
function removeComments(str) {
163-
str = str || "";
164-
165-
str = str.replace(/\/\*(?:(?!\*\/)[\s\S])*\*\//g, "");
166-
str = str.replace(/\/\/[^\n\r]*/g, ""); // Everything after '//'
167-
168-
return str;
169-
}
146+
const PACKAGE_JSON = "package.json";
170147

171148
/**
172-
* Reads configuration file in the specified directory. Returns a promise for configuration object.
173-
*
174-
* @param {string} dir absolute path to a directory.
175-
* @param {string} configFileName name of the configuration file (optional)
149+
* Reads package.json and see if eslint is in dependencies or dev dependencies
176150
*
177151
* @returns {Promise} a promise to return configuration object.
178152
*/
179-
function _readConfig(dir, configFileName) {
180-
return new Promise((resolve, reject)=>{
181-
configFileName = configFileName || CONFIG_FILE_NAME;
182-
const configFilePath = path.join(dir, configFileName);
183-
let displayPath = ProjectManager.makeProjectRelativeIfPossible(configFilePath);
184-
displayPath = Phoenix.app.getDisplayPath(displayPath);
153+
function _isESLintProject() {
154+
return new Promise((resolve)=>{
155+
const configFilePath = path.join(ProjectManager.getProjectRoot().fullPath, PACKAGE_JSON);
185156
DocumentManager.getDocumentForPath(configFilePath).done(function (configDoc) {
186-
let config;
187157
const content = configDoc.getText();
188158
try {
189-
config = JSON.parse(removeComments(content));
190-
console.log("JSHint: loaded config file for project " + configFilePath);
191-
} catch (e) {
192-
console.log("JSHint: error parsing " + configFilePath);
193-
// just log and return as this is an expected failure for us while the user edits code
194-
reject("Error parsing JSHint config file: " + displayPath);
195-
return;
196-
}
197-
// Load any base config defined by "extends".
198-
// The same functionality as in
199-
// jslints -> cli.js -> loadConfig -> if (config['extends'])...
200-
// https://jshint.com/docs/cli/ > Special Options
201-
if (config.extends) {
202-
let extendFile = FileSystem.getFileForPath(path.join(dir, config.extends));
203-
_readConfig(extendFile.parentPath, extendFile.name).then(baseConfigResult=>{
204-
delete config.extends;
205-
let mergedConfig = $.extend({}, baseConfigResult, config);
206-
if (config.globals) {
207-
delete config.globals;
208-
}
209-
resolve(mergedConfig);
210-
}).catch(()=>{
211-
let extendDisplayPath = ProjectManager.makeProjectRelativeIfPossible(extendFile.fullPath);
212-
extendDisplayPath = Phoenix.app.getDisplayPath(extendDisplayPath);
213-
reject("Error parsing JSHint config file: " + extendDisplayPath);
214-
});
215-
}
216-
else {
217-
resolve(config);
159+
const config = JSON.parse(content);
160+
resolve(config && (
161+
(config.devDependencies && config.devDependencies.eslint) ||
162+
(config.dependencies && config.dependencies.eslint)
163+
));
164+
} catch (err) {
165+
console.error(`ESLint Error parsing ${PACKAGE_JSON}`, configFilePath, err);
166+
resolve(false);
218167
}
219168
}).fail((err)=>{
220-
if(err === FileSystemError.NOT_FOUND){
221-
resolve(null); // no config file is a valid case. we just resolve with null
222-
return;
169+
if(err !== FileSystemError.NOT_FOUND){
170+
console.error(`ESLint Error reading ${PACKAGE_JSON}`, configFilePath, err);
223171
}
224-
console.error("Error reading JSHint Config File", configFilePath, err);
225-
reject("Error reading JSHint Config File", displayPath);
172+
resolve(false);
226173
});
227174
});
228175
}
229176

230177
function _reloadOptions() {
231178
projectSpecificOptions = null;
232-
_readConfig(ProjectManager.getProjectRoot().fullPath, CONFIG_FILE_NAME).then((config)=>{
233-
projectSpecificOptions = config;
234-
CodeInspection.requestRun(Strings.JSHINT_NAME);
235-
esLintConfigFileErrorMessage = null;
236-
}).catch((err)=>{
237-
esLintConfigFileErrorMessage = err;
238-
CodeInspection.requestRun(Strings.JSHINT_NAME);
179+
_isESLintProject(ProjectManager.getProjectRoot().fullPath).then((shouldESLintEnable)=>{
180+
esLintEnabled = shouldESLintEnable;
181+
CodeInspection.requestRun(Strings.ESLINT_NAME);
182+
}).catch(()=>{
183+
esLintEnabled = false;
184+
CodeInspection.requestRun(Strings.ESLINT_NAME);
239185
});
240186
}
241187

242-
function isESLintConfigActive() {
243-
return true;
244-
// return !!(esLintConfigFileErrorMessage || projectSpecificOptions); todo
188+
function isESLintActive() {
189+
return esLintEnabled;
245190
}
246191

247192
function _isFileInArray(fileToCheck, fileArray){
@@ -257,13 +202,12 @@ define(function (require, exports, module) {
257202
}
258203

259204
function _projectFileChanged(_evt, entry, added, removed) {
260-
let configFilePath = FileSystem.getFileForPath(ProjectManager.getProjectRoot().fullPath + CONFIG_FILE_NAME);
205+
let configFilePath = FileSystem.getFileForPath(ProjectManager.getProjectRoot().fullPath + PACKAGE_JSON);
261206
if(entry && entry.fullPath === configFilePath.fullPath
262207
|| _isFileInArray(configFilePath, added)){
263208
_reloadOptions();
264209
} else if(_isFileInArray(configFilePath, removed)){
265210
projectSpecificOptions = null;
266-
esLintConfigFileErrorMessage = null;
267211
}
268212
}
269213

@@ -278,10 +222,9 @@ define(function (require, exports, module) {
278222
name: Strings.ESLINT_NAME,
279223
scanFileAsync: lintOneFile,
280224
canInspect: function (fullPath) {
281-
return !prefs.get(PREFS_ESLINT_DISABLED) && fullPath && !fullPath.endsWith(".min.js")
282-
&& isESLintConfigActive(); // in browsers, jshint is default if no linter present
225+
return !prefs.get(PREFS_ESLINT_DISABLED) && fullPath && !fullPath.endsWith(".min.js") && isESLintActive();
283226
}
284227
});
285228

286-
exports.isESLintConfigActive = isESLintConfigActive;
229+
exports.isESLintActive = isESLintActive;
287230
});

src/extensions/default/JSLint/JSHint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ define(function (require, exports, module) {
258258
scanFileAsync: lintOneFile,
259259
canInspect: function (fullPath) {
260260
return !prefs.get(PREFS_JSHINT_DISABLED) && fullPath && !fullPath.endsWith(".min.js")
261-
&& (isJSHintConfigActive() || !ESLint.isESLintConfigActive()); //jshint is default only if eslint is not
261+
&& isJSHintConfigActive();
262262
}
263263
});
264264

src/nls/root/strings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ define({
959959
"DESCRIPTION_ESLINT_DISABLE": "true to disable ESLint linter in problems panel",
960960
"DESCRIPTION_ESLINT_FAILED": "ESLint Failed due to an unknown reason. {APP_NAME} supports only ESLint versions above 6.",
961961
"DESCRIPTION_ESLINT_LOAD_FAILED": "Failed to load ESLint for this project. {APP_NAME} supports only ESLint versions above 6.",
962-
"DESCRIPTION_ESLINT_NOT_FOUND": "Please run `npm install` on your project to enable ESLint",
962+
"DESCRIPTION_ESLINT_DO_NPM_INSTALL": "Please run `npm install` on your project to enable ESLint",
963963
"DESCRIPTION_LANGUAGE": "Language specific settings",
964964
"DESCRIPTION_LANGUAGE_FILE_EXTENSIONS": "Additional mappings from file extension to language name",
965965
"DESCRIPTION_LANGUAGE_FILE_NAMES": "Additional mappings from file name to language name",

src/styles/brackets.less

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ html, body {
177177

178178
.editor-text-fragment-warn.editor-text-fragment-warn.editor-text-fragment-warn{
179179
border-bottom:2px dotted @warn-underline-text;
180+
.dark &{
181+
border-bottom:2px dotted @dark-warn-underline-text;
182+
}
180183
display: inline-block;
181184
position: relative;
182185
}
@@ -185,6 +188,9 @@ html, body {
185188
content: '';
186189
width: 100%;
187190
border-bottom:2px dotted @warn-underline-text;
191+
.dark &{
192+
border-bottom:2px dotted @dark-warn-underline-text;
193+
}
188194
position: absolute;
189195
display:block;
190196
bottom: -3px;

src/styles/brackets_core_ui_variables.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@
200200
@dark-bc-text-thin-quiet: #bbb;
201201
@error-underline-text: #ff5388;
202202
@warn-underline-text: #ffc600;
203+
@dark-warn-underline-text: #8c7d00;
203204
@info-underline-text: #6bbeff;
204205
@spell-underline-text: #82b839;
205206

0 commit comments

Comments
 (0)