Skip to content

Commit 80fac2a

Browse files
authored
Merge pull request #2 from quadre-code/listen-changes
Listen changes
2 parents 3aec331 + 09b61ab commit 80fac2a

File tree

7 files changed

+63
-32
lines changed

7 files changed

+63
-32
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

package-lock.json

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@
3535
},
3636
"dependencies": {
3737
"brackets-inspection-gutters": "^0.2.10",
38-
"eslint": "^4.14.0"
38+
"eslint": "^4.15.0"
3939
},
4040
"devDependencies": {
4141
"@types/jquery": "2.0.40",
4242
"@types/node": "8.5.2",
4343
"concurrently": "3.5.1",
4444
"rimraf": "2.6.2",
45-
"tslint": "5.8.0",
45+
"tslint": "5.9.1",
4646
"typescript": "2.6.2"
4747
}
4848
}

src/main.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const Menus = brackets.getModule('command/Menus');
1212
const DocumentManager = brackets.getModule('document/DocumentManager');
1313
const EditorManager = brackets.getModule('editor/EditorManager');
1414
const PreferencesManager = brackets.getModule('preferences/PreferencesManager');
15+
const FileSystem = brackets.getModule('filesystem/FileSystem');
1516
const EXTENSION_NAME = 'quadre-eslint';
1617
const AUTOFIX_COMMAND_ID = EXTENSION_NAME + '.autofix';
1718
const AUTOFIX_COMMAND_NAME = 'Auto-fix with ESLint';
@@ -101,6 +102,14 @@ editMenu.addMenuItem(AUTOFIX_COMMAND_ID);
101102
const contextMenu = Menus.getContextMenu(Menus.ContextMenuIds.EDITOR_MENU);
102103
contextMenu.addMenuItem(AUTOFIX_COMMAND_ID);
103104

105+
FileSystem.on('change', (evt, file) => {
106+
if (/^\.eslintrc(\.(js|yaml|yml|json))?$/.test(file.name)) {
107+
const projectRoot = ProjectManager.getProjectRoot().fullPath;
108+
const useEmbeddedESLint = preferences.get('useEmbeddedESLint');
109+
nodeDomain.exec('configFileModified', projectRoot, useEmbeddedESLint);
110+
}
111+
});
112+
104113
// register a linter with CodeInspection
105114
['javascript', 'jsx', 'typescript', 'tsx', 'vue'].forEach((langId) => {
106115
CodeInspection.register(langId, {

src/node/domain.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,18 @@ exports.init = (_domainManager: any) => {
4141
]
4242
);
4343

44+
domainManager.registerCommand(
45+
domainName,
46+
'configFileModified',
47+
esLint.configFileModified,
48+
false,
49+
'notify that config file was modified',
50+
[
51+
{ name: 'projectRoot', type: 'string' }
52+
],
53+
[
54+
{ name: 'result', type: 'boolean' }
55+
]
56+
);
57+
4458
};

src/node/eslint.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ const isOldNode = /^0/.test(nodeVersion);
2929
const defaultCwd = process.cwd();
3030
const ESLINT_SEVERITY_ERROR = 2;
3131
const ESLINT_SEVERITY_WARNING = 1;
32-
const BRACKETS_TYPE_ERROR = 'problem_type_error';
33-
const BRACKETS_TYPE_WARNING = 'problem_type_warning';
34-
const BRACKETS_TYPE_META = 'problem_type_meta';
3532

3633
let cli: ESLintCLIEngine | null = null;
3734
let currentVersion: string | null = null;
@@ -210,15 +207,15 @@ function mapEslintMessage(result: any, majorVersion: number): CodeInspectionResu
210207
switch (result.severity) {
211208
case ESLINT_SEVERITY_ERROR:
212209
message = 'ERROR: ';
213-
type = BRACKETS_TYPE_ERROR as CodeInspectionResultType;
210+
type = CodeInspectionResultType.ERROR;
214211
break;
215212
case ESLINT_SEVERITY_WARNING:
216213
message = 'WARNING: ';
217-
type = BRACKETS_TYPE_WARNING as CodeInspectionResultType;
214+
type = CodeInspectionResultType.WARNING;
218215
break;
219216
default:
220217
message = 'UNKNOWN: ';
221-
type = BRACKETS_TYPE_META as CodeInspectionResultType;
218+
type = CodeInspectionResultType.META;
222219
}
223220

224221
message += result.message;
@@ -248,7 +245,7 @@ function createUserError(message: string): CodeInspectionReport {
248245
erroredLastTime = true;
249246
return {
250247
errors: [{
251-
type: 'problem_type_error',
248+
type: CodeInspectionResultType.ERROR,
252249
message,
253250
pos: { line: 0, ch: 0 }
254251
}]
@@ -323,3 +320,8 @@ export function fixFile(
323320
}
324321
callback(err, res);
325322
}
323+
324+
export function configFileModified(projectRoot, useEmbeddedESLint) {
325+
setProjectRoot(projectRoot, null, useEmbeddedESLint);
326+
currentProjectRoot = projectRoot;
327+
}

src/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
export type CodeInspectionResultType = 'problem_type_error' | 'problem_type_warning' | 'problem_type_meta';
1+
export enum CodeInspectionResultType {
2+
ERROR = 'problem_type_error',
3+
WARNING = 'problem_type_warning',
4+
META = 'problem_type_meta'
5+
}
26

37
export interface CodeInspectionPosition {
48
line: number;

0 commit comments

Comments
 (0)